Event-Driven Architecture in System Design

Events vs commands, event notification vs event-carried state transfer, delivery guarantees, ordering, schema evolution and where EDA helps or hurts in system design.

What it is

In event-driven architecture (EDA), components communicate by producing and reacting to events: immutable facts that something happened (OrderPlaced, PaymentCaptured). Producers do not know who consumes the event. This decouples services in time (asynchronous), space (no direct addresses) and change (new consumers without changing producers).

Message type Meaning Example Coupling
Command "Please do X" to a specific receiver ReserveInventory Sender knows receiver
Event "X happened" broadcast OrderPlaced Producer unaware of consumers
Query "Tell me X" GetOrderStatus Synchronous, request/response

Event styles (Martin Fowler's taxonomy)

  1. Event notification: minimal payload (ID + type); consumers call back for details. Low coupling on data, but callbacks add load.
  2. Event-carried state transfer: payload includes the state consumers need. Consumers keep local copies; fewer calls, more data duplication.
  3. Event sourcing: events are the system of record (see CQRS and Event Sourcing).
flowchart LR
  O[Order service] -- OrderPlaced --> B[(Event broker<br/>Kafka / EventBridge / Pub/Sub)]
  B --> I[Inventory: reserve stock]
  B --> N[Notification: email]
  B --> A[Analytics: lakehouse]
  B --> L[Loyalty: award points]
  B --> F[Fraud: score order]

Delivery guarantees and ordering

  • At-most-once: may lose messages. Rarely acceptable for business events.
  • At-least-once: default for most brokers; consumers must be idempotent.
  • Exactly-once: achievable within certain boundaries (Kafka transactions for read-process-write within Kafka); end-to-end it means at-least-once delivery + idempotent processing.
  • Ordering: usually guaranteed only within a partition/key (Kafka partition, SQS FIFO message group, Pub/Sub ordering key). Choose the key that requires order (e.g. orderId).

Schema evolution

Events are a public contract. Use a schema registry (Confluent Schema Registry, AWS Glue Schema Registry, Apicurio) with Avro/Protobuf/JSON Schema and enforce backward-compatible changes (add optional fields; never repurpose fields). Document events with AsyncAPI.

Real-world example

When a customer places an order, the order service commits the order and an outbox row, and OrderPlaced reaches inventory, payment, notification, analytics and loyalty. Adding a new "carbon footprint" service later requires no change to the order service: it just subscribes.

Advantages and disadvantages

Advantages Disadvantages
Loose coupling, easy to add consumers Eventual consistency; harder to reason about flows
Absorbs load spikes (buffering) Debugging needs distributed tracing and event lineage
Natural audit trail and analytics feed Duplicate/out-of-order handling required
Resilience: consumers can be down temporarily Schema governance becomes critical

Technology options

Need Options
High-throughput log with replay Apache Kafka (MSK, Confluent, Event Hubs Kafka endpoint, Google Managed Kafka), Redpanda, Pulsar, Kinesis
Event routing/filtering SaaS bus Amazon EventBridge, Azure Event Grid, Google Eventarc
Pub/sub messaging Google Pub/Sub, SNS, Azure Service Bus topics
Stream processing Flink, Kafka Streams, Spark Structured Streaming, Dataflow

Architect-level considerations

[!ARCHITECT] Use events for reacting to facts and commands/RPC for requesting an outcome you need now. Do not force synchronous user flows ("show the order confirmation with payment result") through long event chains without a clear status model.

[!EA] Govern an enterprise event catalog: naming conventions, ownership, schemas, PII classification and retention per topic.

Interview questions and answers

How do you ensure consumers process events in the right order?

Partition by the entity that needs ordering (e.g. account ID), keep one consumer per partition at a time, and include sequence numbers/versions so consumers can detect and drop stale updates.

What if a consumer is down for a day?

With a durable log (Kafka retention, Pub/Sub retention, SQS up to 14 days) it catches up from its offset. Size retention for the longest expected outage and monitor consumer lag.

When is EDA a bad idea?

Simple CRUD systems, flows that need immediate consistency across steps, small teams without observability maturity, or when events are used as disguised synchronous RPC.