Microservices
Microservices
Interact with each other like lightweight protocol like rest http and also lot of library available.
list product
shipping
payment
They are not dependent on other services in same app.
If required they make rest or RPC call for other services to get or update services and they deploy
separately.
Advantage as Monolithic:
Disadvantage:
If technology build on jango then may be notification serve build with nodeJS or someotjer
Or some company give nodejs or go.
Can’t use because we use jango and python cant integrate due to technology difference
2) engineer focus: team work on order management understand same team and understand code
and tightly couple too
3)scaling data layer: we can scale VM but as we have more VM everyone talking to same DB.
4) overloaded VM/container:
5)CI/CD problem: the test will be pain point need to run test for all application
And build take time and push code have so many conflicts to same repo.
So new dev to team understand code pain as its huge file of code as new dev lost understand all of
this code.
To take problem and make a better ecommerce scaling and all we can do with microservices.
Monolithic architecture:
Functional Decomposition:
Broken into different services and have code base and different team have underatand for specific
services and maintain application and individual deploy and scale horizontally based on traffic.
What to do is make call from shipping to notification it will be of different interface like
Advantage : since one DB per service shows what kind of data we want not like old monolotic.
Search+product ->elastic .
Advantages:
Deploy easy: as size of code base is small and start time is reduce.
No dependency on services
Faster to develop to understand: code base is small like how payment work can check payment code
only bcoz its loosely couple as code based to specific services.
Microsevices are loosely coupled:
Means change part of code in one services doesn’t affect other services.
While monolithic app change one part of code have impact on other modules.
If payment service not working it wont impact other services like search or add to cart or other.
Also load balancer and all also service discovery and gateway.
Functional decomposition: decompose search and product page into more services
Like 3 services
Service 1 -> a to c
Service 2-> d to k
Service 3 -> N to z.
Above techniques to scale microservices but vertical scaling cant do bcoz can be hard end
API gateway:
If monolithic architecture we use expose one API /productinfo/product ID 123 all in one api we
could have.
1) Direct calls -> front end call each services one by one or parallel.
But is it good or best way to do it as we need to make 7 calls as will have impact on load time
If tomorrow split rating and review into two different services then update client to update 8 calls
than 7.
2) API gateway:
And API gateway makes 7 calls to microservices and combine those and give to client
if want to make two serial calls one of another then can configure in API gateway
first call search product based on that 6 different calls can make also possible with API gateway.
Another access pattern for API gateway called as backend for front end :
Instead of one API gateway it can have another API gateway for mobile and web or another
Scroll and pull data based on info different kind of combination for different kind of devices
Authentication: can happen at API gateway like token based(JWT JSON token based) which check
Only HTTPS verify until API gateway and services can have using http internal calls.
Load balancer: increase serve for search product then API gateway understand increase LB.
Insulation: no one can access directly only API gateway can access it.
Increases hops one hop to API and another hop to service might increase latancy.
System get complicated take API gateway and configure and maintain microservices.
Service Registry:
Client wants to talk to microservices without API gateway how can it be achieved?
If shipping want to talk to merchant microservices which can be solved using service discovery.
But its work as load balancer but LB need to be informed about network address of microservices
where service registry come into picture.
Service discovery: identity network address all instance of microservices using service registry.
When client talk to microservices then ask service registry give address of shipping network address.
Two ways?
Third party registry: Microservice not talk to service registry but service registry ask
microservices about address.
Service registry listen to cluster scaling up it heard that and service registry talk to that
Other advantage: how many instance of service running or responding or not as its
What is discovery?
Client know location of service registry ask for latest network address of services.
What if client cant go and ask service registry every time it might get timeout?
And API request service registry to give network address for microservices and use that list
An order is placed and every other microserices wanted to know if order is placed
https://www.youtube.com/watch?v=5XeVoHtFGo0
https://www.youtube.com/watch?v=q-EkBbfuiAo
https://www.youtube.com/watch?v=XJS_GwcLfHc