Event-Driven Architecture

Designing systems around events: events vs commands vs queries, the four event patterns (notification, event-carried state transfer, event sourcing, CQRS), choreography vs orchestration, topic and event design, ordering, idempotency, versioning, observability, and when not to go event-driven.

On this page

Simple definition#

In an event-driven architecture (EDA), services announce facts that happened (“PaymentAuthorised”) instead of telling other services what to do. Interested services react to those events in their own time. The producer does not know, or need to know, who is listening.

The problem#

With synchronous REST chains, every service must be up for the request to succeed. Latencies add up, and adding a new consumer means changing the caller. A checkout that calls payments, then inventory, then loyalty, then email fails if email is slow. EDA decouples in time and in knowledge, so services can scale, fail and evolve independently.

Messages: events, commands and queries#

Type Meaning Naming Coupling
Event A fact that happened; immutable Past tense: OrderPlaced Producer does not know the consumers
Command A request for one specific receiver to do something; may be refused Imperative: ReserveStock Sender knows the receiver
Query A request for data GetBalance Synchronous, usually

A common split is domain events, which stay inside a bounded context, and integration events, which form the published, versioned contract for other teams. Do not leak internal domain events as public contracts.

The four event patterns (Martin Fowler)#

Four things people mean by event-driven
flowchart TB
    EN["Event notification<br/>'OrderPlaced id=42' — consumer calls back for details"]
    ECST["Event-carried state transfer<br/>event carries the data consumers need"]
    ES["Event sourcing<br/>events ARE the system of record"]
    CQRS["CQRS<br/>separate write and read models"]
  1. Event notification: a thin event with an ID. It is simple, but consumers call back for the details, which reintroduces coupling and load.
  2. Event-carried state transfer (ECST): the event carries the data consumers need, so they keep a local copy and stay available when the producer is down. Data is duplicated and eventually consistent.
  3. Event sourcing: state is derived from an append-only sequence of events. See CQRS and event sourcing.
  4. CQRS: separate models for writes and reads, often fed by events.

Choreography vs orchestration#

Choreography Orchestration
How Each service reacts to events and emits new ones A coordinator tells each service what to do
Strengths Loose coupling, no central component Visible flow, easy to change, clear error handling
Weaknesses The flow is implicit and spread across services, so it is hard to see and debug The orchestrator is a component you must make reliable
Use when Few steps, simple reactions, broadcast facts Multi-step business processes with compensation, SLAs and audit

Most real systems mix the two: orchestrate a business process (see sagas) and choreograph notifications around it.

Designing events and topics#

Event envelope. Use a consistent envelope, for example aligned with CloudEvents (a CNCF graduated specification):

{
  "specversion": "1.0",
  "id": "8f3c2a8e-6d7b-4e39-9b58-2a1f0c3d9e11",
  "source": "payments-service",
  "type": "com.bank.payments.PaymentAuthorised.v1",
  "time": "2026-11-01T09:14:03.120Z",
  "subject": "payment/PAY-20261101-000042",
  "datacontenttype": "application/avro",
  "data": { "paymentId": "PAY-20261101-000042", "accountId": "ACC-42", "amount": "125.00", "currency": "EUR" }
}

Checklist:

  • Unique event ID for de-duplication; event time as well as processing time.
  • Key by the entity whose order matters (accountId, orderId).
  • Topic naming: <domain>.<entity>.<event>.v<major>, for example payments.payment.authorised.v1. Alternatively use one topic per aggregate stream with typed events, if consumers need cross-event order for that entity.
  • No secrets or unnecessary PII in events. Tokenise or reference sensitive data. Events are copied widely and retained.
  • Correlation and causation IDs plus W3C traceparent headers, for tracing across services.
  • Document with AsyncAPI (version 3.x) and register schemas. See Schemas and event contracts.

Reliability building blocks#

Problem Pattern
“I updated my DB but the event was lost” Transactional outbox + CDC
Duplicates from retries Idempotent consumer (processed-event table, natural keys, upserts)
Events arrive out of order Key by entity; version numbers; ignore stale versions
Poison events Retry topics plus a dead-letter topic
Multi-step business process Saga with compensations
Consumers need history Retention, compaction or an event store, plus replay

Observability for asynchronous flows#

  • Propagate trace context in headers. OpenTelemetry instrumentations for Kafka clients create producer and consumer spans linked across topics.
  • Measure end-to-end latency (event time to processed time), consumer lag, DLT rates and retry rates per consumer group.
  • Keep an event catalog: which services produce and consume which events and versions. Backstage, an EventCatalog or AsyncAPI docs can serve.

When not to use EDA#

  • When you need an immediate answer to the user (balance checks, validations): use a synchronous query.
  • For simple CRUD with one consumer: a direct call is clearer.
  • When the team cannot yet operate the platform, monitor lag or reason about eventual consistency.

Common mistakes#

Quick check#

What is the difference between an event and a command? An event is an immutable fact that already happened, and the producer does not know its consumers. A command asks one specific receiver to do something and can be refused.

What is event-carried state transfer? Events carry the data consumers need, so consumers keep local copies and do not call the producer back.

Choreography or orchestration for a 6-step payment process with refunds? Orchestration. The flow, timeouts and compensations are explicit and auditable.

Why include a unique event ID? So consumers can de-duplicate redelivered events (idempotency) and so events can be traced.

What is CloudEvents? A CNCF specification for a common event envelope (id, source, type, time and more) that works across brokers and protocols.

Summary#

  • EDA publishes immutable facts. Consumers react independently, which decouples availability, scaling and change.
  • Choose a pattern deliberately: notification, ECST, event sourcing or CQRS.
  • Orchestrate business processes; choreograph simple reactions.
  • Design events as contracts: IDs, keys, versions, schemas, no secrets, and trace context.

References#