Reactive Microservices on the JVM with Vert.x by Burr Sutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's everyone doing all right you're excited how many team came to the presentation on Wednesday night and saw some of this okay so you're gonna see some same things again but I got a new one okay got a new one and actually this one's a particularly hard when it's running right now what's specifically happening happening is I'm streaming sensor data live on the stage from these little guys right here and we'll play go end up in a second to my own Wi-Fi router which is also saying you're on stage so this is mine is my router okay streaming it into my laptop and my laptop is pushed pulling it through vertex running right here in the background so that's vertex just running its about this amount of code so we're not talking a larger body of code and then it's streaming it out directly to my browser that's what's happening here now you guys ready to get started now okay let's go and get started then are you guys going to record this - fantastic okay because so this is a fun well let's see if it works I'm not currently on the network I'm on my private network and there's a reason why so we're going to talk about reactive programming we're going to talk about reactive systems if you saw my presentation on when tonight we'll cover some of those same demonstrations we can get them all working again but this isn't one that I kinda is kind of special because it does take a little setup in the world and the future world right where you have mobile devices by the billions or you have IOT devices by the trillions you cannot do traditional synchronous enterprise Java programming models and keep up you will be overwhelmed either you'll have to put a fleet of clustered servers out there like you know by the thousands or you have to do things asynchronously otherwise you simply cannot handle the volume that's kind of a key point with this printer demonstration so what all I have here right now are two sensors running two sensors that I just started about 30 minutes 15 minutes ago actually that lesson that I think about I started the sensors earlier but I just started the counting a few minutes ago so we didn't just let's say 10 minutes I have already 30 for 30 400 transactions into the system with 2 sensors now so for instance I was at the Port Authority yesterday as an example they tend to automate fully industrial automation to basically say look when a container needs to move from ship a to ship be on shore get this crane take this container go from here to here to here that's going to involve a lot more than two sensors when you put that level of robotics into a system you're going to have dozens of sensors as an example per machine and per device and so I'm working with organizations that are working in the industrial Internet of Things and they literally are going to put out hundreds per area of these kinds of sensors so that's why having a reactive programming model can really help you in this case so if you look right here very closely you can see that I'm receiving two types of sensors one is called a TI si si 26:51 is a 25:41 and they both are burst you know because I turned this thing on the same time they both have seen now about 1,700 transactions or actual sensor readings you can see the temperature coming here in Celsius they're about the same but they're not the exact same sensor therefore they have slightly different readings you have to know about these kinds of tricks when you live in this space because every sensor from every manufacturers can be slightly different this is actually the same manufacturer just two different models and they're slightly different even though they're sitting side-by-side now this is where it gets interesting just to kind of hopefully make a point here for you guys this is simply me ssh into the done to the devices so actually let's lay out two volunteers who can volunteer I just need two volunteers real quickly who wants to it can be anybody how about you man would you like super easy and you sir come on up here alright so here's what this is you can use be on this side and you can be on this side alright so this right here is my Linux server this is my Linux computer what the biggest thing about this is actually the battery so it's running on a battery has both a Bluetooth radio and a Wi-Fi radio on that it's known as the Intel Edison I'm actually working to replace them right now with a Raspberry Pi zero the new Raspberry Pi zero that actually has the Bluetooth and Wi-Fi I left them in the hotel because they're not quite right yet because Wi-Fi is fine bluetooth is tricky just I'll let you know that now and so the device itself is this guy you can hold on to him he's a he's the TI sensor tag and he operates via bluetooth to that Linux server who's been communicating via Wi-Fi through this Wi-Fi router this Wi-Fi router over to my laptop so watch what happens here okay so if you don't mind just put your hand oh you know just kind of close in your hand okay and you kind of see the temperature changing we're now at 240 degrees now kind of open it up and let it cool off a little bit you can open it up you know just like that and you'll see the temperature drop so here's the top graph right there so if you would grab that one okay same idea for you if you cover it up see it you just covered it up and it started shooting up in temperature there so if you kind of open it up let it cool you'll see the temperature drop and if you heat it up you'll see the temperature right you could you could there isn't you will have to worry about distance so I actually I'm working with a specific company that with bluetooth you have some limits right so all this is based on radio frequency it's all based on 2.4 gigahertz technology right so you could put it in your pocket you could wear it okay I actually like your idea there it will still work but within a certain distance and then you'll start seeing failures packets will get lost so you probably go sit back in your chair without a problem okay but it also has to let do with RF interference in the room or RF interference when industrial machinery so you'd probably find in this distance you could probably find all the way in the back of the room but it depends on how many other devices are between you and that I know that sounds kind of odd but this is the kind of things you have to think about but from a programming model standpoint you guys can try to well look at yours actually went crazy it's up to 200 degrees now so and they sent and then you can see now it's reset itself it figured out probably it was an error and it's come back but all this is simply happening with these little sensors through these little Linux servers into the Wi-Fi router into the system so I asked these folks here just because to prove that it works okay that they're cool thank you so much thank you now her her question about how far can I take it is very very important okay because let me show you this again in a reactive world in an async world you can do this little temperature sense sensor thing which is what we're doing right now and by the way that sensor actually streams ten different sensors census it has temperature humidity a barometer barometer for humidity as well as air pressure it also will do a gyroscope how much is it moving that's a very important one vibrations very important to actually track in an industrial setting vibration tells you when a machine is going to break right so heat and vibration and two things you primarily want to monitor but also you have to look at things like has a compass right a magnetometer and also has a Lux ometer how much light is in the area so if you're trying to monitor darkness or lightness for a reason you can do that too now this distance things super important because here's what you can do with a little Bluetooth device because we specifically gave Bluetooth chips to a whole bunch of people like yourselves at a conference they put it on their lanyard they had a little Bluetooth chip just like this little guy here but cheaper this guy's about twenty nine dollars with all that sensors that one would just the Bluetooth beacon on it was five dollars each so we gave the several hundred of them away so that's why they had to be cheaper but we then set up raspberry PI's kind of like my little until Edison's in rooms around the building and as you entered from room to room to room it's constantly sending out its beacon and we're constantly monitoring your activity by basically grabbing that UUID every Bluetooth radio has a unique identifier grabbing that unique identifier sending it to our spark engine apache spark who's doing real-time analytics to say which sensor are you closest to and this is what you get when you do that so this is actually at a Boston Convention Center we processed over seven million transactions through the course of a conference day and you can kind of see everyone in the top right they're showing up at breakfast that's the breakfast room so everybody's showing up for breakfast okay you can see we're sampling traffic now we go to breakouts alright so you see what's coming to the breakouts right here these are the breakout sessions and we go back and forth from breakout the breakout to breakout and so this is a streaming I've recorded this that same day and then about about four o'clock in afternoon everyone starts to gather for our keynote you can see there's a little bit of other activity you can see watch what happens here because we specifically have a keynote and there's everyone going to the keynote room now and now let me just pause it there because we specifically wanted was to say when everyone showed up the keynote we could show them they showed up for the keynote by the way each of these was uniquely identifiable you could click on these balls and would tell you who it was okay I did make a joke at that point what everybody said look okay we didn't put any sensors in the bathrooms nor the bars so all we know is if you were in the break room right or in the breakout sessions that was it but we then had our session our keynote and then everyone left the keynote kind of thing so you kind of see people epping and flowing and as the day goes on you start seeing them leave the building so we're about 10 o'clock at night now you know and people are just leaving the building for the day seven million transactions process all with a bunch of $5 Bluetooth sensors and a series of raspberry PI's pushing it through apache spark engine and doing real-time analytics to draw this graph so this graph actually updated in real time all throughout the day and I asked the team to put in a mechanism so I could capture the date and record it that's all so I have this video so that's an example of a reactive system also we specifically use vertex actually as part of the implementation of this so this is this would give you good context for what about talk about now okay we already spent 10 minutes on this we gotta get movin so let me do this I'm going to switch to I'm just going to switch actually to my phone just to make this simple all right there it is let me get on line here and we'll get started with this presentation see that's not being started yet okay look just thing still running yep okay our 2/3 2/3 all right let's go over here come on Connect connect connect it's trying to connect there we go okay so a couple things to note I specifically work for an organization called Red Hat developers or developers are red comm is our URL there are stickers but in the booth there's also this cool t-shirt and the booth if you will stop by and sign up for the developer program which is free you if you're there early enough you get when these cool t-shirts that I'm wearing now but vertex is specifically the technology are going to talk about at this moment okay so there's a book that's available to you at our website you can download the book and also get started on this journey specifically reactive micro-services which is the architecture we're going talk about today from a developer standpoint you have to think in these terms we if we were from the 70s I actually did not program in the seventies though I might look that old but you know maybe you did program in the 70s and if you did you only had to know two of three skills you had to know COBOL and whatever mainframe you had and depending on the mainframe you probably did JCL or whistle actually I did whistle for a little while workflow language if you're a unisys spare universe JCL if you come from the IBM universe and that was what we did the 70s and the 80s it got a little more complicated so we had to learn things like C++ or C I did a lot of C programming in the 80s we learned for GL technologies we learned things like case computer aided software engineering I was a network administrator for a period of time when I was exciting you're thinking what's net where I know it's old but we learned relational database technology sequel and unix and in the 90s it gets even more complicated the point of this is we're constantly learning we're constantly evolving as in software engineers you're constantly growing as developers so now in the 90s we learned HTTP and HTML we may have heard a cgi we had get put post delete cookies I just have to explain to people cookies were not going to steal their credit cards in the 90s I'm serious I've travel around the globe telling people software people they're like I can't add cookies my software it's gone steal people's credit cards no it's not going still peels crack cards but we keep going in the ooohs they're to early 2000s right we introduced things like struts spring hibernate this is when the JBoss app server exploded onto the scene we didn't have to pay $80,000 for WebLogic any longer as an example we learned XML and web you know what WS splat libs you know various web services technology Ajax was born in that decade we probably picked up something like subversion in that decade as an example and in the 2010 the decade we're now probably html5 and that stuff you just saw actually a some html5 technology IOT technology mobile technology like iOS and Android maybe some no sequel kind of thing and reactive is one of these skills so my point with all this is just one more skill and you already have a ton of skills you probably have started to least you know learn or maybe even master I can I can tell you I'm not a master of hardly any of these things I just know how to dabble in all of them in many cases but if you do all this you will be a Silicon Valley unicorn right this is the github unicorn by the way but you could too can be the mythical beast so the reactive technology is where we're at and for this particular presentation reactive programming is often seen as a subset of functional programming it will show you some reactive programming to super simple but there's two real players in that space rx Java and project reactor that are very popular arcs java is most popular at this moment but rx Java specifically came from the folks at Netflix they they looked at this technology from c-sharp it came from dotnet originally from Microsoft Research they figured out this reactive programming model they put it in c-sharp net and then of course Ben Christensen and Netflix saw that as a good thing and re-implemented as Rx java and now we have rx Java rxjs and all these other reactive solutions for every language on the planet so rx Java is primarily the one that I'll focus on here but reactive programming is actually not that hard it is different but it's not that hard okay on the other side of the equation though you have to think in terms of reactive systems we'll spend more time here because reactive systems is where it gets interesting okay break the programming pretty easy reactive systems actually fairly tough fairly hard and this is the world of akka and vertex specifically these are the two main players in this reactive system space you can actually build reactive systems without alcohol Rex you did all the C++ if you wanted to certainly possible because it's a style okay it's not a specific framework per se it's a style of how you build your systems so in this case you can think of vertex as a solution for reactive programming or reactive systems we're going to focus more on the second half of that the reactive system definition is primarily defined by the reactive manifesto so if you go to reactive manifest of that org they're going to talk about being responsive as well as elastic and resilient now the key component of that is message ribbon everything is a sync by default a sync message driven technology you have our block of thread it's the whole idea you never you there are threads be to ignore threads they don't exist in your world if you use akka and the actor model it's a single threaded actor if you use vertex and our model is an event loop it's still a single thread that you worry about meaning you don't program any differently than you would and let's say a servlet or an EJB or spring beam because there you don't deal with threads either normally either okay now the number one rule here is be responsive what do your users do if your website is not that responsive anyone have an idea what users do what do you do when you're like me this sites a little slow refresh refresh refresh because you're helping those guys right you're actually giving them yet a whole nother transaction they cannot respond to so you're not helping them by a refreshing refreshing refreshing though that's what we do as software people and non software people and I've noticed here in Singapore I'm doing this more often because there's a higher latency here it turns out for servers actually and in the US as an example and I've learned that the hard way we'll see that hopefully in a few seconds but being responsive is the ultimate thing you've got to be responsive even if your response is I'm sorry I can't help you right now for instance let's say you show up at the grocery store or the retail outlet and you're in the mall whatever it might be and you see a five person queue that's a long line a big queue to get checked out at the cash register to get the item that you need from the guides checkout counter if the person the checkout counter nicely leans around says oh I'm sorry but I'll be with you in a minute you will wait ten more minutes if they ignore you you will leave immediately this is the nature of how humans work it's the same thing true as true of websites also so being responsive is critical to make that point I'll show you this demonstration ok come on exit out of look look at that beach ball going crazy alright let's shut this guy down actually over here and let's go or here we don't need these guys running anymore let's see if they'll shut down for me and actually I changed Network so they're not going to shut down for me so fine just go away let's go over here let's find the right item I'm going to show you just a simple spring boot application let's go and get it running and yeah yeah a little spring good application I kind of make the point here let's actually look at this little spring boot application right here is this guy it is 13 megabytes in size that's the spring boot application running is a fat jar it's now up and running if I come over here and actually interact with it I go to localhost and it actually says and being say say goodbye and actually let's watch it so if I hit goodbye goodbye goodbye works great but it works with a thread pool like all enterprise Java solutions that works with a thread pool so if I actually send in too many requests watch what happens so there go all our requests and look what happens here the browser locks up all the threads are in use every other request is in a queue if I didn't know you had a queue for your web server but they all have queues and I'm now waiting to a thread becomes available and then can respond to my request now it just did ok now I'm back to good again because well technically it's still backed up I think I sent in 200 requests for 100 thread pool that's what it is now this is not doing a thread that sleep it's actually calculating pi it's just running a bunch of really horrible business logic that takes a long time that's all it's calculating PI and takes about 8 seconds per transaction so now we're back to good again ok so in the face of overwhelming load this application was not responsive it was overwhelmed it did not respond and don't think I'm picking on poor spring here here's my app server ok so this is wild fly ball fly swarm it works basically the same way a spring boot same idea it's just that it will also get overwhelmed because it's based on a thread pool it's kinda idea and actually let's look here you can see it so that was a 13 megabytes spring boot this guy right here is to do this guy right here is 50 megabytes so ours is a fool you know more app server kind of thing it's bigger it's 50 megabytes but that's still pretty small if you think about it the whole thing app server and application and 50 megabytes but let's go over here and all right we're good there we go it's responding we put in 200 requests and let's see they're alright the still we're spying out and there we go we're locked up again so my user is not being served so this is a simple concept but this is actually the architecture we're used to dealing with this is the world we live in today with our web logics and websphere x' and Tomcats and everything else that we're used to dealing with from an enterprise Java standpoint now that we have a thread available all right we're going to get and if you hear my CPU fans right now they're going crazy because all that calculating a PI on those CPUs and it looks like we finally have processed enough all right so let's run vertex now ok we're going to run vertex here and let's see there we go vertex starts a lot faster than the rest of them and let's also go here look at the size of that vertex implementation and it's this guy right here and it is six megabytes it's half the size of the spring boot application and a tenth of the size of the blob fly swarm application vastly smaller and it's also faster starting now watch what happens though well not that let's go here to get the right button all right let's push in a bunch of transactions again and it keeps working right if my system is a little slower because I actually have a lot of stuff happening from a CPU standpoint but it always responds to the user you can even see the responses to my user in the middle of all those long-running transactions so it's always responsive there's never a thread being blocked it's always async by default and it's based on an event loop it's actually based on a single threaded model so it actually can process more transactions or a single thread than the other guys can through multiple threads there's a trick tone obviously but in from a programming perspective it just works so if I come back over here I have this code open let me show you this piece of code where to go where to go well okay yeah there we go so it this specifically right here is our spring boot application standard at rest controller of course you have get mapping now but request mapping request method get standard spring abcs standard spring rest controller stuff right this is what you see here's the business logic it prints out the message it computes pi it tells you when it's back from I call it a nap because it seems it takes so long it takes a nap is the idea so that's what happens there here's the wall place warm version the same ok this is Java e jax-rs instead of the at rest controller you have you know I'd get at put at post elite same concept same business logic same just different annotations it works the same way here's the vertex version and it is going to be a little bit different the vertex version basically has the same business logic because this Java but how you set it up is a little bit different this is how you specify your URLs in a and I note in a a vertex world alright so what's kind of zoom in on this a little bit more it has the concept of the router a web router allows you to basically say for this tutorial this URL this URL and open parameters it could be URL parameters or posted parameters it etc you basically then map it to a handler okay this handler has a context and in this case it's basically saying respond in this case the end of the response because my default responses are chunked it assumes you're going to stream but we're not going to stream here we're going to respond with goodbye here's the goodbye message goodbye on vertex and and of course with this URL it hits this piece of code this bit of business logic which calculates by so everything else is the same except for these two lines basically and the magic is actually this thing called the blocking handler because we know that piece of code runs really long we say we it's a blocking component to vary by default you'll get an error message out of Road X if you start blocking if you don't say blocking handle o get real good air and say hey you're blocking stop don't do that you never block the event loop you never block and verb X if you have to block you say so and then you push that off to a background thread pull there's still a thread pull you just don't worry about it okay so the foreground event loop is always available to process a user request so this is seemingly crazy but if you actually are familiar with nodejs this looks familiar to you this is where these ideas come from that cool okay let's jump back into it again let's keep going here and actually we're going to go faster okay you guys are think it's faster but here let's talk about microservices briefly so that's my intro to reactive reactive programming and reactive systems now let's talk about microservices not everybody needs to be doing micro-services and I've actually been in meetings all this week with various organizations throughout Singapore and I can tell you it's actually a good thing to stick with traditional monolithic architecture micro-service is not for everybody because you have to be to pass these kinds of tests by Martin Fowler a thought works people you must be this tall and if you guys aren't familiar with this expression I'm a little guy I'm a little guy by us standards I was actually born in Hawaii I'm half Japanese but I grew up in Alabama and when I'm a little person in Alabama and Georgia and North Carolina where I live and I want to ride rollercoasters but I'm too short to ride a lot of roller coasters in the United States and actually when I was a kid I was definitely too short so they have a sign and from the roller coaster says you must be this tall to ride the ride and I would walk up to it you know and stand on my tiptoes and try to convince the guy to let me on the ride it worked a few times now you got to be this tall to ride this ride you've got to have self-service on-demand elastic infrastructure if it takes you three weeks to get a virtual machine you aren't ready to ride the ride if it takes you longer than three weeks I talk to people like three weeks six weeks to get a virtual machine if it takes you longer than that you really aren't ready to ride a ride if you can't get a new virtual machine within let's say an hour you're not ready to ride this ride resources like that sheep resources like a virtual machine think about how much those things cost nothing how much does your time cost I don't know $50 an hour $25 an hour $100 an hour you have to wait days or weeks to get it nothing a zero cost item it makes no sense it actually sends a bad cultural signal to the organization expensive resources wait on cheap resources bad move so that's bullet number one how long does it take dev versus ops if you throw it over the wall on Friday if you as a developer check in your source code on Friday at 4:45 you head out but all your buddies to the bar you're doing shots of tequila I know you're not here but you know let's say you're doing that you're having beers and the operations team is transferring out and make that code compile tested deploy it and all weekend your crappy code is hurting them you're not ready for micro services either okay you will be there all weekend with them matter of fact you were on the pager now in a microservices world you are now accountable for the quality of your code and the runtime performance of it and the capabilities of it from a business metric standpoint in production if you're willing to do that and your organization's will do that you might be ready for micro services okay automation if you know you guys move there between a snowflake server and a Phoenix server snowflake servers are super cool right you basically someone wrecked a new one you rack-mounted server out there maybe the input some VMS on or whatever right but they basically threw new servers out there in the data center and somebody SSH is in and Yung install or apt-get install and blah blah blah blah blah they tweak some Inadi scripts or systemd scripts right and then they leave it running and they and in some cases they run everything in the background and they don't normally leave the terminal open because that would shut down some processes you guys have had this problem before right and then they leave it running and guess what they can't do to that server they can't reboot it because they have no idea for very boots if it'll come back to life correctly and you may think I'm kidding I've run into people all the time will have this problem so that's a snowflake it's a unique pristine server that only the person who set it up who didn't take good notes by the way and in one case actually was talking to a company to hide this problem the gentleman who set it up was actually hit by a bus in a massive car accident actually and was out for a month and they did not have any idea as to how to operate their service here's what a phoenix server looks like a phoenix server is a vm or a piece of hardware you use something like puppet chef ansible or even something super clever like kubernetes you bake out a script even if it's just a shell script you bake it out to perfection you check that into source control you know exactly what it takes to rebuild that server at a moment's notice and if there's a bug in the server you might SSH n to see what the problem was but you go back to the original script and fix it there you never fix it on the server itself so therefore you can burn the whole thing down and rebuild it in moments that's a different that's the Phoenix server so you've got to be on the phoenix side of this equation if you want to live in this new micro-services world you got to think in terms of CI CD and you know I think it turns you to point a pipeline these are all parts of the equation let's keep going here if you have not read these two books you must read these two books please read these two books the Phoenix project is a phenomenal book it's super easy to read it's not as cool as Game of Thrones I'll tell you that okay but it's close it's actually a work of fiction and specifically it's a work of fiction where they are launching a new project within an organization and they find that when they have a bad deployment they take the business down for days this happened to me one time I had a bad deployment I took the entire business offline for days I had the people of the customers the the business people writing transactions down on paper seriously they went back to paper the good thing is the guy was old enough they counted there he knew how to do paper still some people can't do paper anymore they would just be stuck they were taking credit cards by hand they were doing credits and debits of people's refunds by hand and they were even locked people out of buildings because part of the system actually triggered a door lock for the employees and stuff like that we lock people out of buildings that's what the Phoenix projects kind of about the DevOps handbook is the follow-on to that as course written by Jeanne jazz Patrick John these are all people you should be following on Twitter today this gives you practical guidance and just user stories and people what people have done out there Nico system definitely got to read these books okay so in the old Java world you had an operating system you had Java Virtual Machine an app server you had an ear you have Wars you had multiple drawers and jars and this is where I got tricky because of this monolithic architecture you all had to agree everyone had to agree enterprise architects set the standard they define what this was going to look like they defined what this was going to be based on the ugliest worst-case workload in your whole organization you must use WebSphere nd you cannot move Java used to Java 8 you must live in the past by three years you have to live on this old version of Linux you can't be on a modern version of Linux you have to pack up your ears Wars and jars you know in this certain way everyone had to agree and those actually weren't that bad well WebSphere and D is different issue but one thing goes super bad you all had to agree on the same maven central dependencies you how often we get customer support cases where people have looked at three versions of spring into their app and it doesn't work anymore yes right so two versions of hibernate it doesn't work well if you mix and match versions across some of these dependencies you need to pick the right stack so getting all those things to agree with a big team of people like you see here all these developers operators etc it's a challenge if you have 45 people working on a big monolithic codebase like this you all have to agree and this is why it goes so slow this is why you only deploy every six months this is why you only deploy every nine months it's a high ceremony release that involves everyone working super hard to pull this off now in the world of micro services you split it up into smaller independent teams we refer to these guys now as two pizza teams because you can feed them with two pizzas I've been in Singapore long enough we're not talking Singapore pizzas we're talking American pizzas because this came from Amazon so it'd be maybe four singapore pizzas okay for pizza team but the whole concept is six to eight maybe ten people work together they include all the capabilities they need if they need a awesome DBA they got a DBA they did business analysts they have business maps they need Java coders front-end coder you know J's coders they got the coders I got the operators and they holistically own that piece of the system all the way in the production until end of life there is no throwing it off to some offshore people who will just babysit this thing they own it forever it is their product they take great pride in ownership they insure it's brilliant as an example so you build it you own it these are the Amazon principles as an example so these are the key characteristics of a micro services architecture number one you have to have deployment independence if you cannot independently deploy your component without disruption to anyone else you can you could not do micro services it's really simple if you have to coordinate deployments across a release schedules across all these different teams you're not going to go fast and whole point of this is to go faster to get to production faster to learn faster to get experimentation done faster and if you can't go faster why are you doing this you're just simply hurting yourself in my quickie this afternoon or lunchtime I'll show you demos of these things we're not going to do the demos now but the concept of employment independence is absolutely key a couple other bullets here you want to keep in mind you need to have decentralized governance now this is really going to blow people's minds right this is where each independent teen makes their own decision that's best for them if they decide go as the programming language is the right solution for them they will take advantage of that because that best meets their business needs they might just do WordPress because that meets their business needs okay so they will be independent of each other and they will also have independent databases this is these two bullets is what breaks the back of most average enterprise IT shops they're like nope we're not doing that we have a nice enterprise architecture team and they dictate all the rules around here they said WebSphere and D on Java six for next ten years and do you have to suck it up you and I'm talking to my programmers in a room like condos architects they never let us do anything and actually the architects are in the promise of DBAs right VBA's never let us do anything but that's really we're talking about here architects and DBAs six and seven they're not gonna let you do this okay keep that in mind so if you do have a decentralized data management problem it's and Onaga is actually here you wrote the book on this topic and you need to read this book and understand the principles and techniques in it so you can actually deal with a potential database issue so monolithic database problems go read this book he'll be signing the book I think at 3:30 today in the booth and he's here giving a presentation on this topic so it's an you're not going to check him out these are all the different micro services concerns you should be thinking about I don't want to spend too much time on them because they can actually be fairly hairy and actually I'll demo a lot of these things to you a little bit later in my second session but just keep in mind you need to be thinking in terms of not just your codebase but how do you deal with load balancing and scaling and elasticity resiliency discovery logging you know distributed tracing what is your API strategy going to look like these are all the things you have to have really researched to proper microservices if you're trying to do micro services with oh I'm using spring boot I've got a rest endpoint let's go run it you're not going to have fun with that as a matter of fact you're not going to go any faster with that you're probably just going to make a big distributed ball of mud all right it's going to be spaghetti at the ultimate level and it's not going to be fun for anybody a few years down the road now you're probably thinking I'm going to check out of this organization leave it to someone else keep in mind that whenever we as developers or architects have said would that follow that person thinking the person who comes behind you is going to think the same thing okay because you don't know the constraints that they had to work under you don't know the politics they had to work under and technical ramifications they had to deal with you're going to make bad decisions today that will be future legacy tomorrow it's just nature what we do okay so these are things you need to be thinking about okay there are some key patterns again I don't want to spend a ton of time on this because we'll do the demos later but this is common in the retail outlets they will use the browser to aggregate server-side components so the browser mobile browser in this case we'll call components on the server side very common in the retail outlets that I see so I use a retail example here you can see that my top-level description my price my star rating the descriptors here the thumbnail images there's 15 available in my local store all these in the case of the retail group that I worked with on this are often mainframe implications so they've specifically are calling from the mobile browser to a server an edge service it was Tomcat at one point but they ran out of gas on Tomcat and then they would then in turn call the mainframe the reason I called this pattern out is because this is really really want some async capability because the mobile browsers are not diminishing over time they're only growing over time and especially especially here in Asia the number of people getting smartphones Android in particular like all the folks in Bangalore are trying to get iPhones I was just there a couple weeks ago everybody's getting a smartphone and they're all going to hit your site and they're all going to want responsiveness from your site and if you can do the asynchronous capability here especially if you have to go to some other resource like a slower mainframe a slower old-school database a slower old-school Java EE application then you it really behooves you to put an async layer here as the API gateway or is the edge service some people say oh this resume fits a Netflix ooh sure this is what Netflix invented Zul for this is what Netflix invented rx Java for and history explore the vertex it's the same space all right this is where vertex can live as an example you also have to think in terms of failure what happens if the mainframe does not respond at all or worse more insidiously does not respond in a certain SLA I need to respond to my mobile browser within one second let's say one second mainframe sometimes takes two seconds to respond I need to be at a short-circuit that right there break that connection off and you can do this asynchronously you can't do it synchronously right it's only in the async world you can do this and I'm going to respond to my user in a clever way we'll see vs. 15 available right now I'm going to respond with oh I don't know if 15 are available but I still know your store that's based on the GPS of the device so you change your user interface you change the behavior of the application you change the business logic based on the things you can report back on not the things you cannot so this concept this architectural pattern is incredibly important in a micro service in this next-gen cloud native architecture you have to think about these things this is exactly what Netflix is and Walmart's and Amazon's do if you had if you ever log in Netflix and you'll notice the user interface is different from the day it was before my wife tells me this all the time she's like didn't either my thing dizzle I don't I never even watch these movies sure right I never watch these shows and she's right because Netflix is responding based on overwhelming load with default data it's not her choices it's just default data that's how they deal with it the same kind of concept here ok let's keep going there's also concept of the API gateway where you aggregate that on the server so again the nice thing is you catch the error here there's also the concept of the chain and you want to make sure you don't have a cascading fail roll up your chain to their user these are all things you have to think about in a micro services architecture ok and of course most people will will actually have new the way so they kind of massage this into their own way of thinking but these are the things you'll think about and again I have some demonstration of this in our in our next session all right so the circuit breaker is something you'll want to keep in mind we'll show you a circuit regulator today but the idea is that by default the circuit is closed that means all transactions are flowing but you have a monitor in the middle the monitor is going our transaction is good are they responding as we expect them to or things getting slow are actually not responding at all if it sees things getting slow or not responsive it opens the circuit which means things just bounce off now so basically if that component is dead you don't kick the dead guy any longer you bounce off and you get an immediate fail and that way you can respond to your user your mobile browser with the default data than you have this is this concept of the circuit breaker was popularized by a project called hysteresis as an example but we also have circuit breakers built right into vertex as an example but you can use history too if you want okay so I'm going to skip that figure piece of demo because I got much cooler demos to show you let's talk about vertex down so we talked about reactive we talked about micro-services talk about vertex vertex is a toolkit for building reactive applications on the JVM so we could do this with nodejs this is actually where we learned a lot of these things nodejs universe but I want to do it on the JVM I'm a Java guy having a Java guy for 20 years well I can tolerate JavaScript I write very bad JavaScript mostly because I hate the fact that I don't get compile time error checking until run time right that's just an issue of mine so this is what you can do from a vertex standpoint by default you'll get the core right here where you can speak HTTP or HTTPS B to stuff is really awesome we have a deep dive presentation on that not at this conference but just keep that in mind UDP TCP you can basically open a socket and let bytes flow and that's what you might do with this particular technology that's what was do we were doing with those IOT sensors we were just simply opening up port one eight eight three which is the in QT port and letting bytes flow so from the Bluetooth to the book to the to the little Intel Edison over Wi-Fi into the laptop we're just dealing with a stream at that point so that's something super simple you can do a vertex and it took a page of code for that I took one class ok it doesn't take much to do some of these things you also have the concept of the event bus and shared data so the event bus will see of numerous examples of that and we'll show you some live demos of that but it is super nice because you can specifically have all your JVMs linked together on a common shared piece of memory essentially they're clustered together and a peer-to-peer network and they can work with each other and communicate with each other therefore you can defer jobs to other members of the cluster and you can communicate broadcast messages to the whole cluster you need to request reply messaging across the cluster and then now the question in your mind is oh that's a messaging broker no it is simply in-memory clustering right there's no real message broker here there's no guarantee delivery because we're not writing these transactions to disk and ensuring that the subscriber who eventually comes back online gives us the acknowledgement that he did receive that message and then deleting it from disk that's called a message broker that's your active interior you know your Pesci cop got your RabbitMQ that's what those technologies are that's not this this is purely for light ultra lightweight messaging to make all these custom members talk to each other we can share data with each other we can share processing with each other we'll show you an example the event bus there's some other aspects of this like you can build web applications using like time leaf and templating mechanisms you can you know so if you want a standard angularjs restful back in you know with or you know react angular that kind of thing with a nice vertex back into that no problem that's not a problem at all you can use different programming languages like Java groovy JavaScript or Ruby so I personally like Java but I have a whole demo based on groovy as an example and actually some Ruby and JavaScript in there too so you can basically mix and match all these components your jar file does get bigger depending on which of these you add in you know the one I showed you earlier or super small six megabytes you get a little bigger as you add these guys in because they're just additional jar files you add to your application but you can see the vertex can actually build whole applications we're using the same ideas right so just like any other application solution it's an onion pinyin ated toolkit for reactive async applications it makes async easy that's really the focus of what we've been doing with it if you have the concept of the of the vertex instance you have these verticals that's what we refer to them think of them as programs spring of them as classes in Java sense it be a dot groovy file or dot RB file dot J's file or dot Java file right that's your vertical that's what they are they all have the event bus available to them even if you stay in the same JVM right they can communicate with each other all within the same JVM or across JVM that's really what we're going to see in a moment okay it's all based on this concept of the event loop the event loop is super simple you have let's say browsers giving you get put post and delete IOT sensors whatever it might be flowing in those events are coming through a queue you basically have this wild true loop it's just looping and it says get the next then find the registered handler in the case of IOT sensor oh there's a handler that says I want to handle that IOT sensors data and it in turn does a dispatch okay through an async call to update the browser so async async async but it doesn't really look that hard right because we the programming model so this concept of the event loop is just what is the architecture this is all single threaded from your perspective okay if you have a multi-core machine you actually get an event loop record so this is important it's a multi reactor pattern some people for reactor pattern multi reactor pattern the reason this is important is there's actually a lot of benchmarks on the public internet you can google and find to talk about vertex versus nodejs and vertex often one and people like how's that even possible no jesus is the fastest thing ever created in history it's actually not okay if you go to tech and power benchmarks and actually look for nodejs in those benchmarks it's sometimes in the 10th or 12th place a whole lot of people are beating no chance these times vertex being one of those who's beaten in a few categories and one of the reasons for dec speed set is because of this we can take advantage of all the cores you give us ok super simple but in other cases of serialization for this or it's the optimization of the JVM with the jet you know you know things everything wins in different ways but I can tell you that the c-sharp guys I've met them they guarantee you they're going to be no js' they're all over they're not number one today they're going to be number one the future if you're using the Kestrel server this built a new C sharp core it's amazing so that's a different thing but done everybody's fighting for that here we go here's a super simple main method our super simple application I mean so it's my main vertical it extends abstract vertical this is typically what you write so it's one import state but one's class declaration one method and in that method you then set up the rest of the things this sets up the HTTP server and you can see right here it simply responds with a hello vertex and it listens on port 8080 okay and if you're familiar with no GS you're like oh that's kind of like node yes exactly okay and then we also have the getting started part of it I won't spend a lot of time on this but you just create a directory and then you basically can run this if you want to this actually is just a maven plug-in that'll generate a default vertex application for you copy and paste it from these slides and then maven compiled vertex run and the cool thing about that is it treats Java as a dynamic language also so groovy and Ruby are dynamic but teach Java is dynamic language it will dynamically co-pilot on the fly every time you make changes to it and rerun it and this is kind of neat just read hot reloads the Java files on the fly and this is what may be a more advanced program might look like you can see here there's the router so I specify the specific routes and then I have very specific business logic to respond to those route requests so simple restful endpoints are very simple okay let's see here this is the concept of the router it basically routes different handlers and actually sends out the responses here's what a more advanced router might look like you can see we actually have in this case is the method reference we have the parameter right here you can see where we're going to this delete one you know it's basically these are just other business logic methods associated with these routes that's all you also have the concept of the static hammer meaning if you have HTML files CSS files JavaScript files it'll load those two-room pretty fast aren't I we're not moving really fast enough we're almost out of time so let's get going ok let's show you these things let's see if is in fact my stuff is still working here we'll find out the then let's see can I get into my server come on connect for me can I'm using my phone here there we go alright so I have a server out on the public Internet it's at web bur dot red you guys can try it out but let's do this under tension to do and I'm just basically navigating a maven project as you can see right here good I have Java alright I have just uh yeah calm I'm trying to remember these things BRR yeah reactive workshop I did all these for reactive workshop and speed not too long ago and there's my vertical so VI main vertical and let's look at it here this has the router built in basically it has some neat things in it like if you actually respond so if you get the root it just responds to this little bit of text if you actually get hello and with the name it actually responds with the name there and so let's do this tintin tintin tintin tintin not not that one let's go this one here all right let's do this rope look look do your doctor okay this thing is a little bit weird right it's a little um yeah did I do that okay I always get a little whenever the keystrokes don't respond immediately always messes me up let's see here pseudo vertex run main I think I can do it this way I have to remember if I'm in the right directory sometimes it doesn't like it if you're in the right directory then let's go here and so web burnout red hello and there you go so hello a ship in space there you guys want to try that try that pull out your phone and try this because this this is going to get more interesting trust me so if you have your phone out try web that bird out red I just wrote that little program or updated a little program and run it for you that's how hard it is to build a vertex application on the public internet in this case so you can SSH in this is an example of a snowflake by the way right I didn't do my ansible playbook and push out these changes I just simply went in there and edit in the code but there we actually have a nice little application okay you can see right there and this is a very small server but there you go now I'm gonna actually just kill it real quick I just shut the server down for those you're connected to it and actually I do have some challenges with the server and now that it does not want to release in some cases so let's see here I will SSH in here and actually I'm going to bring these guys up while we're at it I'm just making other connections to it let's see distant and Jen Jen Jen Jen let's see is it still really nope it actually shut down yeah it shut down okay so that's an example of a web app but let's do this well alright let's go here I'm going to show you this guy now so the same kind of web application that you saw earlier so what we're going to do it this way we're going to run a web application that has the eventbus built into it and now once it gets connected looks like if you guys come up here and just put web burnout red and hit refresh here's what that's going to look like okay I'm connected and the server is going to just push me messages so this is an example where the event bus can bridge across the back plane of the JVMs on the server side and send and wow you guys really all those socket connections all you guys alright so that's you guys connecting so you guys connecting and you're getting a stream of messages from my really slow Northern Virginia server because that's where I was when I set this up so if it's not performing very well it's got to come across the entire globe to get hear those messages but watch what happens when I do these other things okay so we've got message flowing and O's 6 let's show you this I'm going to let slide up the job of publisher so now we're gonna get Java messages coming in there oh six well it helps if you actually type in 0 6 and it let's actually do this let's do a JavaScript consumer all right so we're putting all away the guys so you get you're getting you get Java messages now right ok ok so I can even come in here and say let's we have all this stuff happening now so all the spurning I'm server I want a groovy consumer how about that I want my groovy guy running and so basically on the server side I have listeners on the server side and all the listeners in this room seeing these messages and I can come over here and SSH plan 8 web Burnette red and oh man 9 minutes we gotta go faster come on connecting connecting Siddhant ending ok we can now say let's add Ruby messages to that mix so here come the Ruby messages and so and actually while we're doing that I want to shut down the Java messages will kill the Java messages there so you're going to lose Java messages and you're going to gain ruby messages as soon as that guy cuz it's very go there's our Ruby messages fly so all this takes almost no lines of code right now you can show you the code real quickly it's super simple and all this is available on github so here's my HP TT one this one right here specifically is like here's my publisher for Java right here's my consumer for Java if you actually look at the consumer for others like here's my consumer for Ruby I can my publisher for Ruby they're almost the same API is because they are they all have the eventbus available to them we even have the eventbus available as in npm so you just if you have a pure node.js application you can light it up on the event bus - and so it's a pretty simple tool but it gives you some amazing powers ok so let me shut these guys down ok we're shutting these guys do don't and it does take a while to clean those JVMs up let's see here see we got a bunch I'm running so let's just kill -9 a few these guys did that okay Oh help by CD we're not well we're getting rid of someone and just instant turn just it to do away ah alright so do kill my decide go away what else do we have running and one more yeah Denson it's a tiny little server so it struggles with all these things okay there we go Oh 4006 what it was and it would help that this thing okay he'd already stopped all right so good we're back to clean again so let's do this we're going to go back here and now imma let me bring up another server this is where a fat jar is crazy you saw me - a fat jar earlier but now I'm going to do is another fat jar in this case I'm going to run this one it's going to bring up my web server again if you go to refresh at webdiver not read okay someone's already connected I see the socket connected there let me connect okay watch what happens now a lot of people are connecting fantastic and I'm going to bring up the dashboard this is an example where the event bus allows you to paint pictures so someone's look at that already painting pictures so basically if I come over here and I flip it in my B and you can see what's happening now this is working off your 3G connection your 4G connection to my server in Virginia I'll light all the way back here to my browser here on stage wearing through my phone you think about that for a second that's actually pretty amazing it's going across the globe and back again based on the keys I basically a programmed it so the end of stroke right when you release your fingertip it sends the entire civilized html5 canvas over the wire because I did know how to code this so I just like awesome the whole damn canvas is sterilizable through the event bus and back out to the actual browser in a thumbnail form so you guys are having a good time here it's you and I have to admit though in Latinamerica I get some pretty awesome art you guys would have to work a little harder here but you can stall so if you also refresh you know if you if you have refresh you'll get another panel I set it up that way on purpose so come over here and you see my B okay so there you go so that example is again the eventbus allows you to do some pretty interesting things so let's let's make this a little bit more interesting now okay I'm gonna go ahead and just shut that guy down and I want you to switch to a different URL this time because this one actually did require a little bit of a little bit of work you're going to go to game that burn out red G AME bird on red and actually this game that burned out red okay you're going to get a user interface it looks like this and says play game but game DUP bird up red and a redirect your accordingly okay game that bird out red and watch what happens here we have a little game we're going to play with you guys and it's going to involve balloon popping it's like fruit and in Jove you guys get the popping balloons there and I'm gonna bring up some other stuff here alright I'm going to game that bird out red I'm going to bring up the leaderboard let's see how many of you guys are out you get allow you guys are already well into this thing already let you go to scoring points like crazy there you go again the same kind of concept you guys are playing on your 3G across in this case I did move this server to Singapore the latency was noticeable enough that I did move this server but we're almost to a thousand transactions in a few seconds it took me to load these pages based on your guys phones okay so pops or transactions now the important thing here you guys keep playing as you understand this is going to go from your phone basically pop is a transaction to my server my vertex server whose asynchronously then interacting with a traditional Java EE application on a traditional Java app server known as JBoss running the business rules engine known as drools who's calculating your achievements and updating the whole system and updating this dashboard real-time so you can see people have already broken the ten-point barrier they've knighted the 300 point or 500 point barrier probably cuz the games too hard let's make this a bit easier let's come over here and actually let's make these balloons big and go okay now we're going to big balloons you got big balloons and actually let's make it even easier let's give you red balloons count as 10 how about that and I want to change the background to blue and go now you guys are having some more fun to get even more points happening there in real time you guys think that's cool so far but wait okay you guys are having too much fun here huh so hold on a second okay I needed your attention for a minute okay so this is important these this what what you're doing I know you guys are playing you're like oh there's also my playing games one more time this is what we're dealing with here okay your phone is popping these balloons is hitting a vertex game server running on a simple ec2 instance there's three JVM is running on a single server and we basically have the verdicts achievement server which holds the body of achievements they're the Britax game server which is based on groovy it's dealing with all your socket connections all your real-time interactions you'll notice too on your phone you're getting real-time updates to the phone it's saying you've got this achievement you've got this achievement each achievement is being scored through a traditional Java EE application again asynchronously so you will see it be a little behind because it's asynchronously handing it off to this other process and it in turn is in letting everybody know the dashboards know the current achievements as well as your phone that's the architecture we're dealing with here now you guys want to play some more all right let's do this let's go back boom all right we're playing again but let's not go look more interesting let's make them fast and invisible and you know that kind of thing and go all right let's see what it looks like I lost my little window here where you go there we go there they are you're doing it now but games too hard okay too hard but actually okay we'll make them bigger again a little slower you know make it looser will give you more points for these guys done centa and actually let's turn onto Golden Snitch this is the team who built this with me thought this was funny so let's go ahead and add that into play so we change the background color and now you should have a very interesting extra bonus point there and seriously they're like well let's add this in I'm like oh okay and now you can see our points there we go you can see everybody scoring this is the name on your phone so you guys should you guys have these names okay we assign names on purpose because people would otherwise put bad names into the system you saw what happened when we let you finger paint earlier right okay this is part of the problem but it is time for this game to be over okay let's see did it work and here's what here's what's funny you see there's two people still in the game I've had this problem especially in low latency environments the message doesn't make it all the way back to your phone to tell you the phone to turn off so maybe we'll end up winning this game because they were able to stay in it's actually a part I got to fix this on the server side so instead of worrying about only the client-side but by default think about this we're doing everything between the client server and making that phone the gaming engine it's a 60 frame per second gaming engine running inside your browser and we're simply doing all the interactions here on the server side if you see your name up here we actually do have a special prize for you guys we actually have a won the custom t-shirts I talked about earlier this nice young lady is going to be passing them out but thank you so much for your time today we're at the top of the hour if you have questions I'll be available for the rest of the day until my next demonstration where we show you all the cool micro service e blue/green deployment connect canary stuff it will show you all right is that cool if you want these slides one thing just make note up here the slide deck and all the demos are listed at bitly reactive ms aid right there that's the URL you'll want to check out also follow me on twitter i'll tweet these things out too but thank you so much for your time hopefully you had a good time and found this be interesting now bring up the leaderboard one more time so if you're on here really we got a t-shirt for you come up and get it
Info
Channel: Devoxx
Views: 25,946
Rating: 4.908524 out of 5
Keywords: DVS17
Id: MydhJVPEnzU
Channel Id: undefined
Length: 60min 40sec (3640 seconds)
Published: Mon Jun 19 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.