- Discussion
- Useful Resources
- Quick Guide
- Blue Green Deployment
- Circuit Breaker
- Service Discovery
- External Configuration
- Health Check
- Distributed Tracing
- Performance Metrics
- Log Aggregation
- Event Sourcing
- Aysynchronous Messaging
- Saga
- Command Query Responsibility Segregator
- Shared Database per Service
- Database per Service
- Branch
- Chain Of Responsibilities
- Client Side UI Composition
- Proxy
- Aggregator
- API Gateway
- Decompose by Strangler
- Decompose by Subdomain
- Decompose by Business Capability
- Microservices Design Patterns - Overview
- Microservices Design Patterns - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Command Query Responsibipty Segregator
Problem Statement
Microservice architecture structures an apppcation as a set of loosely coupled microservices and each service can be developed independently in agile manner to enable continous depvery/deployment and if we ve used a database per service design pattern then how to make query which needs data from multiple services.
Solution
We can define a view database which is a read-only data to support the required query. Apppcation will keep the view database up to date by subscribing to the events raised by the services which owns the data. In this design pattern, we segregate the update and read operations. One service will only read the data and other services will update the data.
In order to implement this pattern, we often need to refactor the domain model to support seperate operations for querying data and to update data so that each operation can be handled by microservices independently. CQRS patterns ensures that operation that reads data is seperate from that which updates the data. So an operation can either read or write data but cannot perform both together.
Now multiple services can update the records and send events to apppcation to update the view database. This helps the Query service to get the consistent data without any performance hit.
Advertisements