beginnerIntroduction to CQRS

Why might the model used to write data in a system look very different from the model used to read it?

A write model exists to enforce correctness: it needs to validate business rules, like checking whether a loan amount is within policy or whether an account has sufficient funds, and it's usually shaped around those rules rather than around any particular screen. A read model exists to answer questions fast, and it's usually shaped exactly like whatever is consuming it — a dashboard that needs a list of overdue loans sorted by amount, or a profile screen that needs one customer's accounts, cards, and loans combined into a single object. Trying to serve both needs from one shared model tends to leave both jobs done worse than they would be done separately, which is exactly the imbalance CQRS is designed to fix by letting each model be optimized for its own actual purpose.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What makes it possible for a single component to build a read model from events published by several different microservices?← Back to all Event-Driven Microservices questions