Today’s industries where software applications are built on a day to day basis developers always have to keep in mind regarding the architecture and the implementation of the code and also the UI of through which the user will interact with the application now the only way to make sure that all these parameters are met is by using Microservices and API.
What are Microservices?
What do you understand by the term Microservices well the term Microservices defines itself what I mean by that is it’s basically small tiny services communicating with each other so if I have to define Microservices for you then Microservices are most commonly known as Microservices architecture is an architectural style to build the applications now these applications are basically the software applications so basically you can structure an application as a collection of small or normal Services models around the business domain for example let’s say you know you have an e-commerce application your business domain is basically eCommerce so for that you’ll take care of what all functionalities and features are required and according to that you will build these services now when I say services it’s not with respect to the number you can have any number of services based on the architecture or the application that you have now before Microservices came into the picture industries we’re using the bone elliptic architecture.
So what I mean by monolithic architecture is basically that you know you have the complete application stored in the single bucket when I say stored in a single bucket what I mean is that you know all the functionalities and the features are stored at one place so basically all the features the dependency is the functionalities of the complete application either it be the front end in the back end and all of them will be residing at a single place so that’s what monolithic architecture basically mean guys so for this session let’s take an example and then we will understand all the topics with that particular example now if you consider an e-commerce application what do you think are the main three functionalities of it for example let’s say you using Amazon what all do you see you’re a customer you see all the products on Amazon and then you put your products into the cart and finally you order those products that is basically the simple workflow if you have to understand now if you have to build this application using micro services what you can do is you can have mainly three functionalities.
- The customer information
- The products available in the cart
- All the products available on the website
Now all these three functionalities can be put into different services what I mean by that is you can have service a having customer information service be having the products available in the cart and service C having all the products available in the application.
Now when the customer goes forward and orders a particular product you can have a corn faucet Microservices which will basically take data from all these free services and generate the output for the client so I hope you’ve got an idea of what I’m talking about now as I was telling you that you know before micro services came into the picture there was monolithic architecture how do you think all these functionalities of the application were stored in this kind of architecture well it’s really simple. What would happen would be all these three services
That is the customer service the product service and the cart service would be the siding in a single area and then here would be a data access layer through which you can access the data so as you can see you screen you have applied browser through which the client requests for the information so as soon as the client would request for the information on the application the request would be passed to this particular area where all the functionalities are present and the data would be retrieved from the data access layer and the data piece so if I have to just define monolithic architecture for you then it’s really simple guys monolithic architecture is an architectural style in which all the functionalities or the required components would be inside one single block so I hope that particular part is clear so I hope that you’ve understood what was monolithic architecture and what are micro-services on that note let’s get into the second topic
What is API’S?
What are API’s what do you think API is i’ve obviously everybody has heard of this term API so you can basically understand API is as a point of contact through which all the services communicate with each other to process the client request and send the response so for example let’s say you know you’ve sent the client request let’s say on Amazon you’ve requested for a phone so if you just type phone what will happen is that you know this particular request will be sent through API Stu the respective functionality or a feature and that particular functionality or feature will retrieve the requested data and then will send back the response to the client so if you see you are applied then this particular functionality or feature present in the application and then in between both of you there’s API through which we can communicate so I hope that point was clear now while building and using these applications what developers do is that you know we basically use the crude operations when I say crude operations what I mean by that is we basically created a source read on the source updated resource and deleted the source so API is are generally developed by using the restful style and these methods are nothing but the HTTP methods now I’m sure you must have got confused when I said created a source read in the source updated resource and deleted the source well guys it’s really simple to understand for example let’s say you know you using book Marshall and then you want to find out the details of a specific movie so what you do is you send a client request so when you send a client request you basically asking for the information so what will happen is that you know the information has to be read and then the response has to be sent to the client so that basically reading the resource coming to creating updating and deleting this is one basically the developer site where you know they keep adding the information to the application or may be specific movies details are updated or may be the complete movies deleted so basically the information of the movies deleted once it is out of the market so that’s how basically it works now whenever we send a request what happens is that we are basically sending an HTTP request so for that we use the HTTP methods.
HTTP Methods?
The different HTTP methods so the HTTP methods are as you can see on my Blog screen we basically have the post catch put and delete methods so whenever you want to create a resource you basically used post method whenever you want to read a source you use the get method whenever you want to update a resource you used put method and whenever you want to delete a resource you use a delete method so basically guys API issued these methods to basically communicate between the client and the respective functionality or the feature of the application.
Where are API’s used in Microsevices?
API is used in Microservices now when I was explaining API is for you I was always saying that you know they’re basically a middle person between the client and the respective feature of the functionality now obviously that particular feature or the functionality can go into a specific service so let’s say you know we have a functionality of all the products present in the application now that particular feature can be present in a specific service so now when a client requests for all the products available in the application the request can directly go to that particular service and the response can be generated back so I hope that point is clear so what you can do is basically the application that we took the example that we took we had a client browser and in the monolithic architecture the customer information the product service and the cart service all these three services basically all these three functionalities residing in the same area and then there was a common data access layer and then a common database now when you break down this application or may be when you refactor this application into micro-services what you can do is you can have a specific micro-service and then you can have its own data access layer and database and for each Microservices there’s a separate API so basically the customer micro-service will have a specific API data access layer and database similarly goes for the product Microservices and the cart micro-service now it’s not necessarily that you know there’s single database for each and every micro-service it may also happen that you know two or three Microservices share a common database through which the data is retrieved so basically guys if you have to understand where API I used in Microservices it’s really simple each service will basically have its own API through which the services will communicate with the client so for example let’s say you know your app and then you’re asking for your own information your own customer details what will happen is as soon as you send the request basically the API gateway will decide to which service this particular request has to be sent now since we’ve owned the customer details this particular request will directly go to the customer Microservices and what will happen is that you know the required data will be retrieved from the API and then again the API will send back the requested response to the client so basically that’s it all that you have to understand guys that you know each service will have its own API and then through that particular API you can communicate with that particular service now it’s not necessary that you know you need information from a single service even in that scenario is what will happen is that you know each Microservices will generate the requested data and all of them together will send back the requested response to the client so I hope that you understood where our API issued in micro services.
Microservices V/S API
The differences between Microservices and API now in this tutorial on Microservices with API I hope that you know you’ve understood what are basically micro services and what API skies these are completely two different things micro services is basically.
Microservices: An architectural style through which, you can build the applications the form of small autonomous services.
API: A set of procedures and functions which allow the consumer to use the underlying service of an application.
So basically the main difference between Microservices and API the micro service is basically an architecture through which you can build the application and API is is basically like a middle person between the client and the services through which you can establish communication between both of them so I hope that point is clear also from the example that I explained you I’m hoping that you know it’s clear to you that you know API is are a part of Microservices and thus it helps these services communicating with each other however while communicating with the other services each service can have its own crewed operations to store the relevant data in the database not only this but while performing the crewed operations API is generally accept and return the parameters based on the requests sent by the user so for example if the customer wants to know the order details so maybe he must have ordered few items what will happen is that you know the product details will be fetched from the product service the billing address and the contact details will be fetched from the customer service and the product purchased will be fetched from the cart service so basically if you have to you know generate a specific theater or maybe if you want a specific data all these services can communicate within each other with the help of API and generate the request of the spots so I hope it’s clear to you guys so guys this was the basic differences between Microservices and API, Microservices is basically a simple architectural style and API’s are a set of procedures and functions which allow the consumer to use the underlying service of the application so if you’re someone who is aspiring to build an application using micro service architecture I would always say that you know make sure that you know your API is are working and then all the services are working are collaborated with the API is in such a way that you know no request is harmed and maybe all the client requests are satisfied with the requested response so I would just say go forward and we’ll applications using micro services.