Q&A-17What is the difference between an event and a command, and why does it matter?
Answer
A command instructs a specific consumer to do something: SendWelcomeEmail. It has one intended handler, it expresses the producer's intention about what should happen, and the producer knows who will act on it.
An event states that something happened: UserRegistered. It has no intended handler, it is a fact, and the producer need not know or care who is listening.
The difference matters most for coupling. A producer emitting commands must know what should happen, so adding 'also create a trial subscription' means changing the producer. A producer emitting events does not: a new consumer subscribes and the producer is untouched. That is the property that makes event-driven architectures extensible, and it is the main reason to prefer events at boundaries between teams or services.
It also matters for naming and evolution. Events are past tense and immutable facts: OrderPlaced was true when emitted and remains true. Commands are imperative and may become inappropriate: a ChargeCard command sitting in a queue for an hour may no longer be right if the order was cancelled meanwhile. Events do not have that problem, because a fact does not expire.
And for replay. Replaying events reconstructs what happened, which is coherent. Replaying commands re-executes intentions that may no longer be appropriate, which is not, and that is a real difference when you need to reprocess history after a bug.
Commands are still legitimate. Task distribution is genuinely command-shaped: 'resize this image' has one handler and is an instruction, and pretending it is an event by calling it ImageUploaded when only one consumer will ever act on it adds indirection without benefit.
The failure I would look for is an event that is really a command in disguise: OrderPlaced published to a queue with exactly one consumer that must handle it, with the producer depending on that consumer's behaviour. That has the coupling of a command and the indirection of an event, and being honest about which it is makes the design clearer.
The practical guidance: commands within a bounded context, events across boundaries. Inside a service, instructing is fine and simpler. Between services, events keep them independently evolvable, which is usually why they were separated at all.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.