Back to glossary

CQRS (Command Query Responsibility Segregation)

An architectural pattern that separates read and write operations into different models, allowing each to be independently optimized, scaled, and evolved for its specific access patterns.

CQRS splits an application's data layer into two sides. The command side handles writes (creating, updating, deleting data) with models optimized for validation and business logic. The query side handles reads with models optimized for fast retrieval and the specific data shapes that views require. The two sides are synchronized through events or eventual consistency mechanisms.

This separation enables powerful optimizations. The write model can use a normalized relational schema optimized for consistency. The read model can use denormalized views, materialized aggregations, or even a different database technology optimized for query patterns. Each side scales independently based on actual load.

For AI products with asymmetric read/write patterns, CQRS is particularly valuable. A recommendation system might write user events to an event store (command side) while maintaining a precomputed recommendation cache (query side) that serves millions of reads per second. The read model can include pre-computed ML features, aggregated user profiles, and cached model predictions, all optimized for sub-millisecond query latency.

Related Terms