Commands vs events: a small but important distinction
Both are messages, but they carry different intent:
- A command says "do this". It's directed at a specific handler. Imperative. May fail or be rejected. Example:
ChargeCard(orderId=42, amount=99.99). - An event says "this happened". It's broadcast to anyone interested. Past tense. Immutable. Example:
OrderPlaced(orderId=42, amount=99.99, userId=7).
The difference matters. Commands are 1-to-1; events are 1-to-many. A new consumer can subscribe to an event without the producer ever knowing. That's the structural property that makes event-driven systems extensible โ and the same property that makes them harder to reason about.
