Skip to main content

Event-Driven Architecture

In an event-driven architecture (EDA), systems communicate by publishing events, records of facts that happened, such as OrderPlaced, CustomerAddressChanged or PaymentFailed, and by reacting to events published by others. The producer does not need to know who consumes its events; consumers subscribe to the events they are interested in.

Event-driven architecture has become the backbone of modern enterprise data flows. The same stream of business events feeds other services, the data lake, search indexes, analytics, monitoring and AI applications, in near real time. It allows systems to be loosely coupled: producers and consumers evolve, scale and fail independently, and new consumers can be added without changing the producer.

Events, commands and messages​

TermMeaningExample
EventA fact that happened, in the past tense; the producer does not expect a specific reactionOrderPlaced
CommandA request for a specific receiver to do something; it can be accepted or rejectedShipOrder
MessageThe technical envelope carrying an event or command through a brokerA Kafka record, an SQS message

Martin Fowler's article What do you mean by "Event-Driven"? distinguishes several styles that are often mixed up:

StyleDescriptionTrade-off
Event notificationThe event says that something happened, with minimal data; consumers call back for detailsSmall events, but consumers depend on the producer's API
Event-carried state transferThe event contains the relevant data, so consumers can keep their own copyFull decoupling at runtime; data is duplicated
Event sourcingThe sequence of events is the system's source of truth; current state is derived from itComplete history and audit; more complex to build

Related patterns include CQRS (separating the write model from read models built from events) and sagas (coordinating a business process across services through events).

Govern events like APIs​

Events are interfaces. A published event is a contract, just like a REST API: other teams build on its structure and meaning, and changing it carelessly breaks them. Event streams deserve the same governance as API access:

ConcernPractice
ContractsEvery public event has a documented schema and meaning, described with AsyncAPI and based on the enterprise data model
Schema registry and compatibilitySchemas are registered and versioned; compatibility rules prevent breaking changes (see schema registries)
OwnershipEach topic or event type has an owning team and system, recorded in the catalog and the systems inventory
DiscoveryEvent catalogs list available events, their schemas, owners and consumers
Access controlProducers and consumers are authenticated; who may publish and who may read is authorized per topic, like API scopes (see identity and access management)
Data protectionEvents are classified; personal data is minimized, masked or encrypted; retention follows privacy rules
StandardsCommon envelope and metadata (for example CloudEvents), naming conventions, identifiers and time formats
ObservabilityThroughput, consumer lag, errors and dead-letter queues monitored per topic (see observability)

Public contracts and private exchanges​

Not every event needs the same level of governance. The key distinction is whether the event crosses a boundary:

Public (cross-system, cross-domain) eventsPrivate (within a system boundary) events
PurposeIntegration between systems and domainsInternal communication between components of one system, owned by one team
ConsumersOther teams, possibly unknown in advanceOnly the owning team's own components
ModelCanonical, business-level: sales.order-placed.v1Internal technical model, free to reflect implementation details
ChangeVersioned, backward compatible, announced, with migration periodsChanged freely by the owning team
GovernanceFull contract governance: schema registry, catalog, review, access controlTeam-level practices; not exposed to other teams
DDD analogyPublished language / open host serviceInternal model of a bounded context

This mirrors the difference between a public API and internal method calls. Private events let a team move fast inside its own boundary; public events give other teams something stable to depend on. A common problem is private events leaking: other teams start consuming an internal topic, and the owning team can no longer change it. Prevent this with access control on private topics and clear naming conventions, and offer a proper public event instead.

Typical change data capture streams are a special case: they mirror a database's internal tables, so they are private by nature. Publishing them directly as cross-domain contracts couples consumers to the producer's database schema. Transform them into public business events first, or use the outbox pattern (see below).

Key mechanisms​

Change data capture (CDC)​

Change data capture reads changes from a database's transaction log and publishes them as events, without modifying the source application. It is the standard way to get events out of systems that cannot publish them themselves, especially legacy systems. Debezium is the most widely used open source CDC platform (see also the article on Change Data Capture and Debezium).

The transactional outbox pattern combines both worlds: the application writes a business event into an outbox table in the same transaction as its data change, and CDC publishes the outbox rows as public events. This guarantees that data changes and events never get out of sync, and the published event has a deliberate, business-level design.

Data transformation​

Events often need to change shape on their way to consumers:

  • Format conversion: for example JSON to Avro.
  • Mapping: from a source system's internal model to the canonical model, in an anti-corruption layer.
  • Filtering and routing: sending only relevant events to each consumer.
  • Enrichment: adding reference data, such as customer segment or product category.
  • Masking: removing or pseudonymizing personal data before events leave a trusted boundary.

Simple transformations can run in connectors (for example Kafka Connect single message transforms) or routing rules; complex ones in stream processing jobs.

Stream processing​

Stream processing applies continuous computations to events as they arrive, instead of processing stored data in batches. Typical uses are real-time transformations, joins between streams, fraud and anomaly detection, and maintaining live aggregates.

EngineCharacteristics
Apache FlinkPowerful, stateful stream processing with event-time semantics; SQL and programmatic APIs
Kafka StreamsA library for stream processing inside Java applications, tightly integrated with Kafka
Spark Structured StreamingStreaming on the Spark engine, convenient when Spark is already used for the data lake
Streaming databases such as RisingWave and MaterializeDefine continuously updated results with SQL

Aggregation and windowing​

Streams are unbounded, so aggregations are calculated over windows:

Window typeDescriptionExample
TumblingFixed, non-overlapping intervalsOrders per minute
Sliding / hoppingFixed-size windows that overlapRevenue in the last hour, updated every minute
SessionPeriods of activity separated by gaps of inactivityActions per user visit

Real-world events arrive late and out of order, so stream processors distinguish event time (when it happened) from processing time (when it arrived) and use watermarks to decide when a window is complete.

Materialization​

Materialization turns a stream of events into a current state that can be queried: for example, a table with the latest status of every order, or a customer's current address. Materialized views are maintained continuously by stream processors or streaming databases, and serve as read models (CQRS), caches, search indexes or silver tables in the data lake. They let consumers query current state without calling the producer.

Compaction and retention​

Brokers that store events need rules for how long to keep them:

  • Time- or size-based retention: events are deleted after a period or when a size limit is reached.
  • Log compaction: for keyed events, the broker keeps at least the latest event per key and removes older ones. A compacted topic acts as a durable, replayable snapshot of current state, for example the latest record of every customer. New consumers can rebuild the full current state by reading it from the beginning. Kafka supports this natively (see the Kafka documentation).
  • Tiered storage: older data is moved to cheaper object storage while staying readable.

Delivery guarantees and ordering​

  • Delivery semantics: at most once (may lose events), at least once (may deliver duplicates, the most common), and exactly once (supported within certain platforms and processing frameworks). In practice, consumers should be idempotent, handling duplicates safely.
  • Ordering: usually guaranteed only within a partition or message group. Events that must stay in order, such as all events of one order, share a key.
  • Error handling: events that repeatedly fail go to a dead-letter queue for investigation, instead of blocking the stream.
  • Replay: platforms with retention allow consumers to re-read past events, for example to rebuild a read model or recover from a bug.

Message brokers and streaming platforms​

Brokers fall into two broad families: queues and pub/sub services, which deliver messages and then forget them, and log-based streaming platforms, which store events durably so they can be replayed.

PlatformModelCharacteristicsTypical use
Apache KafkaDistributed logPartitioned topics, high throughput, configurable retention, replay, log compaction, large ecosystem (Connect, Streams, schema registries)Enterprise event backbone, CDC, data streaming
Managed Kafka: Confluent Cloud, Amazon MSK, Azure Event Hubs (Kafka API)Distributed logKafka without operating the clustersSame as Kafka, with less operations
Amazon SNSPub/sub (push)Fan-out of each message to many subscribers (SQS, Lambda, HTTP, email); no long-term storageNotifications, fan-out to multiple consumers
Amazon SQSQueueEach message processed by one consumer; standard queues for scale, FIFO queues for ordering; messages retained for a limited timeWork queues, decoupling and buffering between services
Amazon EventBridgeEvent busContent-based routing rules, schema discovery, integration with AWS services and SaaSEvent routing between applications and services on AWS
Amazon Kinesis Data StreamsStreamManaged, shard-based streaming with retention and replayStreaming data on AWS
Google Pub/SubPub/subGlobal, managed messaging with retention optionsEvent distribution on Google Cloud
Azure Service BusQueues and topicsEnterprise messaging with transactions, sessions and dead-letteringBusiness messaging on Azure
RabbitMQ (open source)Broker (AMQP), also streamsFlexible routing with exchanges, mature and widely usedTask queues, routing-heavy messaging
Apache Pulsar (open source)Log with queue semanticsMulti-tenancy, geo-replication, tiered storage; both streaming and queueingMulti-tenant event platforms
NATS with JetStream (open source)Lightweight messaging, optional persistenceVery simple and fast; JetStream adds storage and replayEdge, IoT, lightweight service messaging
RedpandaDistributed log (Kafka API–compatible)Kafka-compatible, implemented without the JVM, single binaryKafka workloads with simpler operations
Apache ActiveMQ (open source)Broker (JMS, AMQP)Long-established Java messagingExisting Java enterprise integrations

A common AWS pattern combines both families: an SNS topic fans out to several SQS queues, one per consumer, so each consumer processes events at its own pace with its own retries (SNS to SQS fan-out). For an enterprise-wide event backbone with replay, long retention and stream processing, a log-based platform such as Kafka is the more common choice.

Choosing​

  • Do consumers need to replay history, or join streams? Choose a log-based platform (Kafka, Pulsar, Kinesis).
  • Is it work distribution between instances of one service? A queue (SQS, RabbitMQ, Service Bus) is simpler.
  • Fan-out of notifications to a few known consumers? Pub/sub (SNS, EventBridge, Pub/Sub).
  • Limit the number of platforms, and record the choices in the technology radar. Each additional broker means more operations, skills and governance.

Common pitfalls​

  • Event spaghetti: many events with no catalog, owners or contracts, so nobody understands the flows.
  • CDC streams as public contracts: consumers coupled to another system's database schema.
  • Leaking private events: other teams consuming internal topics, freezing the owner's design.
  • Events as remote procedure calls: using events where an immediate answer is needed, then building fragile request–reply logic on top.
  • Assuming exactly-once and global ordering: consumers that break on duplicates or out-of-order events.
  • No dead-letter handling: one bad event blocks a consumer or is silently lost.
  • Personal data everywhere: sensitive fields copied into events and retained far longer than allowed.