Event-Driven Architecture: When to Use It and How to Design It
Event-driven architecture publishes facts about changes and lets subscribers respond asynchronously. It helps independent consumers and high event throughput, but consistency, duplicates, ordering, and failure tracing need deliberate design.
Structure and key terms
An event-driven architecture (EDA) has event producers, an event channel or broker, and consumers. An order service can publish an OrderPlaced event for inventory, notification, and analytics services to handle independently. Producers need not know their subscribers, which supports independent deployment and scaling.
An event states a fact that already happened; a command asks a specific component to act. Keep the meanings distinct even when they share a messaging system. Event publication usually does not wait for a response, so turning an immediate lookup or validation into an event flow can add needless complexity.
Choose a topology and delivery model
In a broker topology, producers distribute events and consumers handle the ones they need. This loosely couples simple flows and makes subscribers easy to add, but no component owns the state or recovery of a multi-step workflow. In a mediator topology, a coordinator manages the next command, progress, and error recovery. The flow is clearer, but the mediator can become a bottleneck or failure point.
Pub/sub and event streaming are a separate choice. Pub/sub suits subscriber notifications; a log-based stream retains events so consumers can read from their own positions or replay them. Retention, replay, and ordering guarantees vary by product, so the term “event-driven” does not define delivery guarantees.
Decide with an order example
If inventory, notifications, and analytics can react independently after an order is received, and their success need not block the response, publishing an OrderPlaced event through a broker is a natural fit. If inventory reservation and payment results must be combined before confirming or cancelling the order, a coordinator that tracks state transitions and compensating actions may fit better.
The interface should distinguish “order received” from “order confirmed.” Views can temporarily disagree before asynchronous processing finishes. Keep work needing immediate strong consistency in a synchronous call or one transaction, and publish events for follow-up work in a hybrid design.
Design for failures and data contracts
Consumers should be idempotent: handling a redelivered event must have the same effect as handling it once. Assume at-least-once delivery and use an event ID to detect work already applied. If order matters, partition or create sessions by a key such as order ID, and check how that ordering scope limits throughput and scaling.
Separate database updates and event publication can leave one successful and the other failed. A transactional outbox stores the state change and event in the same database transaction, then a separate dispatcher publishes it, reducing this inconsistency window. Prefer backward-compatible schema changes such as optional fields. Include correlation IDs, schema versions, retry counts, and a dead-letter queue (DLQ) in recovery and observability plans. Keep sensitive data out of events unless consumers need it.
Adoption checklist
Before adopting EDA, answer: (1) Who publishes which fact, and who consumes it? (2) Can the business tolerate delay and eventual consistency? (3) What scope of duplicate handling, retry, ordering, retention, and replay is needed? (4) How will failed messages be isolated and retried? (5) Can a correlation ID trace the flow end to end?
EDA helps when independent consumers react to the same change or the system must absorb high event volume. For simple request-response, immediate strong consistency, or teams unable to operate distributed asynchronous systems, consider synchronous calls or a queue-based workflow first. Start small; inject duplicate delivery, consumer delay, and an invalid schema to verify recovery before expanding.