Microservices interview question and answers | Architecture design and Best practices

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so tell me what do you understand by microservices so microservice is basically decoupling of entire application into small small services okay like if I take an example of Amazon or Uber or like you can say any application so like take example of Amazon okay so in Amazon we'll have like many partners like seller then we will have buyers and at the end we'll have like persons from Amazon who will be managing all the applications or like we'll be seeing the transactions and every other details so we will mention it as an admin so this is an entire application say suppose it is written in Java so what happen is like if I need to change something like in buyer I need to change a small like I want to give an offer of 5% so what I need to do I need the I need to write the code and deploy the entire application so instead of this we can use microservice based architecture where the seller will be a single application buyer will be another application and the admin would be another application so here what happen is like if the admin is down or like if the server is down the entire Amazon website is down so but in this case if admin is down people can use the buyer option or like if the seller is down seller will not be able to add any further items to his store but the buyer can able to check out from his cart and or you can add anything from other sellers or which are already in the stores and if suppose I want to change something in seller and want to deploy, so I will just go and deploy this application and the seller what happened is like it may be written in Java it may be written in .net it may be written in node.js so you said that it is a decoupled architecture so coming to that can you explain what are the major differences between service-oriented architecture monolithic application and a micro service so what happen is like as I already told that in service-oriented architecture or monolithic application is the entire application so the application monolithic application is the whole block of application service layer or SOA service-oriented architecture is like we define small small module but inside the same application only so we make it modular wise like we take the part of if you take the example of Java we created packages we create interface for particularly for DAO a particularly for seller particularly for customer and particularly for admin and in micro service what we have is like we'll have more granular levels of breakdowns like in seller also we can have different types of sellers like from us we can have the part for us only which will be running on any servers on us or we can have clients or any other applications who will be interacting with or auth layer for particularly sellers and auth layer for particularly admin 2 different applications we can have so all these are completely segregated and talked to each other in like over an HTTP and not throw the application himself so if I draw an example like monolithic SOA and if I take the example of micro service I can say like microservice and there can be N number of microservices okay now I will give you two scenarios first design a simple micro service architecture application and the second scenario is migrate the existing monolithic application to microservices and what will be your means approach or whatever your thought process to break down those into small small micro services like you took example of Amazon right so you can just show how Amazon can or if you are owner of Amazon that particulars software so how you would have broken it into small small micro services so how I design a micro service is like if it is a new application as you already told since it is a new application so I'll just take the requirements so I will ask like who are the users what are the existing schema how the relationships are mapped like like what are the dependencies like I can have like buyers and sellers so both are actually correlated we can't segregate it out completely so the database , how will manage the databases and all so if I take example of buyer and seller only so buyer will have its own name ID and like items so we have three tables and seller will have like cart details and items brought so these means different tables so this item and this item is related so it is like it can't be like I have brought here like a pan and the buyer doesn't sell a pen or any of the buyers doesn't sell any pen so it it is related so how it interact is like I will call this and suppose he brought already one item or added it so it it will get deleted from here and it will be added here so this is how but these things are completely independent these and these are completely independent so we can keep it out and build two microservices micro-service one and micro-service - yeah this is how means generally we define micro-services for if I am going for a new application and say it is database and this is database and how we will break a micro surface actually this is a long term process it doesn't work so quickly or so nicely so what we can do is like in monolithic application there we need to change the existing application also side by side and there are micro services so suppose we have buyer-seller and we want to take this out and make it as a micro service so what we can do is like instead of buyer calling this we need to have like a mechanism to call an API so admin will also be there residing and API for admin also and it will point to this micro service so we'll build this micro service we'll take this part this is business logic from here and put it here and once it is done then we'll just point it out instead of calling this we will now call this and instead of calling this we will now call this so this is how we break down so we need to take care of similarly the table structure I mean the schema and we need to means slowly and gradually we need to take these and map so it's like a long term process so while breaking those micro services what are the advantages you have and what are the drawbacks while using all this micro service based architecture so the main advantages of micro service is like earlier I told that we will deploy okay so how we'll define is like a we have buyer then we have seller and we have admin so like independently we can deploy independently we can make the code change so it's fault tolerant like if it goes down it will be up it will be up then what else one more thing is like we can expand it like we can scale it so like independently we can have entire admin then admin and we can have a load balancer to navigate the traffic and one more thing is like as its mainly practiced by Netflix so like an individual contributor or an individual developer will take like the requirement then he will deploy he will make the code changes then he will deploy it in like cloud or any server independently so he takes a complete responsibility smaller tasks and more thing and one more thing is like it can be written in Java it can be written in node.js so there is no like dependence on any particular technology so anyone can use any technology this is the main criteria so the main problem is like we can have multiple layers of authentications like micro service one is talking to micro service to micro service 3 then it is talking to individually they are talking with each other then micro service 4 the micro service 5 and suppose like so first of all we need to have individual deployment strategy for each one and suppose if something goes failed here so we need to find out we need to find the root cause or why it got failed so we need to debug all the stages here and why it got fail you need to check and on the top of that we need to have multiple layers of authentications, so for micro service 3 it may able to access few of the applications or few of the API so this one will give like auth this one may have authorization type 2 so here we need to implement multiple types of authorization means like for each one individual applications we need to give multiple layers of authentications or authorizations so you have hierarchical of micro services like micro service one and micro service 2 is talking to micro service 3 suppose which is an auth layer and the micro service 3 is talking to some other micro services like 4 and 5 respectively so if something goes wrong like in micro service layer third or layer 4 something went wrong so how you will know that that micro Service is failing and you need to debug that micro service application logs so to answer your question suppose I have multiple layers of micro services so what we can do is like we can traffic all the logs to Splunk or Kibana or we can say elasticsearch and for each request we can generate a correlation ID so this correlation ID would be passed through each of the headers and it will be logged in the Splunk or like elasticsearch and like suppose if anything goes wrong with this request we can later take out that request and see okay how we can process it from the backend so that's how and if something suppose this server went down so we can have a health check to look for all the servers and suppose this went down the health check will return to the Kibana or email notification like that we can have okay can you tell me some of the best practices of micro-services so best practice there are many things like first we can dockerize it ,so it is not mandatory but we can just dockerize it so I walked in three projects, so in one I used severaless SLS technology for deployment in other application Java we just dockerized it we took the image made our own image and we deployed it in Amazon cloud computing so there is separate build for each application so each a play like micro service one is build and it goes into deployment through Jenkins micro service 2 can use TFS instead of GIT and it can be build like with node.js and any other application and it can be deployed in Amazon Cloud micro service 3 can be deployed it in Amazon or not in Amazon suppose Azure cloud or like Google cloud so means individual build method mechanism or mythology is implemented for each of the micro services and one more best practice is to like for each micro service instead of talking to like micro service one micro service 2 and micro service 3 instead of talking to database 1 or single database what we can do is like we can take this out and make individual databases so while deploying those micro services what are the technology stacks you mainly use so answering your technology stakes I already explained like how micro service works so it's like individuals contributor or it's like a particular team decides like whatever technology they want be used one micro service can be on node.js one micro service can be on like Java ok then PHP but the main overhead is like we need to write the deployment script for each one so if I go with node.js and the deployment would be same means if I am deploying it to Amazon Cloud or any other cloud ok and how you communicate between those micro services and it's like I don't want to give access to all the micro services, so this will be my rest api's right so it will be exposed like either in the VPN virtual private network or I means like publicly so how I can restrict few people's from accessing those micro services or the few are not people's I'll say like few applications how I can restrict them from accessing the micro services how they communicate using normally HTTPS or HTTP so we use REST API to communicate between one micro service so micro service one and micro service 2 will communicate using Rest so what happen is like suppose a buyer once to get some of the information of the items available or not so you can check from the seller side and using get API you can get it but when he bought it like he already added it in cart and he checked out then what the buyer can call for a means like put API to remove this or like soft delete the item so should it be like stateless yeah it's all the apis are always stateless okay why stateless because like inside elastic load balancer or load balancer you can say similar type microservice can be there micro-service one type there can be like n number so like request came I want to preserve it so I will not preserve it because what will happen is like for request one suppose I am trying to get this request get the item so it is served by this micro service item then again when it comes if I am preserving this in this o nly the next request for the put it may come to these or this so this will not be handle so for this we will make it stateless so how we will do authentication is like we will have multiple layers of like micro services sorry, MS1 we can have elastic load balancer or application load balancer and so for authentication or like preserving the session we can use like redis or like any cache mechanism and each one will talk so this one will be single point of contact so this one will all be stateless so how a user interface or a client interact with the first microservice layer like I have a user interface or a browser how I interact with the micro-services so how a user communicate with the micro-service is like suppose we can have client or browser and here we have amazon.com so using like CDN content delivery network we can get the photos and like static pages so this JavaScript will communicate using REST API to multiple applications so from here it will fan out and it will go to like micro service one micro service 2 micro service one and then from here onwards it can communicate as usual like micro service 4 micro service 4 micro service five they can internally correlated and then we have our databases so that's all for this tutorial don't forget to hit the subscribe button if you have any question then mentioned in the comment section or if you want me to make interview questions like this on other technologies like Java and nodejs Amazon Cloud then do let me know in the comment section and from both of us don't forget to subscribe hit the like button
Info
Channel: CodeSpace
Views: 331,877
Rating: 4.7208681 out of 5
Keywords: microservices interview questions, microservices interview questions and answers for experienced, microservices interview questions and answers, what are microservices, Microservices Architecture Interview Questions, microservices training, microservices architecture, microservices tutorial, microservices tutorial for beginners, learn microservices, microservices qna, yt:cc=on, codeSpace
Id: G0waumbpK48
Channel Id: undefined
Length: 20min 58sec (1258 seconds)
Published: Sat May 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.