Dev tools
Event Driven Architecture: A Plain Guide
Event driven architecture explained: producers, brokers and consumers, the main patterns, event driven architecture examples, pros, cons and when to use it
Event driven architecture is a way of designing software where services communicate by publishing events, short records of something that happened, such as "order placed" or "payment failed," instead of calling each other directly. A producer announces the event, a broker or event channel carries it, and any number of consumers react to it on their own schedule. The result is loosely coupled systems that scale and evolve independently, at the cost of eventual consistency and harder debugging.
This plain guide explains what is event driven architecture in more detail, what is an event in event driven architecture, how it works, the main patterns, a step-by-step event driven architecture example, event driven architecture vs REST API calls, the tools people use, the benefits and challenges, and a checklist for when it's the right choice.
What Is Event Driven Architecture?
Microsoft's Azure Architecture Center describes the structure in three parts:
- Event producers generate events when something changes.
- Event channels, often an event broker or ingestion service, transfer events from producers to consumers.
- Event consumers listen for events and react: updating a database, sending an email, starting a workflow, or publishing new events of their own.
The defining feature is decoupling. A producer doesn't know which consumers exist or what they'll do. You can add a new consumer, say a fraud check or an analytics pipeline, without changing the producer at all.
What Is an Event in Event Driven Architecture?
An event is a record of something that already happened, at a certain time: "Customer 4812 changed their email," "Sensor 9 reported 81°C," "Invoice 330 was paid." Three properties make events different from ordinary messages:
- They describe the past. An event states a fact; it doesn't ask anyone to do anything. That's what separates an event from a command such as "send this email."
- They are immutable. You never edit an event after publishing it. If something changes again, you publish a new event.
- They have no single recipient. The producer publishes once, and every interested consumer gets it, including consumers added years later.
In practice, an event is a small message, usually JSON, with a type such as OrderPlaced, a unique ID, a timestamp, the source that produced it, and a payload with the relevant data or just the IDs consumers need to look it up.
How Event Driven Architecture Works
Two delivery models dominate, and Microsoft's guide distinguishes them clearly:
| Publish-subscribe | Event streaming | |
|---|---|---|
| How it works | The broker tracks subscriptions and sends each event to every subscriber | Events are written to a durable, ordered log; consumers read from any position |
| After delivery | The event isn't kept, so new subscribers don't see past events | Events stay for the retention period; consumers can replay |
| Ordering | Usually not guaranteed across subscribers | Strict within a partition |
| Typical tools | Amazon SNS and EventBridge, Azure Event Grid, Google Cloud Pub/Sub, RabbitMQ fanout exchanges | Apache Kafka, Amazon Kinesis, Azure Event Hubs, Redpanda |
| Best for | Notifications and reactions to events as they happen | Data pipelines, analytics, replay and late-joining consumers |
On the consumer side, processing ranges from simple to complex:
- Simple event processing: an event immediately triggers an action, like a serverless function sending a receipt.
- Event correlation: a consumer remembers earlier events and combines them by an ID, for example waiting for both "payment received" and "stock reserved" before shipping.
- Complex event processing: detecting patterns across many events, such as a moving average crossing a threshold.
- Event stream processing: continuous pipelines that transform and route streams, common in IoT and analytics.
Event Driven Architecture Patterns
Martin Fowler pointed out in his article "What do you mean by Event-Driven?" that people use the term for four quite different patterns. Knowing which one you mean avoids a lot of confusion.
| Pattern | What the event carries | Strength | Trade-off |
|---|---|---|---|
| Event notification | Just the fact that something changed, often with an ID | Very low coupling; easy to add consumers | The overall flow isn't visible in any one place in the code |
| Event-carried state transfer | The changed data itself | Consumers keep local copies and don't call the source; more resilient | Duplicated data and more logic on the receiver |
| Event sourcing | Every state change, stored as the source of truth | Full audit trail; rebuild past state; replay | Harder schema changes and replays involving outside systems |
| CQRS (command query responsibility segregation) | Separate models for writes and reads, often fed by events | Read models tuned for queries | Extra complexity; not strictly about events |
Two topologies sit on top of these patterns:
- Broker topology (choreography): components broadcast events and others react, with no central coordinator. It's highly decoupled and scalable, but no component owns the state of a multi-step business process, so error handling needs careful design.
- Mediator topology (orchestration): a central orchestrator receives events and sends commands to specific services, tracking the state of each process. It gives more control and better error handling at the cost of coupling and a potential bottleneck. The saga pattern, which coordinates multi-step transactions with compensating actions when a step fails, can use either style.
Event Driven Architecture Example: An Online Order
Here's an event driven architecture example step by step, for an online store:
- Checkout saves the order and publishes
OrderPlacedwith the order ID, customer ID, items and total. - Payments consumes
OrderPlaced, charges the card and publishesPaymentSucceededorPaymentFailed. - Inventory consumes
OrderPlaced, reserves stock and publishesStockReservedorOutOfStock. - Shipping waits for both
PaymentSucceededandStockReservedfor the same order (event correlation), then creates a shipment and publishesOrderShipped. - Notifications consumes
PaymentSucceededandOrderShippedand emails the customer. - Analytics consumes everything into a data warehouse.
- If payment fails, Inventory consumes
PaymentFailedand releases the reserved stock: a compensating action.
None of these services call each other. Adding a loyalty-points service next month means subscribing to PaymentSucceeded; nothing else changes.
A well-structured event, using the CloudEvents format, looks like this:
{
"specversion": "1.0",
"id": "a3f1c2e0-7b1d-4c8e-9a51-2f6d1c0b9e77",
"source": "/checkout",
"type": "com.example.order.placed",
"time": "2026-11-22T09:15:00Z",
"datacontenttype": "application/json",
"data": { "orderId": "981", "customerId": "4812", "total": 42.50 }
}CloudEvents is a CNCF specification for describing events in a common way; it graduated in the CNCF in January 2024. It requires four attributes, id, source, specversion and type, and the spec says producers must ensure source plus id is unique for each distinct event, which consumers can use to detect duplicates.
Event Driven Architecture vs REST API Calls
In a request driven (request-response) design, such as one service calling another's REST API, a service calls another and waits for the answer, usually over REST or gRPC. In an event driven design, a service announces what happened and moves on.
| Request driven | Event driven | |
|---|---|---|
| Communication | Synchronous call and response | Asynchronous publish and react |
| Coupling | Caller knows the callee and its API | Producer doesn't know who consumes |
| Failure impact | If the callee is down, the caller fails or waits | Events wait in the broker until consumers recover |
| Consistency | Immediate, within the call | Eventual: services catch up over time |
| Adding new behavior | Change the caller to make another call | Add a new consumer |
| Debugging | Follow one call stack | Trace events across services with correlation IDs |
| Best for | Queries and actions needing an immediate answer | Workflows, notifications, integrations, pipelines |
Most real systems use both: synchronous APIs for reads and actions the user waits on, events for everything that can happen afterward. Our comparison of webhook vs API covers one common way events cross company boundaries.
Event Driven Architecture Tools
| Category | Examples | Use |
|---|---|---|
| Event streaming platforms | Apache Kafka, Redpanda, Amazon Kinesis, Azure Event Hubs | High-volume, replayable event logs |
| Message brokers | RabbitMQ, ActiveMQ, NATS | Routing and queuing events and commands |
| Cloud event routers | Amazon EventBridge, Azure Event Grid, Google Eventarc | Routing events between cloud services and SaaS apps |
| Cloud pub/sub | Amazon SNS, Google Cloud Pub/Sub | Fan-out to many subscribers |
| Standards | CloudEvents (event format), AsyncAPI (describing event APIs) | Interoperability and documentation |
| Workflow and orchestration | Temporal, AWS Step Functions | Coordinating long-running, multi-step processes |
Choosing between a broker and a log is often the first decision. Our guides to the message queue and Kafka vs RabbitMQ cover that choice in depth.
How to Design Good Events
Events are a contract between teams, so design them as carefully as an API.
- Name them in the past tense, after business facts:
OrderPlaced,InvoicePaid,SubscriptionCancelled. Events describe what happened; commands likeShipOrderask for something to happen and usually go to one specific service. - Decide how much data to include. Microsoft's guide describes two approaches. Putting all needed attributes in the payload lets consumers act without querying anything, but larger events cost more bandwidth, duplicate data across systems and make versioning harder. Putting only keys in the payload keeps one system of record and simpler contracts, but every consumer has to query the source for details. Many teams include the key fields most consumers need and an ID for the rest.
- Include metadata: a unique event ID, the time it happened, the source, the event type and version, and a correlation ID that ties related events together.
- Version deliberately: add optional fields rather than renaming or removing them, and publish a new event type when the meaning changes.
- Document event APIs: the AsyncAPI specification does for events what OpenAPI does for REST endpoints, listing channels, message formats and examples.
Testing Event Driven Systems
Testing changes when services don't call each other directly.
- Unit test handlers with sample events, including duplicates and out-of-order arrivals.
- Contract test event schemas so a producer can't publish a change that breaks known consumers.
- Integration test with a real broker running locally or in a test environment, checking that events flow end to end and land in the right state.
- Test failure paths: consumer crashes mid-processing, broker restarts, poison messages that should end up in a dead-letter queue.
- Assert eventually, not immediately: wait for the expected state with a timeout instead of checking right after publishing.
Event Driven Architecture and AI Systems
Events fit AI workloads well because model calls are slow, expensive and fail more often than ordinary functions. A support ticket created in a help desk can publish an event that triggers an AI classifier, which publishes TicketClassified for routing; a document upload can trigger embedding and indexing for retrieval; an AI agent can subscribe to events from business systems and act when something happens, rather than polling. Queuing model work behind events also smooths spikes and makes retries and rate limits easier to manage.
Benefits of Event Driven Architecture
- Loose coupling: services evolve, deploy and scale independently.
- Easy extension: new consumers plug in without touching producers.
- Resilience: if a consumer is down, events wait; the producer keeps working.
- Real-time reactions: consumers act as soon as events occur.
- Scalability: consumers scale horizontally to match event volume.
- Audit and replay: with event streaming or event sourcing, you keep a history you can reprocess after a bug fix or to build a new feature.
Challenges and How to Handle Them
| Challenge | Why it happens | How to handle it |
|---|---|---|
| Eventual consistency | Consumers update at their own pace | Design user interfaces and reads to tolerate brief staleness; use synchronous calls where strong consistency is essential |
| Duplicate events | Most brokers deliver at least once | Make consumers idempotent; use event IDs to skip duplicates |
| Ordering | Parallel consumers process events out of order | Partition by a key such as order ID; include sequence numbers or versions |
| Lost events at publish time | The database write succeeds but the publish fails, or the reverse | Use the transactional outbox pattern: write the event to an outbox table in the same transaction, then publish from there |
| Error handling | No caller waits to handle the failure | Retries with backoff, dead-letter queues, compensating actions |
| Observability | One business transaction spans many services | Put a correlation ID in every event and use distributed tracing |
| Schema evolution | Producers and consumers deploy separately | Version events, only add optional fields, use a schema registry |
| Event overload | Too many fine-grained events | Publish meaningful business events, not every database change |
| Data exposure | Events are visible to many components | Leave sensitive data out of events or encrypt it |
When to Use Event Driven Architecture
Microsoft's architecture guide lists conditions where the style fits, and where it doesn't. Turned into a checklist:
Good fit when:
- Several subsystems must react to the same events.
- You need near real-time processing.
- You need pattern detection or aggregation over time windows.
- Event volume and speed are high, such as IoT or clickstreams.
- Teams need to deploy and scale producers and consumers independently.
Poor fit when:
- Workflows are simple request-response and synchronous calls meet your needs.
- Business transactions require strong consistency across services at every moment.
- Your team has no experience running distributed, asynchronous systems; debugging, monitoring and recovery work very differently.
A practical path: start with a well-structured application that uses synchronous calls, and introduce events where they clearly help, such as sending notifications, syncing data to analytics, or integrating a new service without touching existing ones.
Common Mistakes
- Using events for everything. Queries that need an answer now belong in an API call.
- Publishing database changes instead of business events.
RowUpdatedtells consumers little;OrderCancelledtells them what happened. - Ignoring duplicates and order. Assume both will happen.
- Skipping the outbox. Saving data and publishing an event as two separate steps eventually loses one of them.
- No correlation IDs. Without them, tracing a failed order across five services is guesswork.
- Breaking event schemas. Removing or renaming fields breaks consumers you may not know exist.
FAQ
What is event driven architecture in simple terms?
It's a design where parts of a system tell each other when something happens, by publishing events, instead of calling each other and waiting. Other parts listen and react in their own time.
What is an example of event driven architecture?
An online store where checkout publishes "order placed," and separate services for payments, inventory, shipping, email and analytics each react to it, without checkout calling any of them directly.
Is Kafka an event driven architecture?
Kafka is a tool, not an architecture. It's an event streaming platform that is commonly used as the event channel in an event driven architecture, especially when you need durable, replayable event streams.
What is the difference between event driven and microservices?
Microservices describes how you split an application into small, independently deployed services. Event driven architecture describes how components communicate. Many microservice systems use events, but microservices can also talk through synchronous APIs.
What are the disadvantages of event driven architecture?
Eventual consistency, duplicate and out-of-order events, harder debugging across services, schema evolution and the operational work of running brokers. Good practices like idempotent consumers, correlation IDs and the outbox pattern handle most of them.