</>CodexBash
All articles
System design

CQRS explained

Command Query Responsibility Segregation explained: separating the write model from read models, commands and queries, keeping read models up to date with events, eventual consistency in the user interface, how CQRS relates to event sourcing, a worked example, and when it is worth the complexity.

CodexBash, , 5 min read

In most applications, the same model serves both writing data and reading it: one set of tables, one set of entities, used by the "place order" code and by the "show my orders" screen alike. That works well until the two needs pull in opposite directions: writes need strict rules and normalised data, while reads want fast, denormalised views shaped for each screen, sometimes at a hundred times the volume. CQRS, Command Query Responsibility Segregation, resolves the tension by separating the two sides deliberately. This article explains the idea, how the sides stay in sync, and when it is worth doing.

Sign in to read the rest

The whole 5 minute article is free with an account, along with every problem, lesson and tutorial. No card.