Micro Services With Node and React
Micro Services With Node and React
16 Dec 2022
Monolithic Server
Monolithic servers contain all codes to implement all features of our app
Micro Service Architecture
A single Micro service contains all codes to implement one feature of our app
Micro Service Architecture
A single Micro service contains all codes to implement one feature of our app
A Micro service is self-contained
If all micro services except one goes down, it does not impact the single running micro service.
The feature implemented in the running micro service will work just fine
Data in Microservices
Each micro service has its own database and will not reach to another service’s database
Data in Microservices
Each micro service has its own database and will not reach to another service’s database
Why Database-per-service
To decouple micro services
If two or more micro services talk to same DB and that DB goes down, then all the micro services connecting to that DB will go
down as well
If each micro service is using a different DB then it is easier to scale up only the DB that requires scaling up
DB schema/structure may change
Some services may function efficiently with one type of DB (E-g MySQL) and other my work well with another type of DB (E-g
Mongo)
Communication Strategies Between MS
SYNC
Micro Services communicate with each other using direct requests
ASYNC
Micro Services communicate with each other using events
Sync communication Example
Here Service D needs data from Services A,B and C
D connects to A, B, C through HTTP calls
Sync communication - Pros and Cons
Pros
Easy to understand
Service D does not need a database
Service D does not connect to the Databases of other MS
Cons
Coupling is introduced between D and Other services
If anyone service fails then entire request would fail
The entire request is only as fast as the slowest request
Could easily introduce a complex web of requests
Sync communication - web of requests
Sync communication can introduce complex web of requests
Async communication
Each service is self container with its own database even if it means data duplication across different services
Service D duplicates the data from DB-A, DB-B in its database
Async communication
Each service is self container with its own database even if it means data duplication across different services
Service D duplicates the data from DB-A, DB-B in its database
Async communication - Pros and Cons
Pros
No direct communication between services
Services are Extremely fast
Cons
Data duplication - Extra DB storage
But this is very minuscule. The cost is ignorable when compared to the advantages it gives
Complicated. Difficult to understand
MS With Event Bus Architecture
Pros
No direct communication between services
Services are Extremely fast
Cons
Data duplication - Extra DB storage
But this is very minuscule. The cost is ignorable when compared to the advantages it gives
Complicated. Difficult to understand
Event Syncing
If a particular service is down for sometime, then it will lose all those events that it had subscribed to, during that downtime
We can resolve this issue with the technique called event syncing
The event bus should store all the events it receives.
Whenever any service starts, send a request to event bus to get all the events stored in event bus and handle them one by one