Skip to content
advanced Phase 17 · Cloud Architecture Patterns

Event-Driven Architecture

Design event-driven systems with EventBridge, SNS, SQS, and DynamoDB Streams for decoupled, scalable event processing.

1h 5m
0 problems
Topic Progress 0%

Event Producers, Brokers, and Consumers

Event-driven architecture (EDA) is a software design pattern where the production, detection, and consumption of events drive the flow of the system. Unlike request-response architectures, EDA enables loose coupling, scalability, and responsiveness.

Event Producers are components that detect state changes and generate events. An event represents a fact that occurred in the system, such as OrderPlaced, PaymentProcessed, or UserRegistered. Events should be immutable, containing all information needed by consumers. For example, an OrderPlaced event includes order ID, customer ID, items, total amount, and timestamp. Producers should not know or care about consumers, enabling independent evolution.

Event Brokers receive events from producers and route them to appropriate consumers. Amazon EventBridge is AWS primary event broker, supporting content-based routing, event filtering, and delivery to over 30 AWS services as targets. EventBridge processes over 100 billion events monthly for AWS customers. It supports custom event buses for application-specific events and the default event bus for AWS service events.

Event Consumers subscribe to events and react accordingly. A consumer might update a database, trigger a workflow, send a notification, or invoke a Lambda function. Multiple consumers can process the same event independently. For instance, an OrderPlaced event might trigger: inventory update, shipping label generation, customer confirmation email, and analytics data collection.

Event Filtering at the broker level reduces unnecessary processing. EventBridge rules filter events based on patterns matching event content. A rule might route only OrderPlaced events with amounts exceeding $1000 to a fraud detection consumer. Content-based filtering uses exact matching, prefix matching, and numeric operators on event fields.

Dead Letter Queues handle events that fail processing. Configure DLQs on event source mappings and SQS queues to capture failed events for later investigation and reprocessing. Without DLQs, failed events are lost or retried indefinitely. Monitor DLQ depth and set alarms for unexpected growth, which indicates consumer problems.

EventBridge Pipes, Schemas, and Event Sourcing

Amazon EventBridge provides advanced features for building sophisticated event-driven architectures at scale.

EventBridge Pipes simplify the creation of event streaming pipelines. Pipes connect an event source to a target with optional filtering and transformation. Sources include SQS, SNS, Kinesis, DynamoDB Streams, and EventBridge. Targets include Lambda, Step Functions, ECS tasks, and API destinations. Pipes handle batching, retry logic, and error handling. For example, pipe DynamoDB stream changes to a Lambda function that syncs data to Elasticsearch for search indexing.

Event Schemas define the structure of events in your system. EventBridge Schema Registry stores and manages schemas for events flowing through your event bus. Developers can discover available events, understand their structure, and generate type-safe code bindings. When an event is published to an event bus, EventBridge can automatically detect the schema and add it to the registry. Generated code bindings for Java, Python, TypeScript, and C# provide strongly-typed event classes.

Event Sourcing is a pattern where state changes are stored as a sequence of events rather than just the current state. The current state is derived by replaying all events. For example, a bank account balance is calculated by replaying all debit and credit events. Event sourcing provides complete audit trails, the ability to reconstruct state at any point in time, and natural support for temporal queries.

Change Data Capture (CDC) detects and captures changes in databases, streaming them as events. AWS Database Migration Service with CDC captures database changes. DynamoDB Streams automatically captures item-level modifications. Debezium on MSK captures changes from MySQL, PostgreSQL, and other databases. For example, when a customer updates their profile, CDC captures the change and publishes a CustomerUpdated event to EventBridge.

Streaming Patterns using Amazon Kinesis and Managed Streaming for Apache Kafka (MSK) handle high-throughput event processing. Kinesis Data Streams provides real-time event streaming with sub-second latency. MSK offers Apache Kafka compatibility for event-driven architectures requiring exactly-once processing semantics. Choose streaming when you need ordered, replayable event processing with high throughput. Choose EventBridge when you need content-based routing and integration with diverse AWS services.

Quiz

1. What is the primary role of an event broker in EDA?

Question 1 options

2. What does EventBridge Schema Registry provide?

Question 2 options

3. What is the key difference between event sourcing and traditional state management?

Question 3 options

4. When should you choose Kinesis over EventBridge?

Question 4 options

Flashcards

Question

What is an event in EDA?

Answer

An immutable fact representing a state change, containing all information needed by consumers to react.

Question

What is EventBridge Pipes?

Answer

Connects event sources to targets with filtering and transformation, handling batching, retry, and error logic.

Question

What is Change Data Capture (CDC)?

Answer

Detects and captures database changes, streaming them as events for real-time cross-service consumption.

Question

When use Kinesis vs EventBridge?

Answer

Kinesis for high-throughput ordered streaming with replay. EventBridge for content-based routing with diverse AWS integrations.

Revision Notes

Key Takeaways

  • 1. EDA components: producers generate events, brokers route them, consumers react independently
  • 2. EventBridge provides content-based routing, schema registry, and Pipes for streaming pipelines
  • 3. Event sourcing stores all changes as events, enabling complete audit trails
  • 4. CDC captures database changes as events for real-time synchronization

Interview Tips

  • Explain event-driven vs request-response architectures with examples
  • Describe EventBridge content-based routing with a real scenario
  • Discuss event sourcing trade-offs: auditability vs query complexity
  • Compare Kinesis and EventBridge use cases

Cheat Sheet

EDA: Producers -> Broker (EventBridge) -> Consumers. EventBridge: filtering, schemas, Pipes, 30+ targets. Event Sourcing: store all changes, derive state by replay. CDC: database changes as events. Kinesis: high-throughput ordered streaming. DLQs for failed events.