What the heck is Spring Cloud ? An Introduction to building Microservices using Java + Spring Boot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] thank you [Music] so let me start presenting fine so what are you planning to do right now so my main goal is I want to make everyone familiar with the microservices like microservices is fairly a broad topic and there are a lot of design patterns a lot of tools a lot of thoughts a lot of uh you know Library involved in that but what we will be doing right now um we will start it from absolute scrunch let me tweet everyone is like you know is like you know they are pretty new to the microservices and we will start it from as I said from absolute scratch I do not care if you have already worked with microservices or if you don't right I know there are number of peoples over here who knows microservices I know there are also people who are completely freshers I know also there are people who have worked for years but they are working in monolithic architecture and they are new to microservices as well so what we are going to plan right now for the next three days let's just get started with microservices let's just start writing couple of microservices let's try to interact with each other let's just try to get some data and let's just try to have our thoughts clear what the services are and what the heck this microservice is which is a buzzword right now so guys let me tell you that one thing let me let let me make it very clear to all of you if you know Java if you know spring you got microservices right it's just some design patterns some new tools some new thoughts that will be start learning from right now but yeah the coding will not be new to you right so it's just like you know like we are following in VC design pattern we might follow some DDD design patterns some Saga design pattern maybe we we have some kind of patterns that you know we'll be learning right over here and the spring cloud is basically make it more simple to develop microservices so it's going to be a very simple and straightforward Journey for us so let's just get started from very scratch and let me just give you a requirement right now I'll just start giving you a requirement imagine you know like you know I run an organization called selenium Express and let's say I have a requirement right now that I want to create a employee and a customer management system uh you know that let's say I have few people who purchase my services like you know whom we give support to their projects like uh maybe some of the clients can talk with us they say okay this is your issues or this is your stories that you need to implement for us and we do give services to them so they are my customers and let's say we have few people here who work on work for different projects and maybe there are a few people who help me on my video production let's say they are my employees okay and let's say you guys I can call you guys as students or maybe you guys also paid me money so you guys are also my customers so let's say I want to create an application which is going to help me to manage my employees and customers uh right sure okay so I have given uh this particular requirement to you guys and I want you to build me this application base has some ad feature like I can add employees I can add customers I have some delete feature like I can remove my employees I can remove my customers and I have some update feature as well like you know if I want I can update or modify the employees I know like you know whatever experience level that you have you all can develop this application if you have a little bit of understanding with Java and spring and the j2ee isn't it so now let's just say you know okay we'll ask what's the big deal I need to develop this employee and a customer management system so I'll just try to find out the main components right here okay so what are the main things you need okay you have a organization where you have employees so okay I'll just create a separate module for employees and I'll have a separate module for customers where I will be managing my customers I will have a separate module for courses where you'll be selling your courses somebody will purchase your courses you will have new students who will be enrolling there will be students who might need font or you have different you know thoughts process involved with that and also all your employees will have addresses the customer will have a billing address shipping address so I'll treat it as a separate component or a separate module okay let's just say that say like that now you know you have started creating some of the endpoints using what you know your UI application or a third-party application can start getting all the employees like let's say start a slash employees who's gonna get me all the employees back just like that you know slash employee slash ID will get me a specific employee whenever I will hit this endpoint and it's obviously a get request just like that it will help me to create a post uh endpoint which is going to help me to add an employee if you are familiar with restful web services and you know that you know slash employees you will be passing in the employee details as a Json as a as a buddy and you know with the Json buddy an employee will be created and will be posted to the server and if it is it will create a new employee on my server this is going to be a post request just like that for all the other modules that I have you will be creating the endpoints the similar way you will be creating endpoints for uh customers which is going to get you all the customers back you're going to be creating endpoint for customers who's gonna get you a specific customer back you're gonna be also creating endpoints to create a new customer just like there to create a new course you will be using this endpoint to get a specific code course you will be using this endpoint and to get all the courses which are available in our database you'll be creating this endpoint right just like that similar for the address as well okay so let's say you have different modules right now and imagine you have developed all these endpoints you have created employee controller customer controller course controller address controller created all these endpoints which are specific to those controllers and you just wrapped it off under this ZIP file and you put it on a server let's say on a tomcat server or a JT server or maybe a under tow server or JB server and you jibbed this thing and you put it over here on the server and that's it your things are done right so basically you'll have your database as well which is going to be connected and all your employee stable customer table course table address table will be over here on the database pretty straightforward this is what we are trying and doing for the last uh you know for for our last course where we launched springboard and also you know if you are familiar with the monolith application um or that kind of architecture this is something that you are trying to do every day now here is a big word alert where I said monolithic what do you mean by that I'm going to come back to this but yeah monolithic means what I think you guessed it because we are wrapping all our components module under a single Jeep and we are deploying it into the server this is the traditional approach which is pretty much familiar in 2000 but right now the requirements are changing and you're going to be getting a lot of different types of requirement this is something that I'll be discussing right now but yeah this is something what we call a monolithic architecture like where you can see um this UI the customer module employee module course module address module the dial layer imagine this all are your business code or business layer this is your UI layer this is your business code customer employee course address where the business is happening and the dial layer is basically connecting to the database you are wrapping it off under a particular zip file you can treat this white line as the zip file and you are deploying into the server and this is what is a traditional monolithic architecture as you are you know wrapping everything into a single zip file and you are putting it inside the server okay pretty straightforward so now uh what are the problems and challenges that we that we basically face on monolithic and why the world is moving towards the microservices the first challenge number one okay imagine I have given you a requirement right now that hey in the course module right now I want to have a new feature implemented so Implement some new features and let's say you are there I have given you some of the box to fix let's say I told you I hey I have this new feature like you know I want to add this new feature to my course module let's say all of all my courses will have this new theme or some a new button or maybe I I will tell you hey there is a box somewhere in my course module just go and fix that defect or I'll say my ADD button is not working my update button is not working you imagine I have given you some kind of sample requirement so you are a Dave you know what um let's say this guy is you who is working for the course module you can see there are there are like you know there are three people working on the employee module there are three people who are working in the course module imagine this guy is you or this girl is you and let's say there are customer module and there are three people working in the customer module right and the way the things Works let's say somebody um they say these three people are developing new features or working on bugs or defects in the employee module so if they need to change something they will uh push the code to the git and the Jenkins will take the code from the git and creates the build out of it guys you know that git is a source control where we can basically put our code if you are new to git is something like SVN or clear case and you know you will be pushing your code to get and this guy will do nothing it will just run a build just like that just like you know you are doing a math and build in your application you are doing a map and install is creating War for you and that war you are deploying into the Tomcat server and running the thing same thing the Jenkins will do the same thing once you you want to push the core to the gate the Jenkins will take the code from the gate and will create a build for you and that will have your you know the chip or the war or whatever and that word you will be deploying into the server and the server will have a database and once your code will be you know compiled and we create the jar for it uh jar from it we'll be pushing it to the server and the server will run that particular jar file let's say we are deploying our code to our Tomcat server or JB server and our code will work over there in application is go live on that so right now you have right now three different uh teams right now working one example one is one team is working on employee module course module and another team is working on customer module now they all do continuous development they push their changes to the gate and right now the Gen can create the build and push it to the server and as I said in the last uh in the last slide that your client has given you some new features to implement right and he told you like okay do it on the course module and as a Dev what you did let's say this guy is you right now you have basically have made some changes on your code base in the course module and you push it to the gate and let's say the code goes to Jenkins and the Jenkins picks up the code creates a build and deploy it into the server and your application went live and you have tested your changes and you have seen okay my client want me to implement this feature on the course module my client wanted me to takes this bug in the course module right now I have done it I have tasted it it's working fine it's on the server is live right now let me go home and sleep and in the very next day you came back to office and you are just walking in the lobby or you just went to the cafeteria and there you see that there are like the some of the people from The Tasting team they are just continuously looking at you and laughing and you said hey what's wrong why you guys are not tasting right now even you know I yesterday I have put some changes to the server and you might need to check the new features that I have implemented and the tasting uh Team told you that hey you know what I know that you have pushed some changes and that basically broke the application now you said hey this is crazy I have done some changes in the course module I pushed it to the uh like you know git I have taken the new build I have deployed it on the server I have tasted my application and it was working like a charm I can able to see my new feature right there and I can see like whatever the bug I have fixed or whatever the defects that I have fixed it's all working good but the tasting team said hey you know what the new feature is working fine but something is broken the customer module right now the customers are not able to log into the application and you just got out of words like you know what to say over here you know I have done some changes here and how can you tell me that there is something wrong here in the customer module I have just add some new features in the course module but how can you tell me that the customers are not able to log in right now how these two things are related because I have not touched any code over here now that's the problem because as I have told you previously your entire application is getting dipped together and getting deployed together on the server so like you know there are two problems over here okay why the code is not working in the customer module why the customers are not able to log in that two things any changes on the code lead you to test the entire application you have changed something in the course module right now for that your testers right now need to run the entire regression test the entire test cases which has been written for employee module course module and the customer module together and find out whether there is some issues are there so any changes whoever the developers change any code maybe it's in the employee module maybe it's in the course module or in the customer module the tester will taste the entire application because any changes in one module can impact the other one just like the scenario that I have given and the second thing is that the developers may not have the knowledge of all the modules and that's making it harder to get started with any module and also fixing any issues now imagine this scenario as I said right now you have done some changes in the course module right now something has broken in the customer module now let's say you are new on the team and you have only got KT on the course module right now the client is bashing you and you know you are getting a lot of emails that hey what do you have done my customers are not able to log in just try to fix the code and you are completely new to this module because you are a developer right here who works for this but now there is some problem here now you are completely ignorant what's going on over here how the login is happening you have no idea on Spring Security you have no idea how the security things has been implemented you have no idea why someone is not able to log in and now if you're gonna study those things get KT and fix the issue by the time you'll be fired so basically the thing is that a developer who is working in one module he might not have idea of this module might not have idea on this module that's why if you are working on a monolithic application in your company it might be very hard to get started with the application you might need five months six months six months even if very less maybe 10 months year two years to get started and to get have a complete understanding of your application and it's very hard to have the complete idea of an application because even though you don't need to work on this you don't need to work on this you need to get ideas on this okay this is one more thing and the challenge is number two okay now basically you know what let's say the client has has given you an offer let's say every new users and customers will get 20 percent off in all the courses of selenium Express okay good thing I ran some ad in Facebook I ran some ad in YouTube I have announced it on YouTube I have I have done something and I said hey you know what 20 percent of the courses which used to be 20 000 right now available in let's say fifteen thousand or sixteen thousand now what will happen imagine this is your application and this is your business code this is your modules and this is your Dow layer this is your UI now as I am running some offer as I said 20 off for the new users now what will happen is lot of users will come and start uh signing up right they are trying to log into the application by signing up and creating a new user account on the website now there are lots of load coming into this module right now which is the customer module now you know what in your spring boot or any application that cannot basically handle lots and lots of load coming into this let's say this is your server a server will will have some capacity like the server can handle this many requests let's say your spring boot application can only handle 200 concurrent requests at a time but let's say there are thousands two thousand requests coming right to the server and the people are trying to log in and your server is right now going to perform slow you know what it's the Crosshair is going to keep on rolling and the people will not be able to you know browse the application properly because there are tons of requests coming into this particular module and your server cannot tolerate the load let's say you have taken a server you have you have said like okay I have a two course CPU running I have a 50 GB hard disk I have a 4GB Ram okay you have the extra bar of this capacity but right now the load which is coming that load is not been handled by the CPU core that you have let's say two core CPU is not able to handle all the load uh which is coming right so now what will happen now basically your website will be coming slow over here so right now what you can do as a solution you can take the same application which is running on server one okay you can put it over here this is your selenium Express website or the selenium Express uh you know customer and employee management application that you are building you can put it on the server one you can put it on the server too you can put it on the server 3 like this now same application same code you are putting in one server you're putting it in another server you are putting it in another server and you are basically having your DB connected to all the servers right now the same code is running in three different server right now our goal is whenever the request is coming some request I'll send to This Server some request I'll send to This Server some request I'll send to This Server because this customer module right now is having a lot of demand a lot of people are coming into the website right starting to create a new account and my website is not able to handle the load so basically I will have three different server and I will basically I will basically put you know my application into three different server instances and right now you know I will have a load of balancer implemented and this load balancer will do what whenever the request will come it will route the request into different server to handle and to balance the load right now the same code is running in three different server and this load balancer is basically routing the request to multiple servers in order to balance the road so that there will not be any button or load into different servers that we have now what's the problem here the things that result but the problem is here you can see we are having traffic here in the customer module only but right now just because the customer module is heavy we are ended up deploying the code into three different server because the customer module is not independently Deployable we cannot just we are only getting the load here we are only getting the load here and here but why to deploy the employee module a course module address module into a different different server this is unnecessary taking uh you know memory you know what whenever you purchase server it is heavy you even cannot imagine how much you ended up paying for the server right you are creating three different server you are trying to deploy your application because the customer module is only having the traffic maybe if I'll only deploy the customer module it might be needing a 2GB Ram but is you have your application zipped off together and you are deploying it to the server at once so you ended up purchasing a server which says 8GB Ram 8GB Ram 8GB Ram just because with the customer module you are also deploying all these other things because they are monolithic application and and has been zipped together and the same word you are deploying into every server where where the customer module and also the other code is also over there as well so the customer module is not independently Deployable and that's why you ended up spending much more resources whenever you are scaling up your application what I mean by scaling up because you are having more load so you are creating more server instances you are purchasing more server and deploying your application into different different server and routing the request to multiple servers which has the same application running I think this is making sense right so right now as I said the entire thing has been zipped together as a single package and you know that has been deployed to a server now here comes the micro services and the introduction to the micro services so look at this architecture right now so right now it's the same thing only this blue boxes I have just changed it into the single compartment now look at that you have the employees module you have the customer module you have the courses module and the address module right now now I will not tell them as modules rather I will tell them is you know Services small small Services right now your entire application I have divided into four different things like employee is a separate module customer is a separate module course is a separate module address is a separate module okay let's create a service for address let's create a separate application for course let's create a separate application for customers and let's create a separate application for employees so let all the four applic all the four you know things that you are seeing over here right now you can tweet it as four different applications if you know spring or springboard treat it as four different springboard applications you know what all these endpoints using this this application can talk to this this application can talk to this how because they have the endpoints and we can have rest calls like employee wants to get some data from the customer then it will invoke this and point and we'll get the customer data over here right so right now these are four different applications and they all have separate separate databases right and right now this is basically the microservices building small small Services right so right now you just concentrate on this word small small because our entire application we are splitting it off and developing small small application look at that one more time now this is one application and this application has been deployed into this particular server this blue line you can think like this thing has been zipped and has been deployed to this server and this server has this database you can think like this is your employee database like this this is your customer application all this endpoints has been zipped together we have created the one out of it and we are putting it inside this blue box which is the which is our server and this server has a different database this is our customer database in previously we used to have one single database for our entire application right now we are making sure every module we are separating we are creating a service we are creating only customer service we are TR we are we are telling it as a service because it is solving something it is doing some business need like a serving the customer details it is serving a particular customer details it is it is helping me to you know create a particular application is doing some work for me that's why I'm telling it as a small service call customer there is a small service call course which is going to help me to do uh you know query for courses finding a particular course and creating a new course and whenever I do all this operation the things will be done inside a separate database right this is one more thing and this is the thing as I said building out small small Services is called microservices Simple right now looking into this thing now you have your UI and your UI has been deployed into a separate server you have all these things employee courses address customers which has been basically deployed into different servers right now and your UI will connect to all these things and all these things will have its own databases like employee DB course DB address TV and like this all the things that we have all the services that we have they all will have separate databases right like this and now this UI can talk to the employee application which has been deployed into a different server you can create this Yellow Boxes as a server now this UI can talk to the employee server and it can talk to the customer customer server you can talk to the address server where my address application has been deployed and the core server where my course is basically deployed all right and all this thing can be talked to like the UI will be talking to this application through the rest call through the rest endpoints right the UI will say hey get me the employee data so it will call slash employees and that's going to get all the data of employees and all these applications and also can talk to each other through the endpoints like this all right so all these things right now also can talk to each other I got something on the chat can you say Okay reminder a camera off okay one second so make thank you very much let's have a pulse one second please foreign [Music] [Music] foreign [Music] foreign [Music] thank you [Music] [Music] [Music] foreign [Music] foreign [Music] [Music] [Music] foreign [Music] foreign [Music] [Music] thank you Sonic okay I have only one thing to tell and after this this presentation is over right we are almost done right now so our UI application is right now we'll talk to every uh small small services and all this thing all this communication well done under arrest right we'll have rest calls with the communication will happen through the rest calls and all these applications like the UI will talk to employee UI application can talk to the course application UI application can talk to the address application they all has been deployed into different server and the way the UI application which has been deployed into a different server will communicate with the employee application through the rest call unless the employee needs some course data the employee the course will need some address data the course will need some customer data they all can communicate using the rest API calls all right so right now this architecture that we used to have where all these team people used to push the code to git and the Jenkins is basically take the code from the gate and will be pushing it to the server by Jeeping all these modules together into a single chip and that particular monolithic architecture right now changed to this right now what we have we have our employee module the code goes to get Jenkins build it and it pushed it to the server and this server has a separate database called employee database just like that for the course module we maintain a separate GitHub repository previously what we used to do we used to have one single git repository so the more our application grows the more heavy the code base become but right now this has been changed to this so right now our employ our employee module will have a separate GitHub repository okay where we have a separate Jenkins server configure Jenkins will get the employee uh employee code if there is something has been pushed to the get and that will be publishing to this particular server which will be specific to the employee module just like for the course we'll maintain a separate GitHub repository and the course application will be deploying into a separate server so same like the customer module will be having a separate GitHub repository and the code will be compiled back is and will be pushed which will be having a separate a server and that server will be connected to your customer database right so you can see three different database three different server for three different modules you have five more modules same as well just copy to this particular architecture and right now this is our microservices architecture okay hopefully it making sense now few important points independently Deployable I am doing some changes over here this guy is doing some changes the code will straight away go to git okay and we don't have to test right now the customer module you imagine that particular problem that we had last time right we have done something in the course module that has been impacted the customer module right now let's say something is getting done in the employee module then the course module does not have to care about that because for the employee module we have a separate code base and if we make some changes to employee module the code will come to this and this will be separately Deployable we'll be deploying that particular application into this server and the code will be coming from this so if you make some changes here the impact will not be go here okay so this is what the micro services will be independently Deployable now is application can be tested differently absolutely you make some changes over here the testing team right now only have to test this module the employee module you make some changes in the employee module let's say you have created a endpoint called add employees the taster will only click the add employee button and will test that he will not test like you know how the customer will be created or how the customer will be deleted because you only have added a new feature in this module so each application need to be tested differently right now and if something we are working on as a Dev we only need to care about that particular module and the tester can single-handedly focus on that particular module without worrying about something we are making changes over here it is basically breaking some other modules this will right now not happen the another Point here code changes on application server does not need a entire application testing as I said next thing the Dave working on one service should not require the entire application knowledge now you imagine guys let's say you are joining a company first time then they will tell you hey only just get idea about the employee module and just get started now you only need to think how the employee is getting created how the employee is getting deleted so as a div you don't have to care about all the other module or the other modules which are there in the application and you don't worry about those Services whether you can only worry about a single service where you are working on and it does not need the entire module knowledge to get started or to implement a story or to fix some defense so Dave working on one service should not require the entire application knowledge okay right now I will go to the next the microservices are scalable and independently Deployable when the load increases now imagine the same scenario that I have given let's say right now you have employees you have customers you have courses address all these things are separate zip file it has been it has been a different different application and they have been deployed to this blue servers that you are looking at right now this server cost where the customer customer service is running that is basically having lots and lots of load coming so no worries so what you will do if the load basically increases in this server and you see that this particular server cannot handle the load the basically you can see this is your previous uh you know example where your UI code is running on a different server and all these modules are running in different different servers right now there is some load is coming into this server and one instance of this particular server will not be able to handle the request so you will start creating some more server instances or you will start creating some more servers and you will start deploying the customer application in different different server right now the load is only coming to the customer so I have some more servers where I ran only the customer service I did not rain the address or B so the core service of the employee service right now because they are all independent if the more employees are getting registered then I'll have one more server where I will create one more instance of employee so that the load balancer right now will basically route the request less a lot of uh like you know there is some more load coming right now you can see the customer customer that three customer instances are right now running in three different server whereas one course instance is running one employee instance is running in one one server because we are having less load to this but for customer we are having more loads so we have deployed this application in three different server okay because of the load balancing and that load balancing will be taken care by the load balancer don't worry about it Springs gives you a very easy way to implement a load balancer that we'll be talking next okay so now let's wrap up the theory okay I'm also pretty much tired right now tell me guys you know if so far things are making sense or did I did I bore you guys enough because this other theory important theory that I need to tell you before I get started and let me tell you guys micro Services has a lots and lots of theory involved and I will not be going into that right now I will first write code then we will discuss about Theory later right this much theory is enough for you right now I believe to get started just tell me yes and no do you guys get everything that we have discussed so far yes now yes please it is fine but my question is that is that any disadvantage of using microservices absolutely absolutely look at this picture I told you one thing I'll tell you one thing one second look at this thing so mik I'll ask you one one advantage or disadvantage you will you will tell me one advantage of Monolithic you will tell me one advantage of microservices now look at this application this is a monolith application right right now you have your UI you have all your business code and the dial layer into SM server now let's say the employee module need to get some customer data and it's making some call to this now the moment we make a call that I need some customer data the employees are asking for it or the course module is asking for some customer data then in a fraction of second you will be getting data why because you are into the solver you are into the same server yeah wherever your customer module has been deployed then only the course module has been deployed or they are only the address module have have been deployed so they all can add data to each other and they can they can share data without any network latency but right now if you're gonna look into this architecture that we talk about the microservices now we have different different uh you know components our UI our business code are all running under different server and how they will communicate as I said they will be communicate through the restful web services and all these micro services will have different dbls there okay exactly and basically the network latency will be there unless the UI is asking some data here right or it is asking uh it is also connecting to the customers let's say you are basically trying to create a customer or delete a customer then UI you can think like this is an angular application or a react application which has been deployed into a different server now UI is asking for the you know customer data so it need to connect to this particular server right now the UI and the customer are not into a single server there are two different server so all these calls will be rest call and as they have been deployed under a separate uh you know servers the network calls obviously will take time and there will be a latency over here and obviously the more like you know where you have to build one like the deployment was straightforward in the monolithic you can see in the monolithic application the deployment was straightforward it was like this okay like you know one Jenkins one gate you push the code things will go to the server but here you have to maintain different server in the micro Services architecture isn't it the micro Services architecture will look like this now you have different server you have to manage different DB you have to manage you have to you have to make sure that all your debut people are working together to make sure that all the things are running fine I'm not telling you that microservices architecture is bad or problematic it has more like you know it is more suitable for today's generation application okay compared to the monolithic one if the monolithic works fine for your organization go for it but the way the demands and the loads are increasing for application right now it is forcing people to choose micro services and that's why it is a buzzword okay okay uh we will be discussing some more disadvantages as we go forward but yeah any other questions so far yes please any other questions guys srinivas Felix okay okay I haven't taught you anything okay right now we will start coding what will code Morrow c will be covered let's try to cover this couple of modules right now let's create the employee module let's create the address module right now I will not call them module I'll call them Services why because the employee will be a separate service which will serve this request whenever we will hit this end points okay and the address will have endpoints that will start building right now and all this employee can talk to the address uh the employee service can talk to the address service and the address service is also right now able to talk to the employee service okay and this call will happen through the rest so you guys need to be familiar a little bit of rest if you don't don't worry we'll be quoting it from scratch so we will be building this couple of application when we'll make sure to communicate though both of the application will communicate through the restful uh you know protocol okay the HTTP protocol okay so right now the thing is that how to code what should we use and why any ideas what should we use to create this couple of applications that I have set what you will use to code any framework where you can just communicate uh like both of the application will communicate using the restful endpoints any any framework which is you want to come into your mind and why anybody has an answer for this like you know obviously we'll code it in Java but which framework will use anyone and why hey I need some answer or uh waste communication I think we should go with the spring good spring boot so why you are saying springboard stomach why not like you know spring MBC you can also do it through spring MDC but I think why why why it will be why you are saying that spring MBC uh like you know it will be difficult to implement the code but spring boot will be easier why why you're choosing springboard because the presence of embedded okay one point accepted embedded server because you have JT support under two support Tomcat support that's cool any other thing [Music] Auto configuration pankaj is saying fine yes Auto configuration let's say you want to build a application because in microservices you have to build fast yeah you have to you have to build fast and you need like the auto configuration support like you want it uh you want some database connectivity there should be some stator dependency which is going to help you to configure uh your session session Factory Connection connection factory data source and all these things so you so that you don't have to create those beans same for the security as well the auto configuration you need over here okay what else lavanya said uh you know embedded server so make said because it will be fast bunkers say the auto configurations Auto configuration Cinema set the auto configuration any or any other thing that you can imagine right here why you should choose spring boot not spring images yes yeah minimal code and The annotation fine yeah minimal code is one more answer any other thing loose coupling yes absolutely punkers very nice point spring from the starting days giving you the inversion of controller dependency injection support so obviously using spring boot you can you you can create application which are highly loose okay because it's because of the inverse and control or the dependency injection feature fine absolutely I'm accepting that particular Point any other point man is exactly managed dependence 11 year because there are a lot of stutter uh you know projects which are available like starter data jpa starter security there are a lot of different applications which are involved which is gonna basically grab the dependency quickly for you and you don't have to you know do it and manually go to Maven repo and have to configure the things uh open source and lots of exactly one is open source and lots of vendor work on this open source is there are lots of and lots and lots of developer are working on Spring boot so you have a very vast knowledge uh among the developers so obviously people are working in Java right now they most of them are familiar with spring because you know this is pretty much a popular framework so this is open source the knowledge is equally balanced between the developer so obviously you know if something happens the developer can communicate with each other right obviously I know you know most I think 99 of you should be aware about spring even before coming to this course I'm I'm pretty sure about that Felix's Felix is saying load balancer absolutely Felix because see as I said in micro Services application we need automatic scaling why what do you mean by automatic scaling automatic scaling means like there are lots and lots of load is coming to one particular service like there is some more customers coming in and logging into the application or maybe I'm running some offer so my products are getting a huge demand and lots of people are purchasing my products so let's see the product service is getting load or the customer service is getting lowered then we should have some automated environment using Docker kubernetes all these tools you can use to create more and more instances of that particular service in case of a high load okay and in that case we need load balancer to implement and this load balancer guys you know there is there are some free uh projects available in Spring framework which is production ready and you can absolutely use you know use it in your application you don't have to write a load balancer spring is going to give you one so load balancer comes free with the spring okay cool any other any other thing I think lots of good points [Music] okay so right now I'll be giving you some example of creating microservices and how the microservice communication happens you don't have to replicate this example this is going to be a very very straightforward and my intention of making this 10 minutes slide so want to make sure that you should understand creating microservice and making communication happen through the microservice is very very simple right now on your screen you are able to see that a couple of springboard application one is called address service and one is called Employee Service right now let's open this application called address service and let's go inside it open the package called com.seleniumexpress dot addressservice.controllers where we're keeping all our controllers and right now as you can see we already have a controller available called address controller right now let's just annotate this particular class with annotation called at the rate rest controller to make it a controller and now let's just go ahead and create a Handler method now my Handler method name is get address and it is going to return me a sample address back the address it is going to return me is called Lake Road marathali Bangalore now let me have a get mapping annotation on top of this method so that it can we have as a Handler method with an endpoint called slash address now my Handler method is ready and it is ready to accept request so let's just start our server but before that let's go into the application that properties file of this address service application and let's configure a port number where my application will be deployed so I'm defining a server.port and I'm setting it to 8080 right now so that my address application will run on a port 8080 when we start our Tomcat server so let's just run the springboard application and let's see if our server started successfully and looks like it does on port number 8080 and if I'll expand this local I can see my address service is running on Port 8080. good job so we are done with our first microservice development right now let's just go ahead and paste it so right now if I'll be hitting an endpoint localhost 8080 slash address there we go we got our first response from our microservice from our address microservice which is lecroad marathali Bangalore foreign service now let's just go ahead and concentrate on our second microservice which is going to be the employee service now let's just go ahead and hedge towards the controller folder and let's just open up the employee controller class this is a simple class that I have already created just to save some time now let's annotate this class with at rest controller annotation to serve some of the restful endpoints and right now I'll be writing my employee Handler method called get employee and I will be returning a hard-coded response of employee imagine there is an employee called Village and his email ID is a Villas at the rate gmail.com well I'm hard coding this response and I'll be writing my Handler method by writing a get mapping annotation and I'll be mentioning my endpoint name here called slash employee so there you go I have successfully created my employee endpoint right now and now let's just go ahead and configure the port number where this employee service will run now I'll set the server.port in my application.properties file and I'll set it to 8081 once this is done I'll be starting my spring boot application which is my employee service and I'm expecting this to up in Port 8081. and there we go right now my employee service is running my address service is running now I have two microservices my address service and employee service they both are running in two different Tomcat container and my employee service is right now running on a port number 8081 and my address service is right now running on a port 8080 I'll confirm the same with my springboot console and as you can see employee service right now running on a port 8081 in a tomcat server and my address service consolidual switch and if you see I'm inside the address service console and this is running on port number 8080. all right so as we have successfully started our employee application and deployed it into a server let's just go ahead and taste it so let me open a new browser window and let me hit the endpoint localhost 8081 slash employee and boom we get our data right we get our hard-coded employee data over here and if I switch the browser window you can see I have another endpoint also available called localhost 8080 slash address which gives me the address data back so a couple of endpoints we have created so far and these are two different applications deployed in two different servers and they are functioning like a charm all right so right now it's time for the most interesting thing of this coding cell right now we have two different applications running in two different server right now let's just make this applications communicate with each other now here is a requirement for you which is going to make you understand the real need of a rest call Now understand this thing now let me go back to my employee service and let me go to my controller and let me open the packets and open the controller and now inside my employee controller I got a requirement my requirement here is that I need to return the address data along with my employee data so right now my last employee endpoint is just returning you employee data but along with that I want to return some address data as well and for that my requirement here is I'm creating a string variable called address and I'm concatenating that with my return statement and whenever I'll be hitting this class employee endpoint right now I am getting my employee data and I'm getting a null value because I don't have any address set with my address variable so far so here is my need get me the address data and initialize this address variable with the address data but how can you get the address data well right now we are inside the employee service we are inside the employee application and this is deployed into a separate server which is running on a port number 8081 to get the address data I need to connect to the address service which has been deployed into a different Tomcat server and I need to ask the address service for data and how can I do that and for that I need to make a hit to this endpoint so right now I can get the address data by hitting this server URL now this is the end point HTTP colon localhost 8080 slash address if you're going to be hitting this endpoint you're going to be getting the address data back you're going to be getting your address string back now I want to get that address detail by hitting this end point and whatever data that I'll get i'll initialize that data I'll set that data with this address variable and then my requirement will be successful because in line number 18 I'm concatenating this address variable along with my employee information so this address is right now null but let's just get the address data by making an external rest API call from my employee application to address application and in order to make a hit to the address server I need a rest client so to make a rest call using spring boot you need a rest client and in this case we'll be using a rest client called rest template so let's just go ahead and declare the rest template variable over here so I'll say private phase template rest template I'll ask spring to give me the bin for this and I'll annotate this with ADD Auto word so the bin will be injected with rest template and using this rest template object right now I'm gonna be hitting the address server so I'm going to say rest template dot get for object because I'm going to be hitting a get request and my get request for this URL called HTTP colon localhost 8080 slash address I'll be putting this URL over here so I'm asking to rest template to make a hit make a get request to this endpoint and this request is going to be giving me which kind of data you know that whenever you are hitting this endpoint this is going to give you this like Road marathali Bangalore which is a string so now I know this endpoint will get me the string data so I'm going to be saying it get the data in string format and once you get that assign the data whatever this endpoint returns to my address variable and finally I'm concatenating the same with the employee details in line number 23. I think I'm all set but there is an issue in this employee service console and it seems like my application is failed to start and it is asking me to configure the bin for a rest template and it is saying me that the auto wearing is not able to happen because the race template bean is not available that's why it is cannot be injected in this variable and that's why you cannot make a call using the get for object method because the rest template is unavailable so right now let's just go ahead and create a rest template win then so I'll go ahead to my root package and I'll create a new class here called employee app config and right here I'm going to be doing some configuration so I'll be marking this class with ADD configuration and I'll be making sure to create a bean for a rest template so I'll create a rest template bin and I'll make sure to annotate this particular method with the 8 Bean annotation so that my bean for rest template can be maintained inside the application context and as you can see right now my problem has been solved because I have created a rest template bin by myself there you go the things are working fine and my auto wearing in the line number 12 is happening like a charm because I have a rest template Bean is available I'm and also I'll be able to make a call right now in line number 21 using rest template so let's just test this out let's go to the browser window and let's hit this endpoint and let's see that whether we are getting the data for this null and there you go you are getting your address data right now whenever you are hitting slash employee whenever you are hitting slash employee you are not only going to get the employee information also you are getting the address information back so your employee service is internally connect to the address service and facing the information of the address [Music] foreign [Music] right now let me go to the next slides okay so why should we use spring framework because we we can have fast development less configuration order configuration support embedded server and production ready and also we have lots and lots of startup projects like security uh data jpa JMS you know Kafka Reverend what not you can Implement with your springboot application and most importantly as Felix mentioned we have ready-med support for microservices and this ready-made support is available through spring cloud foreign [Music] guys writing microservices is simple but maintaining them is not that simple I'll show you some of the challenges right now imagine guys you have this application called employee customer management app where you have different modules like address module course module employee module customer module X module y module jet module whatever this is a monolith application right now your company want to adopt the microservices architecture so you split this application into multiple services and out of this one application which contains many modules right now you're going to be converting all this module to different different services and different different applications consider creating different different springboot application like this now you have separate separate applications like address service for address module course module uh for that we have core Service employee service customer service ex-service by service their service like that we might have thousands of services thousands of spring boot application thousands of small small application and you know in your spring boot you can configure all this application let's say if these applications are all spring boot applications how you'll be configuring this application you set out okay well as I know springboot don't teach me that I will configure my applications using the application.properties file or application.yaml file I know about that concept so imagine in all these applications right now address service code Service employee service which has suppressor plus springboard applications I have this property in all the properties file of this application like company dot name equal to selenium Express so all good like every application will have a DOT properties file which is your application.preps file and in all this application we have this application that properties file where I have written company.name equal to selenium Express imagine my code is basically fetching the value of this company.name and using the selenium Express value in all of my applications now my requirement here is one day is I'm your client let's say you are developing the app for me I'm telling you that hey go ahead and change the value of company dot name to cell exp okay my company am right now changed to a cell exp so your job is going to all this application open the application.properties file and change the company name to cell exp you've got to go to all this application open the application.properties file and change this particular property name to cell EXP it will be a tough task right now maybe we have five or six service right here imagine you have thousands so how you will be doing it do you want to go to every application open the application.properties file and will changing the value of company.name right over there it will be difficult challenge challenge how we'll be solving this issue okay before you think about this so let me just give you a another issue let me give you some pressure by showing another issue imagine you are writing microservices your company has adopted the microservices architecture you have address Service employee service core service student service location service X service y service set service you have many spring boot applications and all the springboot application has been deployed into many different server and I might have thousands of applications right now all these applications let's say core service wants to connect to Android service student service wants to connect to the core service and wants to get some course related data then how this servers will communicate with each other you said okay simple avalash you call you you make a rest call and all these servers will communicate with each other using the rest API pretty good but now here is my question when a server wants to connect to another server let's say this server is connecting to This Server then before this server connects to This Server it needs to know the IP address it needs to know the port number where this particular application is running in This Server I just need to know the port number I just want to know the server IP address or the server name so that this application can connect to this and can hit some endpoint and can get some data this is not going to be a simple job to manage the thing where you have thousands and thousands of application how you will manage the server IP how you'll maintain their port number because every server when you want some data from another server it needs to connect to them and in order to connect to them it needs to know the IP and the server address of that and it will be a really critical job to handle all the IP and the server ports where you have thousands of server where you have splitted your one application into thousands of different modules and deployed into different different servers don't you think managing the IP and the server URL will be critical in case of Monolithic application used to have one server you used to remember the server IP and the port but now your monolithic has been splitted into thousands of application I'll be handling that but before you get the answer for this let me just give you another headache now imagine okay I have a core service which has been deployed into a server an application server but you know what Diwali is coming Christmas is coming either is coming I am running some offers right now okay I'm running some offers for my people I'm saying hey my course is are right now having 50 off please check out now lots of people coming into my server and are trying to hit a lot of requests to my server right now and my server is right now not able to handle all those concurrent requests or all those requests which has come in from my clients or maybe different people will have different computer and they will be keep hitting my server and my server will not handle the load and you know that okay well as you told me about microservices so what I will do I will have three different copy of my course service and I will deploy them into three different server and right now when requests are coming from the client what I will do I'll just attribute the request between multiple server to balance the load I will not throttle one server by hitting lots and lots of requests to this rather I want this request to be go into different server and for that what I will do I'll introduce a load balancer and my job is going to you know whenever multiple requests I'm getting I'll be make sure it will be first reached to the load balancer and the load balancer will circulate this request to different or among different server and will distribute them in a load balanced way so that one server will not be throttled with many requests but now my question is okay good idea man go ahead and write a load balancer come on go and write a load balancer for me in Java ah okay tough job to do right so don't worry spring gives you free this one let me just give you a spoiler right you'll be using spring framework and you got load balancer comes free with spring Cloud all right so the load balancer comes free with spring uh little relax I'm feeling because I don't have to write this but before you think about it I will give you another problem imagine you have a core service and that has been deployed to a server and right now this is a client but this is not a good client he's a hacker right he knows the end point of your micro service and imagine he's hitting many requests to your server is bombarding the request to your server and eventually if the hacker has a script and he has written that script to hire many requests to the server eventually a server will be down right because it cannot handle that many of requests so how can you tackle this particular scenario if somebody knowingly putting a lot of request to your server where he doesn't have to do anything with your application but you just want your server to go down so that your business will hamper your your application will not reach to the targeted audience or your application will not reach to your clients and your clients will have trouble because your server is down and knowingly somebody is putting a lots of requests to the server how you'll be limiting all this thing right there are many many challenges guys and the last challenge guys right imagine you have a server where you have deployed your student service you have another server where you have core service you are one server your student service wants to get some course data so he's making a rest call and hitting this endpoint called slash courses imagine whenever the student service wants some data once all the courses from the course service is making a request but what about the server server is down and as we are hitting right now from one server to another server there will be a absolute probability that this server will down this server is busy this server is slow and it is not able to take our request and process it there is a absolute reason that a n number of reason that the server will not function good it will function good that should be our priority but think about the negative scenario what about the server where you have deployed your application is slow or is down or it is not able to take or process your request then in that case this request will result in an error and because of that error the student service also will not function good and This Server might have a lot of problem because of the request it is making to another server is failing so how to tackle all this kind of scenario and for this kind of scenario you've got your friend and Ladies and Gentlemen please welcome spring cloud and spring cloud is a project under which we have a large and lots of sub projects which is going to give you a absolute pressure using those sub projects you can solve all these problems you have a spring Cloud config server for a problem number one you have service Discovery registration using Eureka for our problem number two you have resilience for the rate limiter for a problem number three you have circuit breaker pattern for the problem number four and all these things has given free by springboot using the spring Cloud project and spring cloud has all this sub projects using what you can build highly efficient microservices free of cost without having tons of exposure to microservices Creation you can create microservices on the go so let's go ahead and try doing it and try learning it the spring Cloud right now which is going to help us to build highly efficient microservices and it's going to help us to build some of the common patterns that we have in microservices so let's just get started [Music] [Music] so spring cloud is what spring cloud is an umbrella not that umbrella that you basically use in your everyday spring cloud is a collection of projects like Felix said load balancer right when the load increases you need a load balancer so you can use one of the project from Spring Cloud called load balancer like a ribbon or spring Cloud load balancer ribbon is right now I think it's gone uh let's say spring spring Cloud load balancer to implement the load balancing and you don't have to write the logic this guy will get you that particular things freely available you just need to add one dependency and the load balancing automatically starts happening and this guy will get you that particular feature so like load balancing service Discovery Gateway like you know security tracing tracking logging everything will be featured everything will be given by this particular guy so spring Cloud basically provides some of the common tools and techniques and projects to quickly develop some common patterns of the microservices I said microservices has different different patterns all those patterns can be quickly created by the help of spring cloud and that's what we'll be exploring next so what is microservices microservices is an approach using what we can create or develop small small Services is a bad line but yeah I have repeated this particular award just to emphasize this small word we'll be creating small small Services Employee Service product service or something like that okay each service should run on its own process containers or server so every service that will be creating the small small service should have its own database and that should run in different different servers or maybe we can have the container concept here maybe if you guys are familiar with Docker you can create Docker containers and you can create multiple containers and can run your micro Services if you don't know Docker don't worry you can think like you have five different servers and five different micro Services is running in five different server we will not be we will not be deploying two different micro service into one server okay so each Services should run on its own process or on own server the next thing the service should be lightweight and independently Deployable as I said like you know every microservices can be developed independently and will be you know uh what we call that and we'll be deploying that independently so this is your microservices definition I think this is clear right now so let's go ahead and start building this application we'll create a employee application we'll create a address up in the okay in the next class what we'll be doing will be start create first of all we'll make it very simple you guys don't have any prerequisite just joined okay no prerequisite little bit of spring rest knowledge will be enough if you don't have it also don't worry about it whenever there will be some prerequisite I'll tell you hey guys if you don't have this critical side you first have it then you go for this lesson for now there will not be any prerequisite you can think like you'll be will be creating an employee application we'll be creating a address application we'll be deploying them into two different server and also we will make sure we let's say somebody will hit this endpoint let's say employee slash one whereas slash one is the employee ID and here along with the employee information you'll also get the address information right now you can see in the employee we have this particular endpoint employee slash ID once you give that this particular application will internally make a call to the address application and will hit this endpoint and we'll get the data and will populate the data like this whenever you give this endpoint you're gonna get this data you are not only going to get employee data right now you are also going to get the address data as well all right you can see obvious has this address right so whenever you whenever you call this the call will hit to this server and we are hitting this endpoint internally there will be a call which will which will go to another server which is going to be your address service and address employee ID will be called by this endpoint and will pitch the address data and this request whenever you make the request to this this is gonna get you this data which has been which will be faced from two different micro services and two different database and this is where we will be starting our application uh in the next class and we will start developing this thing and then slowly slowly we'll be discussing different patterns different problems different challenges and everything I hope this is makes sense so that's it for today's lesson and and guys let me tell you one one thing before you guys leave see do not worry if you do not know microservices at all and if you know microservices I need you guys to hold on for some time okay give everyone enough space even the people who are following the recording I will make sure that I will not start talking about lot of Hi-Fi word which does not make sense in the first stage there might there might be some of you not some of you may be most of you also have working experience with microservices list there are 200 people the maybe 100 people has already worked on the microservices but you know keep your thoughts uh right now with you for 10 days or 15 days and then you just start asking me your questions like what you are having in your office we will be discussing that later but initially what we will do I will start talking about some simple simple pattern we'll do some simple simple starts will complete spring Cloud will have some foundation will complete reactive have some foundation and then we'll start thinking broadly we'll talk about what is domain what is domain driven design what is a saga what is cqrs what is Event Event storming what is event sourcing what is Kafka how will integrate Revit mq Kafka and all these things but for that you have to have a very good foundation on microservice and that's what we'll try to build from the next class onward right so just give me some time first of all 10 days 15 days 3 4 weeks three weeks once you are done with the spring Cloud stuff let's go and start talking the architecture design pattern in a broad way okay I hope this is making sense so should we wrap up right now anything from your end no ask me yes yes yes okay clear chandrakant Gautam Horace Lakshmi lavanya Manish pankaj from what any anything okay good okay fine cool then thank you very much guys see you guys tomorrow same time 7 30 if I'll be late for five minutes I'll let you guys know be ready by 7 30. thank you very much have a good day we'll have four week session then again I'll take a one week break okay so yeah thank you very much guys let's try to cover up everything and also oh let's try to have around a week session I'll tell you the timing for reactive programming free for everyone okay cool thank you recording stuff thank you guys bye-bye bye guys [Music] [Music] [Music]
Info
Channel: Selenium Express
Views: 28,186
Rating: undefined out of 5
Keywords: java microservices, spring microservices, microservices architecture java, spring cloud microservices, spring boot microservices, microservices, microservices architecture, microservices example, microservices architecture spring boot, spring boot and microservices, java spring boot microservices, spring cloud, spring cloud aws, microservices spring boot, spring cloud tutorial, spring boot cloud, selenium express, microservices java
Id: T2rBkbT50TE
Channel Id: undefined
Length: 84min 32sec (5072 seconds)
Published: Fri Oct 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.