Microservices-Design Patterns For Microservices, So You Won’t Abuse It— 5
--
Aggregator Pattern
There are 3 ways of implementing the aggregator pattern.
- Chain Pattern (also known as service chaining)
- Branch (also known as branch aggregation)
- Parallel (Scatter Gather Pattern) (also known as parallel aggregation)
Backends and Pipes Concept
In ESB-based development, there lies a concept called intelligent pipe and dumb backend. However, this is different for microservices making it; dumb pipe (dumb channel) and intelligent backend.
1. Chain Pattern
Create a single service (A) that can consume two other services (B and C) in serial manner (one after the other). Then send back the aggregated result back to the consumer. With Chain aggregation, the response time of talking to services B and C could be higher that parallel aggregation as both calls happen one after the other. Mostly followed for migration purposes from legacy systems to microservices. Chaining pattern is also used in scenarios like encryption/decryption systems as the obtaining of the result is needed before moving on to the next process.
2. Branch Aggregation
Making the decision on which microservice to call based on some factor/decision.
Advantages of following a design pattern for microservices
- Aggregation services doesn’t cost much with not much processing.
- Consumers have the choice to migrate in accordance with their timeline. After all the consumers are migrated to the aggregated service, the legacy service could be shut down (either manually or with elasticity)
- Production is easier as the development happens independently.
Few things to note for when creating microservices
- Since performing service validation on multiple layers take time, try to have a separate identity service along with a token validation process to save as much as time on the round trip.
- Consider infrastructure and security along the way so the system isn’t vulnerable or doesn’t compromise the security of the service.
3. Parallel (Scatter Gather) Pattern
Create a single service (A) that can consume two other services (B and C) in parallel, which will then send back the aggregated result back to the consumer. This pattern creates a dependency between service A and the two other services. With parallel aggregation, the response time of talking to services B and C could be reduced since both happen in parallel.
Thanks for reading. Until next time! 👋🏽
References