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
| Term | Meaning | Example |
|---|---|---|
| Event | A fact that happened, in the past tense; the producer does not expect a specific reaction | OrderPlaced |
| Command | A request for a specific receiver to do something; it can be accepted or rejected | ShipOrder |
| Message | The technical envelope carrying an event or command through a broker | A Kafka record, an SQS message |
Martin Fowler's article What do you mean by "Event-Driven"? distinguishes several styles that are often mixed up:
| Style | Description | Trade-off |
|---|---|---|
| Event notification | The event says that something happened, with minimal data; consumers call back for details | Small events, but consumers depend on the producer's API |
| Event-carried state transfer | The event contains the relevant data, so consumers can keep their own copy | Full decoupling at runtime; data is duplicated |
| Event sourcing | The sequence of events is the system's source of truth; current state is derived from it | Complete 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:
| Concern | Practice |
|---|---|
| Contracts | Every public event has a documented schema and meaning, described with AsyncAPI and based on the enterprise data model |
| Schema registry and compatibility | Schemas are registered and versioned; compatibility rules prevent breaking changes (see schema registries) |
| Ownership | Each topic or event type has an owning team and system, recorded in the catalog and the systems inventory |
| Discovery | Event catalogs list available events, their schemas, owners and consumers |
| Access control | Producers and consumers are authenticated; who may publish and who may read is authorized per topic, like API scopes (see identity and access management) |
| Data protection | Events are classified; personal data is minimized, masked or encrypted; retention follows privacy rules |
| Standards | Common envelope and metadata (for example CloudEvents), naming conventions, identifiers and time formats |
| Observability | Throughput, 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) events | Private (within a system boundary) events | |
|---|---|---|
| Purpose | Integration between systems and domains | Internal communication between components of one system, owned by one team |
| Consumers | Other teams, possibly unknown in advance | Only the owning team's own components |
| Model | Canonical, business-level: sales.order-placed.v1 | Internal technical model, free to reflect implementation details |
| Change | Versioned, backward compatible, announced, with migration periods | Changed freely by the owning team |
| Governance | Full contract governance: schema registry, catalog, review, access control | Team-level practices; not exposed to other teams |
| DDD analogy | Published language / open host service | Internal 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.
| Engine | Characteristics |
|---|---|
| Apache Flink | Powerful, stateful stream processing with event-time semantics; SQL and programmatic APIs |
| Kafka Streams | A library for stream processing inside Java applications, tightly integrated with Kafka |
| Spark Structured Streaming | Streaming on the Spark engine, convenient when Spark is already used for the data lake |
| Streaming databases such as RisingWave and Materialize | Define continuously updated results with SQL |
Aggregation and windowing
Streams are unbounded, so aggregations are calculated over windows:
| Window type | Description | Example |
|---|---|---|
| Tumbling | Fixed, non-overlapping intervals | Orders per minute |
| Sliding / hopping | Fixed-size windows that overlap | Revenue in the last hour, updated every minute |
| Session | Periods of activity separated by gaps of inactivity | Actions 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.
| Platform | Model | Characteristics | Typical use |
|---|---|---|---|
| Apache Kafka | Distributed log | Partitioned 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 log | Kafka without operating the clusters | Same as Kafka, with less operations |
| Amazon SNS | Pub/sub (push) | Fan-out of each message to many subscribers (SQS, Lambda, HTTP, email); no long-term storage | Notifications, fan-out to multiple consumers |
| Amazon SQS | Queue | Each message processed by one consumer; standard queues for scale, FIFO queues for ordering; messages retained for a limited time | Work queues, decoupling and buffering between services |
| Amazon EventBridge | Event bus | Content-based routing rules, schema discovery, integration with AWS services and SaaS | Event routing between applications and services on AWS |
| Amazon Kinesis Data Streams | Stream | Managed, shard-based streaming with retention and replay | Streaming data on AWS |
| Google Pub/Sub | Pub/sub | Global, managed messaging with retention options | Event distribution on Google Cloud |
| Azure Service Bus | Queues and topics | Enterprise messaging with transactions, sessions and dead-lettering | Business messaging on Azure |
| RabbitMQ (open source) | Broker (AMQP), also streams | Flexible routing with exchanges, mature and widely used | Task queues, routing-heavy messaging |
| Apache Pulsar (open source) | Log with queue semantics | Multi-tenancy, geo-replication, tiered storage; both streaming and queueing | Multi-tenant event platforms |
| NATS with JetStream (open source) | Lightweight messaging, optional persistence | Very simple and fast; JetStream adds storage and replay | Edge, IoT, lightweight service messaging |
| Redpanda | Distributed log (Kafka API–compatible) | Kafka-compatible, implemented without the JVM, single binary | Kafka workloads with simpler operations |
| Apache ActiveMQ (open source) | Broker (JMS, AMQP) | Long-established Java messaging | Existing 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.