Event-Driven Micro Services Architecture (In a Nutshell).
Semaan Gerges
Certified Enterprise Architect - CGEIT | TOGAF Certified | CDMP | PMP | PBA
This is a long story short description of the different aspects of Event driven micro services architecture.
What is a monolith?
It contains Routing | Middle wares | Business Logic | Database access to implement ALL FEATURES of an app.
What is a micro service?
It contains Routing | Middle wares | Business Logic | Database access
to implement ONE FEATURE of an app.
Data in Micro service:
Most challenging aspect in MSA is Data management between services.
- Each service gets its own db if it needs one.
- A service will never reach into another service db.
Why?
- Every service should run independently of other service(s).
- db schema/structure might change unexpectedly.
- Some services might function more efficiently using different types of db's.
A Database-Per-Service approach is adopted with MSA
Communication Strategies Between Services:
- Synchronous: Services communicate with each other using direct requests.
- pros:
- Easy to understand as a concept.
- One or many services wont need their proper db to make requests, they depend on other services db's.
- cons:
- It will create a dependency between services, meaning if service A depends on service B with a db, if service B crashes, service A will also crash.
- If an inter-service request fails, the overall request fails.
- The entire request is fast as the lowest request.
- It introduces a web of requests, meaning lot of requests consumption and risk of bottlenecks.
- Asynchronous (Event driven): Services communicate with each other using events using an Event Bus & persist events in relevant services db's.
- pros:
- Zero direct dependencies between services.
- Reduces possible failures into single a point (Event Bus).
- Events are persisted with proper collection segregation.
- Services will become extremely fast, hence low latency.
- cons:
- Data duplication, as events emitted are persisted in almost every service db. (However data storage cost is minimal on cloud)
- Could reach a high level of complexity.
TIP: Mitigate architecture risks by considering necessary service storage over risks of potential multi points of failure in services architecture.
References: @StephenGrider
Cheerz,