Command Side Design
You'll learn how to build the command side of a CQRS system that validates business logic and produces events without worrying about how data will be queried.
The Core Idea
In CQRS, the command side handles all operations that change the system's state—creating orders, updating profiles, canceling subscriptions. Its job is to enforce business rules, produce domain events, and persist those events (often to an event store), but not to optimize for reads or queries.
Think of it like a journal: when you write in your diary, you focus on capturing what happened truthfully and completely. You don't worry about how you'll search or summarize those entries later—that's a separate concern.
Command Handler Responsibilities
A command handler on the command side typically:
- Validates the command against business rules
- Loads the current state (often by replaying events from the event store)
- Executes the business logic on the domain model
- Produces one or more domain events representing what happened
- Persists those events to the event store
The command side doesn't maintain denormalized views, materialized tables, or query-optimized structures. It cares only about capturing the truth of what changed.
Separation of Concerns
By isolating command handling from query needs, you can:
- Model your domain naturally without compromising for read performance
- Evolve your write model independently from your read models
- Scale writes and reads separately
- Apply different consistency guarantees (strong on write, eventual on read)
Key Takeaway:
The command side enforces business rules and produces events that represent state changes, treating persistence as an append-only log—completely independent of how data will be queried.