Scale By The Bay 2020: Mary Grygleski, Deploying a Modern Serverless Reactive Container to the Cloud
[Music] so um thank you i really appreciate all of you uh coming to my talk and it's already towards the end of this conference and i realized that maybe most of you have plans already for the weekend so i have a lot of respect for you for still coming to my talk so i hope it will be useful for you so my topic is about deploying a modern serverless reactive container to the cloud and uh as such too i will be focused a bit more on talking about the specific library that i'm going to be talking about uh but then i'll also give a bit of an introduction to reactive technology because i cannot assume everybody already know what that is so as such this talk is intended more for kind of people wanting to get to know reactive and then i'll show a bit of the deployment to openshift running on the cloud and specifically i'm a developer advocate at ibm so i'll be using the ibm cloud and there's also openshift cluster that's running there that i'm i will be showing so and if you like to uh follow me this is my twitter handle so okay so with that let me start sorry it's a challenge okay all right so um so today as i mentioned uh i'd like to kind of bring up first about why vertex uh vertex is an open source project and it's uh an eclipse foundation open source project and uh it's reactive in nature and it's actually very lightweight so supports like event driven systems programming and it's really the the asynchronous engine that powers corpus if you're familiar with corpus it is a cloud native ready uh library developed by um red hat and uh it's a relatively new uh library and it's highly efficient um i won't have time to actually talk much about it today uh if you're interested too we can uh kind of get more into that later or maybe i'll point you to some resources too so as such too it is a um a library that actually supports both imperative and reactive uh in the runtime so so it's very efficient and not only that too in the build phase of it it trims down a lot of unnecessary things that are there so it makes your executable executable deployment and everything a lot more kind of nimble into your cluster like that so that's caucus and uh so i'm kind of excited actually for me too i was trying to determine like which library to do and when i learned about quarkx and knowing vertex behind so that's why i wanted to spend more time to do some work about it and also uh my weekly twitch uh which swap mail so kindly mention about that coding twitch i also will have some examples in uh using vertex as well okay so that's one thing about the vertex and then get more into it it's a very flexible toolkit this really supports like interoperability um very flexible it doesn't force you the language that you want to write in because it can you can it's very polyglot in nature you can actually write um write your your vertical which is a unit of deployment and vertex you can write that in any other languages that supports it for example scala to and python javascript ruby you name it kotlin um so yeah so opportunities are limited and to me too i've been very interested in doing reactive and all these work because of the asynchronous nature and you can actually uh build out your pipeline um make up made up of different libraries and they can all be communicating with one another especially if they support you know in the reactive java world if they support the reactive stream specification that actually is truly interoperable it's kind of fun to do and that's a project that i'm going to hopefully start on when the holiday time comes i have some time i want to build like a hybrid you know data pipeline that have different library implementations to it so okay so with that i should move forward um so about corpus uh so some information then about caucus and vertex so as such if you use quantize you you wouldn't know about vertex if you just look at the surface because vertex is what goes on behind the scenes like underneath um so when you look into uh you know your application it goes you know it goes into the routing layer then from there it's actually handled by vertex and vertex handles it has a very efficient event bus that um essentially the event loop and the vertical model of vertex they they work together kind of hand in and uh then it takes care of the requests and you know responses uh by the request handler for example like for http so okay so if you wanted more information you go to the vertex dot io or actually the corpus at caucus dot io you can find more information about quarkx as well but let me also then now turn a bit into talking about reactive java quickly uh reactive as such is a um you know less of a hype these days i mean it was for a while i think in kind of like the mid uh 2010s the last decade and now to me i feel like well it's kind of um still very important but not many um you know kind of actual production systems have adopted it yeah and the reason is that it's kind of requires a bit in the change in how you think about uh programming um and but as such at this uh conference i'm sure everybody would wouldn't have any trouble because it's essentially the functional style of programming and and also too uh in specifically two in java uh it's kind of timeless right when um reactive java is all these libraries come out because uh since java 8 there is stream processing support for streams and then for functional style of programming for lambdas all these time you know were ripe and the reactive stream specification which is a specification that kind of dictates or not i shouldn't say dictate but guidelines to uh kind of help to define how asynchronous processing can be handled properly for non-blocking scenarios and not blocking a synchronous scenario and also to um to handle back pressure so that's kind of a one kind of major thing for the reactive screen stream specification and that that reactive streams is actually based on java 9 the flow api too so and as such too i want to kind of point out too there's also difference too when we talk about reactive java because there's uh there's reactive programming which is the functional style or programming and of course if you talk about functional programming and functional reactive programming then there is also kind of differences in there too because reactive programming uh we're talking about you know kind of really focusing on the data uh the flow of it and um it's a bit more focused on the data so what kind of moves your system the flow is really this chain changes in state of the data that move moves it you know down the pipeline on the flow but for functional style programming we know it's more uh based on like a thread of execution so based on the threat um your your program will kind of execute so that's why too i think in in a lot of folks too when i spoke with them or you know my audience in some of my previous uh presentation on an introductory reactive programming uh there are people asking like well why you're doing you know your functional style programming because let's say we're doing a observer um and observable and then we're you know have all these events and then we're doing a subscribe to what will come later it's actually we're subscribing to something in the future so then folks we're kind of asking well how does it actually work so anyway the point i'm trying to make is that it's kind of requires a little bit of different way of thinking because of the asynchronous style processing involved so okay so i'm sure that with our audience here is less of a concern to kind of understand functional uh programming so i won't go into as much detail with like i did with some of the conferences that i've been to now then let me talk about uh reactive so i talked about reactive programming reactive uh streams so now there's also reactive manifesto so reactive manifesto is what um kind of provide a guideline as to what reactive system should be and it's a light band kind of a guideline that is led by light bend um and essentially two there are four tenants uh of the reactive manifesto that guide that guides like what a reactive system should have so um so let me quickly very quickly go over it um it's essentially too uh fundamentally is the responsiveness meaning that uh requests going into a system they need to be handled um you know on a very timely basis and that's essentially what it is and um then there's also resil actually let me go to elasticity so elasticity means that if um you know your system is under load and and a lot of requests coming in then your overall system should then be able to handle all of the you know additional requests that are coming in so then you know then you don't have the problem of back pressure building up in there so let's say you know your valentine's day is always a good kind of example an e-commerce system for handling flowers so right before valentine's day there will be a lot of orders so in those circumstances then the system needs to be very scalable really quickly spin up a lot more processes to handle all of these orders accordingly and that's elasticity so when it's like you know not a busy time then your system should then scale back down so then you can release some of those resources to handle some other scenarios some other maybe systems you know within your whole ecosystem okay so that's elasticity then we move over to the right side about resiliency it means that if there are any kind of error condition that occurs then likewise it also needs to be very responsive be able to handle this error uh right away so then the you know the overall system should not um suffer to the response time should not be you know suffering and then there's also resiliency when you have maybe like one you know some component in a cluster that's down then it immediately should come back and uh kind of cover what's you know been down you should have some way of kind of replacing that or maybe fixing it right away and making it available again so those three are kind of like the uh principles and tenants and with the fourth one um there's message driven so message driven to me too i kind of look at it it's more like an enabler um in order to enable all the three other uh you know kind of tenants happening it's really your system needs to be loosely coupled uh very message driven in nature so they they can all the components are you know not tightly coupled they all communicate with one another through messaging now there's a bit of a difference too between like message driven and event driven so message driven is about messages that they have a known address so they know where they're going to the sender knows what where it goes to to a receiver and likewise you know if they can turn around they communicate with one another now for event driven that's more about in cases like a pup sub type of scenario producer and consumer so any events that happen they're emitting uh you know these uh the source emitting some data it doesn't know where it's going to because it is up to the consumer who whoever is interested in it will need to subscribe to it so like subscribe it's kind of a terminology kind of borrowing from reactive extension you have observables uh streams of data and then you have your subscriber or your consumer subscribing to the data that will happen in the future kind of like that so that's more event driven without like a fixed address this address would be unknown so that's that now now then let me quickly also come and talk about some of the reactive frameworks that are more uh popular in the java world um so just now i mentioned about reactive rx java uh reactive extension rx java and there is of course there are other uh you know languages implementation of reactive extension essentially it came out of microsoft uh the rx.net and then netflix saw the potential and really you know kind of took it kind of turn it around and kind of ported it to java rxjava it's very popular with android developer especially with rx java one uh but rx java one doesn't have any support for back pressure so rx java 2 is the flowable that actually has back pressure support and basically you can have streams and then you can do it too flowable and that can convert it essentially your observable stream into like flowable with back pressure too okay so then now vertex and what we'll be talking about some more and i also want to point out this library called small rye mutiny um it says it's uh open source library but the red hat folks uh uh like mostly they are kind of leading this effort too so small writing meal to me is you may be wondering well another you know reactive library no because what they're trying to achieve is to uh streamline what used to be you know all the uh rx uh reactive extension operators there are tons of them and then um because they're they're run into problems uh too many operators too many methods in an interface so they basically do like a trimmed down version of um you know like a reactive library that's more uh kind of more efficient to so to speak and also too it um it also have better pipelines that it could help with different languages and it supports like different languages too in in the operator that side of things so among a lot of uh benefits to it so okay so that's small right looting and then there's also micro profile which is uh also an eclipse foundation project and it's uh basically you see that the small print here enterprise java so it came out more from the java ee kind of uh side of things and now um it's actually microprofile is a separate project this lighter weight that would support um essentially focusing on support for micro services it has support from reactive messaging and it also has this set of reactive operators as well so um again it's more focused for building microservices uh then of course there's akka without explanation we all know you know aka and then lagom the the opinionated microservices framework uh built on top of octa and the play framework to also on top of opta and then there's also uh the spring coming from the folks who actually produce as the spring that's uh the vmware what used to be pivotal so that's a project reactor which actually their set of operators are essentially the same as the rx java 2 because it's the same group of engineers that work on their open source libraries okay then another thing i'd like to bring to your attention is the r socket that comes out is kind of i should say it comes out of the consortium of six companies um so these are listed here and it's currently kind of under the jurisdiction i guess underneath the reactive foundation which in turn is actually underneath the linux foundation it's very efficient it's an application level protocol late layer five and six based on reactive streams and uh also very flexible um of these things i'm listed here reactive back pressure flow control all these things too so and uh so uh yeah i won't have time to go into all the details but we can talk about it some more too later okay so quick thing then before i go into a bit of a vertex is the small rye mutiny to uh just want to point out to you that where you know mutiny is serving as that too maybe i should have shown this earlier so you can see uh in the reactive world is the manifesto the system the extension all these things then over here there's the programming aspect the streams and back pressure data flow and that's where mutiny uh kind of focusing the library serves in this in this area so for this too i i um borrow this uh you know this diagram from the mutiny documentation so you can look that up if you like so okay so now then let me quickly i realized well it's kind of like so much um so much stuff to talk about so i have to go a little bit faster i hope to also show the deployment part which is what i'm trying to show so vertex okay you know quickly so these are like some of the use cases uh we can use for make use of uh vertex for and essentially vertex says the core library so first and foremost just want to point out their event bus and it's so it's a bit kind of like make it you know make your development of uh reactive uh simpler too in in that sense so so you can see so i won't kind of read over all of it here but essentially writing your tcp clients and servers writing http clients and the event bus and deploying and then deploying verticals all these things handled by the vertex core and these these are like examples of using your palm file how you can specify your dependency currently they're at uh three point uh the version three nine two but four always supposed to come up pretty soon too so it supports for from gradle two and in order to do your vertex is basically you just need to spin up your control center so in order to have your control center it's relatively also straightforward all you need to do is vertex dot vertex and it will bring up your control center and then if you want to add in any runtime options to it um you can kind of specify programmatically like in your you know control center you can basically also pass in your vertex options in this case an example of setting your worker pool size to 40 but you can set like clustering set other kind of parameters too and as such vertex is very event driven so these are some of the example events like timer event has timer has fired some data has arrived on the socket or data has been read from disk an exception has occurred or http server has received a request and some event handling example so this one is probably the one of the simplest case you can use vertex to set a timer so just call set periodic uh specify how long you know you to wait a time the event frequency so here i'm i have like 1000 milliseconds which means it's like a second then i print out a timer fired uh to the console and then there's also receiving an http request uh over here now for floortex you always want to use a handler uh to handle to any kind of events so in this case for http i have a request handler and to print out hello world so in vertex 2 it has a concept of the vertical model it's similar to the actor model like apka which kind of is the was is derivative derives derived from berlin right so but uh vertex uh vertical is not exactly the same like that it's not a requirement but it's a unit of deployment um in for the runtime too and the vertical process is uh incoming events over the event loop and so example of events like receiving network buffers timing events all these things and some example or some more discussion about event loop they are generally used in asynchronous programming models and each event gets processed in a reasonable amount of time so then the idea is not to hold up you know the not not to block the event loop every event loop is attached to a thread and by default vertex attaches to event loops per cpu core thread and event loop and vertical so a regular vertical always processes events on the same thread and so no need to do any kind of explicit you know for your if you're using it to do any threat coordination and it can be passed some configuration and it can also be deployed multiple times too and this is an ex like a diagram that explains like if you're doing a configuration you just pass to the vertical and then it gets deployed and basically two is that then the event bus will then handle this accordingly and you can be listening for some changes in your configuration uh too and that type of stuff so it can you know basically any kind of configuration changes can be hotly deployed back into your server like that so you can also deploy a vertical many times multiple times and here some polycloth kind of discussion too like i said i talked about it earlier it supports a variety of languages i think for python enclosure will be an earlier version it may not be supported yet in the later versions and it doesn't force any usage of any languages but it allows programmers to pick and choose any or all really true interoperability um made possible essentially by the event bus and the messaging infrastructure so this is an example too that i will be uh showing like let's let me kind of show some code it's been kind of i just keep talking so okay so example illustration here i just do a an example of a an api gateway so sort of kind of uh like yeah kind of handles funnels some http requests it runs in the jvm and then i'm basically in implementing my worker vertical in java in kotlin and javascript so for the javascript part i'm using a sock.js bridge to kind of connect the two but otherwise too it's the first you know any languages implementation of the vertical are handled by the event bus so so let me then exit in this case and bring up my code over here and oh sorry and multiple things so okay i think this this is the one yeah i just have okay just very quickly too because assuming not everybody has done it so i i will just quickly show the code and this is what i will be also using hopefully if i have time can quickly show you how do you deploy it to the cloud so over here too um to do a vertical you can all you need to do is just extends um abstract vertical in here so kind of explain to you here well actually i think because i was changing some my um my bill gradle so i think something is broken in here so well anyway sorry but otherwise too it should be like showing up i was hoping to show right the uh the the javadoc to it but but it will work anyway i just uh don't pay attention to the problems right here so it's always when you're trying to do code stuff it's always of something so over here too the hello world i'm doing is just in my start so any um vertical you just need to override the start method and then over here immediately i can just do like a vertex set periodic to set a timer also like create an http server listener in here so over here um in the you know this is kind of include a couple things with a lambda i'm also logging some information to the locker and also then print out my hello and and then i bind you know the port to my listener in here and so in order to start your vertex all you need to do in the main you just do vertex.vertex and then you do a vertex dot deploy vertical that's how you do it and and it's just as simple as that okay so that's that and then let me then move on to my uh api vertical uh here which is kind of strange i actually had it uh working earlier i'm not sure like why often something maybe i kind of right before i start when i realized i changed something in in my build file so okay let me then take a really quick look because i realize time is running short so that uh with the polyglot example likewise too right with my vertical my main vertical i'm extending abstract vertical and then um in my start here as you can see this actually i'm making use of the uh the configuration uh essentially the config retriever that i'm using in here so then this way i can set up my configuration and all i'm doing is that i create my config retriever and then i pass in my vertex and and then my config retriever options to add the file store to it and then over here too once is up in that case then over here too i'm also like calling a method to do all the essentially starting starting it up and also initiating and deploying all of my uh worker verticals in there but then also i want to point out is that the config retriever i can set the listener in here and listen for any changes so if any changes is changing my json my uh my properties file just json is simple one that specify the port number and a couple of parameters in here delay and some work account then basically um any changes to that then they will get picked up and essentially being processed right away uh hotly deployed so okay so let me kind of go then without kind of getting in all of these things but in my startup i'm also like specifying my router and all these things and like over here uh with the sock.js bridge for setting it up to talk to the javascript okay so all of those things aren't there and you know as an example then i also like start my http server in here so over here if all succeeded then i basically will call the method to deploy all of my worker verticals in here so let's take a look quick look then in the in my deploy of these verticals so deploy java worker so same thing when i do my deploy my java vertical all i need to do i take the the control center over here and do a dot deploy vertical and pass in my class name of my vertical and then the other options and then also then with the you know the response that needs to happen and i'm also logging some of these uh kind of metrics too so just so you know so again this is just a demo program so nothing too fancy other than just showing the mechanics of how we kind of can support my polyglot case so over here too this would be my deploy kotlin worker and it's pretty much kind of same kind of code and i can refactor it but for now for demo purpose i just also do a deploy vehicle and then give it the kotlin worker vertical class name class dot get name to it and javascript likewise i also do deploy vertical and then pass in my javascript file to it so that's pretty much it and of course there are some more details too but i won't it doesn't appear i have too much time to show um but in the meantime let me um let me uh swap neil can i talk two more minutes maybe um kind of make sure i kind of realize this already yeah sure go ahead yeah okay thank you um i tried to be a little bit uh okay let me okay the only thing is i can't get to my okay here we go all right so just showing the part to the cloud now um okay so i bring in my uh ibm cloud console um so so the idea is that okay i let's say right i'll just talk through it so this is my openshift uh console that's kind of deployed into my ibm cloud of course there are a lot of magic already so i won't have time to discuss all of it but it's pretty pretty much kind of standard thing i open up my openshift console and i also want to make sure that i have installed a serverless operator so the serverless operator for openshift is essentially the k native so in this particular case i'm actually using k native serving uh to do the deployment and then also there's k-native eventing but i'm not leveraging on that just yet yeah maybe at the next some other future um presentation i'll do that as well so okay so over here these are just you know when you're on the console you can kind of capture how you can actually log on and the nice thing about this is that there's a cloud shell so cloud shell is what you can invoke when you go back and kind of go back to my this here so on your console there's also a option for you to open up a cloud shell so that's kind of really convenient having a cloud shell so over here i happen to be um having my code ready so over there um so okay now i'm doing some magic in here i basically build my code and i then would do a doctor uh build image and essentially build the image and then with the build image then i i push the the image to my docker hub then all i'm needing to do and in this case then look at um all i will need is a surface yaml file to describe so this is my service yammer file uh that's k native uh kind of as you can see so the nice thing about k native is that a very quick note is you know it handles um the traffic for you handles the version for you and uh the revision and also uh and it's using like by default it's using istio underneath um but you can also use other um kind of surface mesh like networking uh kind of libraries underneath uh that it's on on you know with openshift that can support this uh k native so okay so all you would need to do a very simple case of hello world then i can just uh do this and over here and i quickly want to show too is that there's a spec section in which i specify the name of my application i also want to give like a version like a v1 for example so that's how then the um it's it's able to tell that your you know it is it helps you with some versioning that's there so yeah all these details i won't go into the you know all the details description just want to show to you so my image is here now over here it just happens this is a conference i just recently did so i'm because i know that works so i'm just trying to show it in here and this is how we can pass in all the environment uh information through this environment variable called target and that's how i can do it so now assuming there's a lot of magic to do so all i need to do openshift client oc and i just need to do and apply uh or actually apply and uh dash file name and and i should be able to then um use surface it then it should be able to uh do the deploy oops okay uh i think it always happened right this kind of thing um why is it not no i think i think i know why but but you get the idea um i think it's i should be using like a double double dash so sorry i think i'm kind of already very much over time but yeah so so that's the idea so it's you know of course you know borrowing all the setup too um yeah anyway i okay so i actually seem to be having some issue in here but i know it works because i've done it before but again that's the idea i think there might might be some setup in my particular situation too so but again just wanted to quickly show you the deployment part um it can be like as simple as that right after you set up everything so that's the idea and then um let me then get back to my slide to kind of finish this up and and uh just a couple more slides too hopefully not too long and i but i cannot i cannot get to my i'm so sorry my mouse i kind of can get to it okay i'm sorry okay maybe i'll use my touch bar okay here we go so okay so i just did all that and now i just want to okay build part i also did but uh what is going on oh i think i swapped the other thing i'm so sorry okay well i'm so sorry let me uh let me swap it back i'm sorry okay here we go uh okay okay so so these are just uh example of if you want to do dr build and dr push and then do the oc apply file name and that's what is needed so okay so with that comes to an end and i appreciate your patience with me um this so as mentioned too i'm also doing a live stream on twitch uh every wednesday uh gmt actually i should say chicago time it should be gmt minus six and it's wednesday about 12 30 to one that's the time i'll do uh for about an hour to about an hour and a half so currently i'm working on some reactive operator reactive extension rx operators um and also too if you like to continue conversations i also have a discord channel so if you want to join me on discord you are very welcome to and these are some of the uh you know resources links so if you want to get more information on the uh reactive systems on the ibm developer you can look that up and the k native documentation as well as open shift uh information so and with that this comes to an end thank you so much appreciate all your patience and thank you to oli to alexi to the scale by the bay it's been a fantastic event i enjoyed it a lot thank you swapnil for graciously being my host and not rushing me so thank you so much and everybody please have a great weekend stay safe you