Event-Driven Architecture
In an event-driven architecture, components communicate by publishing events (facts about something that has happened) and reacting to the events they care about, rather than calling each other directly.
Event-driven architecture is the natural partner of serverless and managed messaging services. It’s one of the most effective ways to architect for change: new behaviour can often be added by subscribing a new component to existing events, without touching the components that publish them.
Events, commands and queries
- An event states a fact in the past tense:
OrderPlaced,PaymentFailed. The publisher doesn’t know or care who’s listening. - A command asks for something to happen:
ShipOrder. It has one intended recipient, and it can be refused. - A query asks for information and expects an answer.
Confusing these is a common source of tightly coupled “event-driven” systems. If a publisher needs to know that one particular consumer acted on its message, it’s sending a command, not an event.
Events themselves come in two main styles. An event notification carries just enough to say what happened, and consumers call back for details if they need them. Event-carried state transfer includes the relevant data, so consumers don’t need to call back, at the cost of larger and more tightly specified messages.
Choreography or orchestration?
- Choreography: each service reacts to events and publishes its own. There’s no central controller. It’s very loosely coupled, but the end-to-end flow exists only implicitly, which can make it hard to see and change.
- Orchestration: a workflow service (for example AWS Step Functions, Azure Durable Functions or Logic Apps, or Google Workflows) explicitly coordinates the steps, including retries and compensation.
We recommend choreography between business domains and orchestration within a business process that has clear steps, error handling and compensating actions. Either way, describe the important end-to-end flows explicitly, as narrative scenarios that you can test. Otherwise nobody can say what the system as a whole actually does.
The costs
Event-driven systems trade one set of problems for another, and it’s worth being honest about the new set:
- Eventual consistency: different parts of the system will briefly disagree. The business needs to be comfortable with that, and the UI needs to handle it.
- Duplicates and ordering: most managed messaging delivers at least once, and ordering is often not guaranteed. Consumers must be idempotent, so that processing the same event twice has no extra effect.
- Debugging: there’s no single stack trace. You need correlation IDs, distributed tracing and good observability.
- Failure handling: messages that can’t be processed need dead-letter queues, alerts and a way to replay them.
- Schema evolution: events are interfaces, and other teams depend on them.
Good practice
- Name events in business language, in the past tense.
- Treat event schemas like published APIs: version them, keep changes backwards compatible and keep old versions working while consumers move. Don’t freeze interfaces early, but never change a published version.
- Use a schema registry or shared contract definitions (for example AsyncAPI).
- Use the transactional outbox pattern so that a database change and its event are published together or not at all.
- Design for replay: being able to rebuild a view by replaying history is a superpower, and it’s the idea behind event sourcing.
- Smooth out load with queue-based load levelling.