 Welcome everybody. I'm glad you're here. Thank you so much for coming I know that you have a lot of excellent choices indeed if I were not here I would be in some of these other talks as well So I appreciate that you chose to spend your time here in this morning with little old me now Guards lock the doors lock the doors bar the doors and make sure that everybody is sat where they're supposed to be We're gonna go through a lot of stuff I just realized all of them like a minute ago that this is supposed to be in theory of 45 minute talk But it's not a 45 minute talk. So, you know, hold on tight We're gonna go a little faster than we might have otherwise had to go All right, we're gonna go through a lot of stuff and the goal as usual isn't so much to to to understand individual Things that I'm doing. It's to appreciate what's possible And as such I put up the code there. It's online. It's your own reference and edification for later on It's a git repository that contains all the code that you're gonna need to be able to understand everything We're gonna talk about today. And if you should have questions I'm always happy to answer questions. Don't hesitate to reach out to me by a Twitter for example It's 2018. How many of you using how many of you using Twitter? I'm just curious Twitter Twitter 2018. All right, the rest of you Get on it. Come on. It's a great place to be. It's the new IRC It's where the developers that drive the open source that power your business are and if you want to engage Oh, just have to be there. What about email is anybody here using email? email anybody email email no very good, okay moving on we're in a post-slack world people I'm not even sure what that means, but it's a thing people are saying so email. I don't have a fax machine either so It's fine. Whatever. If you want to reach out to me there do please a little bit about myself My name is Josh long. I'm a spring developer advocate on the spring team. I'm an open source engineer and contributor I have the dubious distinction of being the number one the most prolific the most highly-lotted most Visible most acclaimed contributor Of bugs but still number one number one number one across all the projects to which I've been a contributor and committer of the last You know 10 plus years, okay? I am also a book author and a training video leader and so on so I've done all sorts of You know instructional things is in my capacity as a spring developer advocate in a Java champion I've finished some videos. I've got videos on applied continuous delivery I've got videos on cloud foundry and Services with spring and rest API is and all these sorts of things on the Safari online marketplace from the live lesson series I also just finished my fifth book my fifth book It's called cloud native Java and this book is all about how to build applications that survive and thrive in the cloud It's all about how to build applications that survive and thrive in the cloud in terms of spring boot Spring cloud and cloud foundry. These are open source technologies that are designed to allow you to build applications faster And this book took a little longer than I thought it would it wasn't it wasn't It wasn't as agile as we'd hoped if I'm honest. It took a little longer. We we should have known better We should have known better we we know that the software engineers are notoriously not great at estimation So we thought six months roughly in and out will be done with the book And then we'll we'll be off to the races and we can enjoy our lives But it took out it took out turned out it took a took a little longer took a little longer than than six months It took it took a little just a little bit took 18 months longer than than six months It was it was a little longer than we expected and there's a lot of back and forth that went on behind behind the scenes And I want to explain that to you I I don't want to air out my dirty laundry But I'm just gonna go ahead and say it O'Reilly and we the authors we had some trouble We had some trouble you see there's a lot of back and forth a lot of deliberation that went on and choosing the animal on the cover Anybody who knows anything about O'Reilly books knows that it doesn't all that much matter What's in the book proper it has everything to do with the animal on the cover So we eventually settled after 18 months of deliberation back and forth back and forth on this blue-eared kingfisher a Blue-eared it's a bird with ears. Have you ever seen a bird with ears? They look very silly Anyway, it's a bird with blue ears, and it's called the kingfisher. It's from the Indonesian Java Islands and it's a bird and Birds fly yes through the clouds, so it's a bird That is native to Java that flies through the clouds. It's a cloud native Java bird. It's a bird in their mind It'll come give give a time give a time. There's that right and of course I should mention that we're hiring at pivotal right it We have lots of open positions if you're at all interested in working in the open source and fighting the good fight We'd we'd love to have you it's not really a fight Nobody has to nobody has to get hurt by the way It's just a metaphor but please join us and also I work at pivotal which is nice for me And we have a lot of great open-source software pivotal We care about the open-source software pivotal it it is a big part of what we're doing, but let's be very clear at the end of the Day, it's not the main reason. We're here. It's not the reason that people like myself Spring out of bed You see what we care about first and foremost above all else is helping people build better software faster moving an idea from concept To customer from idea to inception all the way up to production We want to see that cycle reduced as quickly as possible and we want to see people do so safely, right? It's anybody can get in a Ferrari and go, uh, you know As fast as possible. That's not necessarily safe. All right, so we We see that a lot of organizations struggle with this They know they need to go faster, but they struggle because they have these Large existing monolithic applications these applications are a good problem to have most of these companies are Victims of their own success The software was written in yesteryear before the era of cloud computing before the economics of cloud computing and is such It represents a bit of a burden these days It takes a long time to affect any change in this large Unyielding sort of burdensome code base and the reason I think for that has to do with the size of the team That eventually has to scale out to accommodate that code base It's easy to say. Oh, well, you're a startup and these startups are small and thus they're able to succeed They're able to iterate quickly and say that it's impossible at scale That's just not true That ignores the success of companies like netflix and amazon and and twitter and all these other Massive engineering groups that still succeed still iterate quickly and you know Safely so the question is what is the important thing here? What is the thing? What is the key to their success and there's no one thing certainly But I think a lot of it has to do with the size of the teams working on the code base You see in having small teams you deliver software as though you are a startup Even if you have to work with at some point other teams Now This is a fairly non controversial thing. I mean, this is not new right? We uh, we have conway's law I'm sure we're all sick to death appearing about conway's law But it it's this insight that milk conway had in the 1970s that says that software is a mirror image of the communication patterns Of the organization that builds it right? So if your organization is dysfunctional that'll be reflected in the software necessarily That that organization builds put another way crap in crap out if want to fix the software you fix the dysfunctional organization It's not a new insight at all, but it does You know provide a path forward it does prescribe something that we can use to sort of improve our systems our code we can make small make Concise the the teams that work on that code the question of course is how do you do that right? You can't just take a large application and arbitrarily break it apart So we look for these large we look at these large existing applications And we look for seams along which to decompose them We turn to eric evans eric evans wrote a great book called domain driven design. How many of you have read that book? It's a an absolutely amazing tome keep it under the pillow read it to your kids. It's amazing and this book You know talks about a number of things one of which is called this called a bounded context A bounded context is a part of the domain model that stands unto itself internally consistent and reusable It's a part of the domain that Uh needs no other part of the system to do its work And if you can identify these bounded contexts, and I grant you it's a bit of an art form at some point But if you can identify these bounded contexts, you have a natural candidate for this decomposition You can decompose the application along the seams of this context and that forms a natural place to do what we're trying to do This is uh extractions decomposition We have a natural candidate for a small singly focused independently deployable reusable bounded context I said independently deployable that's important because we don't want to have to be Gated by other parts of the organization whenever we want to make a change to our code base Right if I have to wait for other people to finish their code before I can deploy mine, then I may as well not decompose at all There's no point in that so it has to be independently deployable and when we talk about independently deployable necessarily we're implying Distribution really especially in the jvm. There's there's some technologies that purport to give you sort of isolation and individual Load ability and that kind of thing on the jvm, but they really don't work in practice So really we're talking about separate processes talking to each other over the network And that distribution invites complexity. So today we're going to talk about ways to approach that complexity. There's uh Patterns and primitives that we need to be aware of in order to make that journey to production fun and in order to understand that We have to understand that we're building a distributed system And when you build the distributed system you run headlong into a number of pains You run and headlong into a number of pains that you need to address before you can go any further The first big pain is how quickly can you stand up a production worthy service? How quickly from zero to 60 or uh, what is equivalent 120 kilometers? I guess uh, how quickly from from zero to whatever your speed limit is and this in germany that metaphor doesn't work at all Because the autobahn has no speed limit. So uh, how quickly can you from whatever your from zero to whatever your speed limit is Stand up a single production worthy service. Suppose you had to build a service that Simply emitted the message hello world What all would you have to do to be able to deploy that into a production environment? Security observability monitoring load balancing heartbeat detection infrastructure arachnistak servers virtual machines containers all of that Everything you have to do that. I am sure nobody relish is doing I'm sure that with the rarest of exceptions that it know that Nowhere in your mission statement in the placard in the lobby of your headquarters does it say we're here to solve ssl Right Nobody says that they said we're here to solve whatever our business vertical is We that's what we care about and yet we need to confront these other sort of realities of building something for production The other once we've gotten past all that once we've gotten past those complexities Now we're confronted with the the complexities of building a distributed system We now face a proliferation of different services talking to each other and we face the realities of distribution Right and the possible fallacies of distribution That we have to be aware of that we have to make sure we don't run afoul of so when we do that We need to be able to you know handle things like outages and fault tolerance and so on so today We're going to talk about Building cloud native software the cloud native application these days is as I at least as I define it something that is agile Something that you can iterate quickly. It is something that is observable Let us just say it's fault tolerant and you know resistant to topology changes and outages It's elastic. It takes advantage of the elastic cloudy nature Of modern platforms today and of course it is observable both at the individual service level and the distributed system level The systemic level the the whole system level, right? So today we're going to talk about a number of different technologies to support all that Those are my slides. I hope you like them. I worked hard on those. Would you think yes? No, maybe the best slides you've seen this hour Good good. Okay, wrong one Opening this up All right, so we're going to start here at start.spring.io This is my second favorite place on the internet my first favorite place on the internet Of course is production. I love production and you should love production too You should go as early and often as possible bring the kids bring the family the weather is amazing It's the happiest place on earth, but if you haven't gone to production you can begin your journey here at start That's spring that I owe If you want for inspiration in the early morning before a cup of tea or coffee start that spring that I owe If your children are restless and can't sleep start that spring that I owe And if you suffer from indigestion after a long night of alcohol abuse and web sphere and php start that spring That I owe So we're going to build a new piece of software today a new service something with which to have an example something with which to iterate So I'm going to build something called the reservation service and we're going to build a service that has a reactive web application interactive web application it's going to support reactive principles here and we'll I suppose we could spend a whole talk on that but suffice it to say reactive programming describes a computational paradigm that allows us to model Asynchronous i o right so we get the right code that is aware of the fact that eventually somewhere in the stack We're going to delegate the input and output of i o to the operating system instead of Blocking in a thread and maintaining or monopolizing that thread Inefficient right so we use we're going to use a number of different technologies here We're going to use the reactive web support. We need some sort of persistence technology I could have chosen reactive Cassandra reactive redis reactive couch base for example, uh, but I chose MongoDB I chose reactive MongoDB because when you want to lose your data And you want to lose it reactively There is nothing better than reactive MongoDB Okay, I'm going to use actuator for observability and operational concerns I'm going to use the config client for centralized configuration. I'll use Eureka for service registration discovery I'll use zippin for distributed tracing And I'll use lumbak which is a compile time annotation processor that'll make the TDM of java just that much more bearable Okay, my friend. So now we have a number of different selections here I think I'm happy with these selections But that said if I were so inclined I could click on switch to the full version Where I'll be given a variable ocean of checkboxes things that I could where I so inclined add to my build to my application But for now for for this demo for for today It suffices to leave things as they are that said I encourage you to prove this list at your own leisure later on There's a number of great choices here. All right, so I'm going to hit generate and that'll give us a new project That we're going to open up in our id and I've downloaded this into my downloads directory Maybe wi-fi permitting there we are and I'm going to open this up in my id I'm going to use intelligent. How many of you using intelligent? I'm just curious good stuff hot sauce. What about eclipse? Right on awesome. I love eclipse. What about net beans? Well, it's awesome as well. I love it at beans. What about emacs? Are you here, sir? Where's the emacs guy? It doesn't seem to matter which there he is That's every single city that you're not him every single city country and continent. I go to it's the same guy Same one one human being one object identity. I say who uses emacs. He says I do and then he leaves Presumably to troll again at the next location Are you related? Maybe it's the same human So anyway, we have this uh, we have this new build There's this new project and I'm going to go ahead and comment out some of the builds bits that I don't need just yet So let me open up this maven build and I'm going to comment this out. We'll say a spring boot starter We want all that we don't want the config and the Eureka and the zippin will comment that out for now and what I'm going to do is I'm going to build a new application That manages data. It's going to manage data in spring in mongo db And it's going to be a data It's going to be an object that I'm going to describe using this It's going to be a record that I'm going to describe using this type called a reservation And I'm going to use spring data's mapping abilities orm's facilities to turn this into a document All right, and I'm going to say private string id and I'll use a I'll have a field here private string reservation name And I'll say at id and there we are. There's my basic entity. That's the essence of what I'm trying to express But of course, this is java. So it's not nearly enough I need getters setters to string equals all that kind of nonsense So I'm going to say no orcs constructor all orcs constructor and add data These are compile time annotations that at compile time will result in getters and setters and all these sorts of things being added to the type. It's thanks to that lumbock project, right? So reservation equals new reservation. You can see it has a constructor I can say reservation dot Reservation dot set id get id all that kind of stuff, right? So makes it easier for me to get work done now What I want to do is I want to save data into the database So I'm going to create a repository an object that's meant to persist records into the database And here I'm going to use the reactive mongo repository. This is an interface that prescribes basic functionality. It provides basic functionality That you know supports common use cases like creation reading updating deleting finding paging sorting all these sorts of things that I want to be able to work with You know this basic types now you see here that it supports monos and fluxes. These two types are publishers These are reactive streams publishers that will emit items of data and I can subscribe to the emission of those datas Of those records. I don't need to wait there sit there and block waiting for the next bite or record or whatever Right, this is a way of modeling code that will Provide data or produce data that I can work with later on when it's available But I don't have to sit and block in the meantime Right, this is what I meant by a computational metaphor for asynchronous code. They're both publishers. They just have different semantics Now I want to be able to use this repository in spring to write some data into the database I'm going to create an object that That is a callback here. It's a callback interface and it's a it's a bean. It's just a regular spring class It's got annotated with that component and when spring sees this application runner It's going to call this void one method giving me a chance to uh to write some data to the database All right, so I'm going to go ahead and add to this to the constructor I'll inject it in the constructor and here I'm going to write some data to the database. We use some names My name is uh, josh. It's so lovely to meet you. Uh, what about you buddy? What is your name? What is it? How do you spell that my friend? II Like that very good. Nice to meet you buddy. Thank you. Uh, what about you miss? What is your name? Miss How do you spell that my friend? r w Okay r w ee j Oh a like that very good. Nice to meet you. I'm sorry. I butchered that. I didn't mean to uh, uh What about you buddy? What's your name? How do you spell that my friend? Like like so yeah, like so very good. Nice to meet you. Thank you so much That's four. We need eight eight is nice because I can divide it by two and then two again And it's still two makes it easier for me to sleep at night. So let's see. What about you buddy? What's your name? How do you spell that? tya Whoops like that very cool. Nice to meet you. Uh, what about what about you miss the related to my emacs guy What is d e n i? Yes, like so Very good. Nice to meet you. Uh, what about you buddy? What's your name? Yeah, sure How do you spell that? Nda like that What is it? Oh, okay, so to end Hey, oh very good. I'm sorry about that. I didn't mean to screw that up very nice to meet you Who wants to know my last victim? I'm sorry. I mean, I mean volunteer who wants to be my last volunteer? Uh What about you buddy? How do you spell that my friend? Like that very cool nice to meet you So there we are we have a publisher full of names and I want to take each one of those names And I want to write it to the database. I'm going to turn it into a new reservation I'm going to say for each name Let's turn it into a reservation Object here of a type that I'm going to persist in the database like so and then for each one of those I want to take it and I want to turn it into a record that's been saved into the database So if you look at what I'm doing, I'm staging this data together here, right? Reservations there we are and I'm going to persist it now. I'm going to say reservation dot map Reservation, this is a reservation object now. I'm going to take each one of those And save it into the database. I'll say this dot reservation repository dot save passing in The reservation itself right now this would seem to work. It looks like it's going to do the right thing But what do you think this is going to result in it's going to give me a publisher full of publishers, right? Because the save output of this is a publisher in of itself So I'm going to actually unpack each intermediate publisher using flat map, right? And the result is now I can type this to a reservation of a publisher of reservations And then I want to save each one. I've already done that now. What if I run this code? What do you think is going to happen? Exactly nothing right This is this is lazy quite like myself. It has to be executed. You have to trigger its execution And so you can do that by saying map dot subscribe That's one way to do it. That's the way you're supposed to do it, right? You're supposed to say this to the publisher I'm interested in subscribing only then will it start activating. So this is certainly one option Another option is to use a block you can block But don't do that I showed this to my To my to my partner I said sweetheart Darling love of my life What do you think of this code? And she looked at me like she had made a terrible terrible mistake In choosing me She knew that this is not how you write this code. She is much better at this than I am She said no no no you why would you take this nice reactive api? And then block You've lost the benefits all all together. So don't do that instead compose or subscribe So this is one option. I want to I want to go ahead and run that code But I can subscribe but I want to do some other stuff first How many of you know the expression a broken clock strikes true twice a day? It means by virtue of the fact that the hands on the clock are fixed And they're not moving that it is correct at least twice a day, right? It's correct in the morning and correct in the evening Uh this expression reminds me of mongo db You see Not often, but sometimes mongo db will persist your data most of the time it will lose it reliably guaranteed But sometimes bugs creep in and it will sometimes persist it I can't fix that and I know the team works hard. I don't mean to pick on them They want to lose it a hundred percent of the time and they try very hard But sometimes data gets persisted. So I want to delete all the data in the database Like that And then subscribe which is a little weird And then I want to say uh this dot reservation repository dot find all And I'll subscribe to that as well, right? So this is these are four different lines four different sets of things or three different sets of things This works I suppose but one thing to understand is that this is not necessarily going to complete before this does And this code word here won't it won't complete necessarily before this does there's these things are executing concurrently, right So I need to use the api I need to compose I say then many and it's expecting another publisher another types of publisher And that's what I'm going to do. I'm going to give it a publisher by you know removing these intermediate variables that while educational Only complicate our code here. So there we go. There's our new publisher. I'll pass that in here And then I will compose again. I'll say using this repository There we are. Okay, so there's the the updated code I'm now using this very very sort of succinct api to stage Operations each of which returns a publisher and I can compose them You know in a chain like this right each line has its own chain now when I run this code Let's see what we get. Let's see what happens when this application starts up It's going to call the run method. I'll get some data in the database And uh We'll see what happens. All right Did I run MongoDB? Yeah, I've got one longer to be so that didn't uh Oh, we didn't print anything out So we need to confirm that everything is working as we expected by uh by running it. Okay Okay, here we are. All right. Very good. Look at that. There we are. We happy few it worked Of course it worked. It was a demo What were you expecting instead? What I wanted to talk to you about was this this is the ascii artwork in spring boot This ascii artwork took a long time to get right But you see we on the spring team have many people who are doctors phd's People in their previous lives worked in nuclear physics Star stuff the very celestial bodies in the heavens above us for their daily bread and butter So it makes me very happy to imagine that someday somewhere somehow there was a github issue that said darn it We need good ascii artwork and I think you'll agree. They did a great job So it's for this reason that I want to take a brief digression just an ever so brief digression To talk about what I consider to be a glaring and serious deficiency in intelligent jet range product for a while I'm a fan. I consider this to be particularly short-sighted. You see that chuck box What the heck it says hide banner That's a dumb feature Once clicked it suppresses the output of the ascii artwork Who does this so I can sense your outrage and I too was also outraged I did what all of us any of us would have done in that same position I went on the internet and I cried and I sent a message out onto the twitters and my friend yann sabron yann sabron is a Here's here. He is right here. Oh Where's that? Come on this this he's a he's a he's a Come on Come on There you go. You can see he is a software developer by passion at intelligent idea jet brains, right? And he sent me this message of hope which I share here with you today right now Don't worry my friends. Hope springs eternal. Anyway, we have now great ascii artwork. We have data in the database We need a rest api, right? So here. I'm going to build a functional reactive rest endpoint I'll say at bean and I'll use this You know functional reactive style here. So I'll say server response Is routes Return router functions Dot route request predicates dot get and I'm going to say whenever somebody calls the reservation It should be get on the local host and goes to reservations. It'll return a new server response Sorry a new h a new handler function that is typed to server response Okay, and there I'm going to return server response that okay And I'm going to return the data that comes from using this repository to look up the data I'm going to inject that there and then return find all With a payload of type reservation. Okay now, uh, let's see. Oh, I need to do body instead. So There we are. There's my my uh Anonymous little web controller rest controller. I can use java isms to make this a little bit Cleaner I can use static imports for example. There we go. I can use lambdas that cleans up nicely there Turn that into a request and there we go There's my one liner for a request for reservations endpoint that will functionally handle the data when somebody calls Okay, so now I'm going to go ahead and restart the application and we have now a web application arrest service at local host 8080 Ford slash reservations there. Voila. Okay, very good. Now. Are we ready to go to production yet? No, of course not not just yet We have concerns like security and observability in these non functional requirements that gate our ability to move to production These are the things that most organizations have and they need to address but they don't really think about but we all have them Most organizations I've talked to not yours, of course Not yours definitely not yours But most organizations that I've talked to have this dreaded wiki page And again, I know it couldn't be it couldn't be yours Most organizations have this dreaded wiki page with 500 easy steps to production It is the list of things that you need to do before you can deliver line one of business differentiating functionality And in this case one of those things is observability. We need to support remediation We the way we do that is by supporting visibility into what the application is doing So here I have this library called actuator an actuator Well, so well, it'll expose Endpoints that surface information about the application itself And so these are operational endpoints that are designed to support Observability and to promote operationalizing the application endpoints that are standardized across all of our services This was inspired by the google borg paper Right, they talked about how their borg monitoring requires that all services No matter what the nature of the service stand up the standardized htp endpoints So I've got the application now running I go to localhost 80 80 for size reservations and now I go to actuator And I can see a number of different endpoints here beans The health the health check right the health check shows me the file system and the MongoDB connection It shows me, um, you know the environment the properties and the environment for example that are Available to this jvm process the info endpoint the loggers that have been configured I can download a thread dump or heat dump I can see all the metrics these metrics are keys and values you can Emit custom keys and values and these can be synchronized with the time time series databases like influx db or prometheus or whatever to support operationalizing your application observability right you need to To see trends over time So all these things are there and that makes it so that we can now kind of get into a feeling for what the application is doing If you're using a platform like cloud foundry It'll show all of these things in an aggregate single pane of glass that gives you A single picture to look at to understand what the state of your system is now We've got that and we could easily add security are we ready to go to production? Sure, why not right so let's go ahead and build an application Um, uh, we've got an application Let's go ahead and talk about what happens if we have more of these things right if we proliferate more services We're going to run into limitations around some of the things that we need to support One thing that becomes tedious in a distributed system is configuration thus far. I've showed you how to configure things using this property file That's fine if I want to have to recompile my jar, but I want to be able to centralize my configuration I want to be able to support symmetric encryption and decryption of Sensitive values in a property file I want to be able to support live reconfiguration of things in the property files And I also want to be able to support auditing and journaling I want to see who changed what and when if necessary to roll that configuration back So for these reasons what I'm going to do instead is I'm going I'm going to create a director I'm going to clone a git repository containing git You know property files in this git repository assuming the page loads Uh, and we're going to call this to my local machine Here we are git clone desktop config Oh, it's already there Good. So I've got one here. It's a prop. It's a bunch of property files I'm going to point that I'm going to create a new config server to manage access to immediate access to that directory full of configuration and uh, we'll say This is going to be a config service config server We'll hit generate that's going to generate a new project In the download directory. So I'll open that up here Come on. All right, moving on. Okay. So now in order for this to work We need to do a little bit of coding here. I'm going to say at enable config server All right, that was hard and I need to specify what port on which port I want this to run And I need to tell it where to find the directory full of configuration, which as we know lives Uh on the desktop Home desktop config. All right. So there's my my configuration to make this config server It itself is going to act as an intermediary between other microservices and their configuration files each of which is named Uh for the uh the microservice. So you see I've got desktop config, uh, you know reservation hyphen service that properties, for example I'm going to name that microservice that we just built the reservation hyphen service and teach it to draw its configuration Not from this property file that's built into the code base But from this microservice that it's going to connect to using the spring cloud starter config Client all right. So this client is going to give us the ability to centralize our configuration. Voila. Okay There's our reservation service application. Now. Let's suppose I take advantage of this microservice that we've just stood up local host uh 8888 Reservation service default you can see there's a property file There's a property message from from where I was about 12 hours ago Right, I was I wasn't I wasn't here 12 hours ago. It was in Dubai. And so this message While it's interesting it's completely wrong. It's the wrong message. We're not there at all So I'm going to go ahead and connect my microservice to the set of configuration But we'll update it and uh, we'll see that we have to change that message. Let's get a new endpoint here called message Okay message server response dot okay dot body flux dot just and I'm going to inject that message here from the config server Here we are I'll use the environment there. I'll say e dot get property message And I'll say string dot class. All right Oops one layer Okay, there we are. Is that right? Thank you There we are. So there was my new endpoint that I've just added to the application It's called message now. Let's see what happens when I call that endpoint. Oops. I need a compiler to do the thing It's supposed to do Okay, good localhost 8000 message remember the config server here says server port is equal to 8000. So it's now at 8000 In message. There's there's a value. It's the wrong. It's the wrong value. We know that I know that even I know that right So I'm going to go to the desktop here config Emacs reservation serves that properties. Yeah, it's me It's me. Okay. I'm going to say hello Then got our extra exclamation mark. So as to reinforce my credentials authority and authenticity and read it Okay, get commit minus a minus m yolo Now I'm going to send an empty htb post to another actuator you know operational endpoint In this service called refresh and the empty htb post is going to be of content type application Jason ready steady go refresh So as soon as I did that it instantly updated the configuration live this supports things like feature flags I can now you know do canary deploys I can do all sorts of nice things with this another thing that I care about in a distributed system Is making it easy for one service to find and work with another and to support this I'm going to use a service registry We could use dns, but service registration discovery gives us the ability to programmatically Interrogate the state of the system to ask is that service there? Not just where does that service live and this is an important distinction Especially in a cloud native system where things are going to come and go based on demand and capacity So while there's a lot of options here that we could use in the spring ecosystem We could use a patchy zookeeper or hashy corp console or a scd or cloud finder itself I mean lots of different options here I'm going to use uika for a couple reasons first of all it's been used by netflix It was created by netflix and it's been used by them for years and years at great scale So we know it's going to do a good job or at least an okay job and also it's an easy thing to stand up and demo So that's great for people like me who are particularly lazy and pressed for time So I'm going to go ahead and now bring in the discovery client support This is the common uniform interface that we need to be able to talk to that service registry Right, so there it is there. I'm going to bring in spring cloud startup, you know, netflix uika client And uh, we'll just start this application up and now what I'm going to do is I'm going to build a service that talks to That service I'm going to build another client that talks to that service called the reservation hyphen client Config client uika discovery gateway Historic circuit breaker. We're going to bring in a reactive web reactive. Uh, we're going to use um redis We use a Uh security spring security Uh, I think that's enough uika config client. Do I have that? Yeah zipkin distributed tracing good. We've got a number of things here good So i'm going to open this up here And this is going to be an edge service. It's going to be a thing that other services will call It'll be the first port of call. It'll be it'll be clients that call it, you know iPhones playstations xboxes etc This will be the first part of call for requests coming in from the outside world that need to be adapted to the Downstream services or that rather need to adapt requests to the downstream services uh to homogenize them So this is going to be our our first port of call for those kinds of uh outside requests It will of course be exposed via dns, but it'll use uh that service registry to resolve all other services within the cluster within the system So we're going to say reservation hyphen client And i'm going to comment out some of the bits. I don't need just yet like the security support here So spring cloud spring boot starter security. We don't need that just yet and we're going to start up the code and Think about these common use cases right imagine you have an html 5 client html 5 clients are very powerful But they live in a sandbox that precludes them from making cross origin requests So we're going to use a gateway project spring cloud gateway It's an api gateway to proxy requests from the outside to the downstream service. Let's do that here We'll create a simple route locator Okay, route locator Routes or gateway. We can call it even right and uh, we're going to inject the builder dsl here Route locator builder. I'm going to say rlb dot routes dot build and then the route that we're going to build the the predicate for the route is This I'm going to say when a request comes in At the local host node on this node the service is going to run important 99 99 when it comes to the path called You know proxy for example, then I want to Send it to this url right html spring spring That io colon 80 forward slash guides. I'm going to proxy the data just to demonstrate what we can do here Right, so I'm using the builder dsl here to build a simple gateway or simple proxy example. Okay So this is I could be more uh, I could do all sorts of other interesting things here. I could say and uh, you know and host equals Dot food calm for example, right? I could do all sorts of interesting things at the gateway predicate layer here But uh for our purposes it suffices to leave it at that so local host 99 99 forward slash proxy Now this is going to call the spring that io website and download the the output and render that there in the client So this is great. This is a third party website. It's not the one we want but it does demonstrate what is Cable here right now Let's instead delegate or forward the request to a load balanced call To our service the service we just stood up that is now visible in the service registry, right? I could I set the path there before I set the path the context path like this before But you can also do that in a filter and the filter is really where you get a lot of the power in the gateway project You can do rate limiting. You can add request headers. You can change request headers You can use a circuit breaker. You can do redirects. You can do, uh, you know, we can remove things You can retry calls. You can save sessions do secure things like that Or in this case you can just set the path Right like so i'm going to set the path on the target call Uh, and then we're going to see what happens. So now remember I started up that service registry That service registry is on port 87 87 61 you can see that right now there's this reservation service. It's in the registry That's the service. It's a visible. It's now. Oh, yeah Very good that service is now visible for clients that are making calls And we're going to use that client, you know, I'm going to use that service registry to find The service and then use it from the reservation client. And that's what I've done here I've got this url that is load balance. This isn't dns. This is actually the service id in the registry itself So we're going to make that call now if I go to proxy you can see that when I go to proxy now It goes directly to the services instances in the registry picks one using a client side load balancer by default It's lru or least recently used but you can do data center aware Load balancing or multi tenancy or oh off aware token, you know session affinity or whatever you want lots of good strategies there Now if you have a different client that is um If you have a if you have a client that needs a particular view of the data As opposed to this cross-cutting sort of generic proxy that applies to all services and all endpoints You can create a semantic endpoint here, right? You can say i'm going to create a uh An endpoint that has a particular view that is adapted for the um I've adapted it uh to the requirements of a client Maybe I want to have a just an endpoint that shows only the the names not the whole jason structure Not the attributes not the id just the names, right? So i'm going to create a new endpoint here This is an api adapter. It's not it's not an api gateway. It's a slightly different thing Uh, but they both serve the goal of supporting a client. Okay, so now when somebody goes to reservations Names they're going to get this handler function And this handler function is going to be you know, I'm going to create another endpoint here server response Dot okay dot body and I'm going to have to make an htb call aren't I I'm going to have to make an htb call Just like I did uh just like you would to be able to do any kind of htb call So i'm going to use the reactive web client right this web client is an htb client that you can use That is very efficient when it makes calls to other services now I'm going to create an instances of this client and the reason I'm going to do that is because uh, I need to configure a filter And this filter is going to be aware of our load balancer of the uh of the client side load balancer and of the uh You know the the load balancer strategy that we've got there So i'm going to inject that here in creating this bean and creating this object I'm going to bend that instance there. Okay, so now I've injected this into the the handler the you know the route route code there and uh, I'm going to call That endpoint I'm going to call dot git ui will be htp colon forward slash forward slash reservation hyphen service again. This isn't dns I'm making an htb call to the downstream service I'm going to take the body and I'm going to turn it into a publisher of type reservation But I don't have this type on the class path do I So I'm going to do something terrible here friends something that you should never ever do not even when you're all by yourself Alone at home and nobody's looking. I'm going to copy and paste some code so want to go here copy and paste Paste oh, that's awful the worst feeling Because you know it's going to come back and haunt you later on so don't even do it I'm doing it for a demo and I feel bad about it All right, so we have a publisher of type reservation. I want to map each reservation To its reservation name and store the whole thing into a publisher of You know a publisher of strings, you know the names So there we are that's the response that i'm going to send In this in this publisher and it'll be of type string and that's fine Now this code will actually work in the 80 percent case If there are one or more instances of the service in the registry It's going to do the right thing But what if I have zero instances of that service in the registry? How can I load balance across zero instances? That's a bit like dividing by zero, isn't it? What happens when you divide by zero? Hey Siri What is zero divided by zero? Imagine that you have zero cookies and you split them evenly among zero friends How many cookies does each person get see it doesn't make sense And cookie monster is sad that there are no cookies and you are sad that you have no friends It's true. Don't make cookie monster sad high performing organizations understand that eventually statistically as you scale out Something is going to fail. It's not a matter of if it's a matter of when and we need to be prepared for that So while this is working, right? I can go to reservation names for example, and I get all the names back, you know Kind of mush together there, but there's all the names that's working It doesn't prepare for the eventuality that something is going to go wrong If you have a cloud platform like cloud foundry It'll make sure that if a service falls down you want to come back online It'll get restarted automatically, but in the meantime, we need to build our code accordingly We need to prepare for something like this to happen using for example a circuit breaker So I'm going to build a circuit breaker using hystrix hystrix is a library for netflix. I'm going to adapt this publisher I'm going to build it I'm going to provide a fallback behavior. I'll say whenever something goes wrong Just call this publisher that returns a string called eek, right? And we'll give it a fallback name a command name So names there we are and I'm going to use that circuit breaker publisher instead of the actual publisher And that way I'll have a little bit of indirection that'll that'll you know Give me a useful response high-performing websites do this kind of thing all the time They'll say oh well you went to the search engine service, but it's not available right now Here are some machine learning recommendations from across the web for example, right? So here we are This is fine. Good. Good. Good. Good. Now I go down to the other service kill that And you can see I get eek instead of a big fat 500 error or a stack trace or something like that. Okay now thus far my friends we have Uh, we've looked at a number of different things here. Uh, we should also be taking care of observability I looked at observability in the very beginning I talked about it in terms of the actuator as a way to observe individual instances But that ignores the larger system the whole system if I am walking here in beautiful bangular Is that equivalent? Is that functionally equivalent to uh looking at the google map? for Bangalore I think not of course not right One is not the same as the other one is far more vivid There's so much more traffic and so much more amazing food and wonderful people here in Bangalore That I could hope to appreciate by looking at the google map The map is not the terrain and the same is true for your production system Your architecture diagram is not the same as your production system And if you want to appreciate the whole system you need to observe that system One way to do that is to use distributed tracing So thus far on my in the class path of my applications I've got this thing called zipkin spring cloud starter zipkin. This is a distributed tracing tool That's already on the class path and it's already publishing Trace information about our application to local host 9411 and it's doing so using Kafka I've got Kafka running the background there. Uh, and so here you can see it says I've got two services reservation client reservation service If I click on this I can see that you know, I've got this endpoint here to uh The reservations endpoint I can see reservation names I can hit find trace and it shows me all these requests that have happened two minutes ago Whatever in a minute ago, I click on that and I get the details. It says oh reservation client reservation names Uh, a few milliseconds later eight milliseconds later. It went to the reservation service I click on that I get the request log the in and out etc Right, this gives me visibility into what the system as a whole is doing I can understand the the system makes it much easier to debug Right because remember when you move to microservices Things get distributed, right? So it's good to have a single pane of glass to understand the whole system. All right my friends well I uh I feel like we're out of time. I feel like we've kind come to a uh a useful stopping point I wish we had more time if we had more time We talk about federated security and single sign-in using spring cloud security If we if we had more time we talk about leadership election into motion using spring integration and spring cloud cluster If we had more time we talk about eventual consistency in the saga pattern using spring uh cloud stream And spring cloud data flow if we had more time we talk about testing with consumer driven contracts and consumer driven contract testing If we had more time we talk about any number of things Beyond what we've talked about today, but i'm afraid my friends that we're just plumb out of time I hope you liked some of what we talked about here today. We covered just a few things We looked at how to build the rest apis in a reactive way We looked at reactive persistencies in mongo db and spring data and you know spring uh spring support for reactive Programming we looked at how to use centralized configuration We looked at service registration discovery client side load bouncing api gateways Uh, we talked about a number of opportunities there including rate limiting and proxing We looked at how to build semantic sort of api adapters. We used the reactive web client We did client side load bouncing there as well We looked at how to integrate reliability patterns like a circuit breaker And if we had more time we would have certainly talked about messaging as a way of doing writes Where we just did reads with the uh the web client and uh, we also looked at observability ever so briefly Using a zipkin a distributed tracing platform from twitter that is neatly integrated into spring cloud and to spring boot We have only begun the scratch only begun to scratch the surface though I hope you liked some of it. Did any of you learn about something you liked here? Or see something that you could use at some point. I'm glad to hear that very glad to hear that of course, uh, but You know I obviously am a big fan Obviously i've got the t-shirt and the spring underwear. Obviously i'm a fan, right? But you don't have to take my word for it. I love this stuff But there's lots of all lots of small organizations out there that are doing amazing things as well There's uh, netflix. They're using spring boot and spring cloud And if you think about amazon.com amazon.com is the alibaba of the far far far far extreme west Okay, now Rakuten.com in japan is the alibaba of the far far extreme east They're an e-commerce engine. They're using spring boot and spring cloud and cloud foundry Alibaba itself is using spring boot and spring and spring cloud For everything. I mean aliyoon alibaba alibaba how Taobao Alipay aliexpress all this is all spring and spring boot and spring cloud Baidu search engine the third largest in the world. They're using spring boot and spring cloud and cloud foundry as well So these organizations, yahoo japan is using spring boot and spring cloud and cloud foundry these organizations And many of those besides are building amazing software and they have to get to production faster They have the money the motivation and the means to solve these problems themselves But they choose instead to build on the pivotal stack because it allows because it allows them as a as an organization To deliver better software faster to the customer which at the end of the day is all that matters So thank you so much my friends. I appreciate it. If you have any questions don't hesitate to reach me outside I'll talk. Thank you