Event-driven architecture, messaging, and streaming
Events state that something happened. Commands request intent. Queries ask for information. Messaging decouples time and availability, but creates delivery, ordering, duplication, schema, and observability work.
Core ideas and patterns
| Idea | What it solves | Cost, limit, or warning |
|---|---|---|
| Publish-subscribe | Fans an event to independent consumers | Consumers can lag or interpret semantics differently |
| Message queue | Distributes work among competing consumers | Poison messages and fairness need handling |
| Event notification | Signals change with minimal data | Consumers must fetch state and race with later changes |
| Event-carried state transfer | Lets consumers maintain local read state | Duplicates data and raises privacy/retention issues |
| Event streaming | Maintains an ordered log for replay and processing | Partitioning limits global order |
| Competing consumers | Scales independent work | Ordering per entity requires partition strategy |
| Dead-letter channel | Quarantines repeatedly failing messages | A DLQ is not a recovery process |
How to apply it
Define message intent, owner, schema, identity, partition key, ordering scope, delivery guarantee, retention, privacy, retry, expiry, and recovery. Assume at-least-once delivery and build idempotent consumers unless stronger semantics are proven end to end. Version for semantic compatibility.
Evidence, not opinion
Track consumer lag, age of oldest message, duplicates, handler latency, retry/DLQ volume, schema compatibility, replay outcome, and business reconciliation.
Small example
OrderPlaced contains stable order facts and version. Inventory reserves idempotently using event ID and order ID. A duplicate delivery changes nothing; a late incompatible version is quarantined and alerted.
Feynman check
Explain the design to a new engineer without using the pattern names. State the problem, the forces that conflict, the chosen boundary or mechanism, what can fail, and the evidence that would prove the choice still works.