#📝 Note: CQRS (Command Query Responsibility Segregation)
#Overview
CQRS is a pattern that separates read and update operations for a data store. Implementing CQRS in your application can maximize its performance, scalability, and security.
#Core Idea
- Command: Changes the state of a system (Write).
- Query: Returns a result without changing the state (Read).
#Why Use CQRS?
- Independent Scaling: Read and write workloads often have different performance characteristics.
- Optimized Schemas: The read store can use a schema optimized for queries (e.g., Elasticsearch), while the write store uses a schema optimized for updates (e.g., PostgreSQL).
- Simplified Security: Easier to manage who can change data vs. who can read it.
#Trade-offs
- Complexity: Managing two separate data models and keeping them in sync.
- Eventual Consistency: There is usually a delay between a write and when it appears in the read store.