Mastering Event-Driven Architectures: Fan-out, Streaming, and Queuing
Event-driven architectures (for example, fan out, event streaming, queuing)
Mastering Event-Driven Architectures: Fan-out, Streaming, and Queuing
This study guide covers the core patterns of event-driven architectures (EDA) within the AWS ecosystem, specifically focusing on how to decouple services to improve scalability, reliability, and responsiveness as required for the AWS Certified DevOps Engineer - Professional (DOP-C02) exam.
Learning Objectives
After studying this guide, you should be able to:
- Differentiate between queuing (SQS), pub-sub (SNS), and streaming (Kinesis) use cases.
- Architect a fan-out pattern to trigger multiple downstream actions from a single event.
- Configure EventBridge to route events based on specific JSON patterns.
- Design resilient workflows using Lambda and Step Functions in response to AWS Health or CloudTrail events.
Key Terms & Glossary
- Decoupling: The practice of ensuring that the components of a system can operate independently without needing to know the implementation details of others.
- Fan-out: A design pattern where a single message is sent to a central topic and then replicated to multiple destinations (e.g., SNS to multiple SQS queues).
- Idempotency: The property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.
- Producer: A service or application that generates events or messages (e.g., S3, CloudTrail).
- Consumer/Subscriber: A service that receives and processes events (e.g., AWS Lambda, SQS, EC2).
- Dead Letter Queue (DLQ): A specialized SQS queue used to store messages that cannot be processed successfully after a certain number of attempts.
The "Big Idea"
In traditional monolithic architectures, components are tightly coupled via synchronous APIs. If one service fails, the entire chain breaks. Event-Driven Architecture (EDA) flips this: services communicate via asynchronous "events." This allows systems to be highly responsive and infinitely scalable, as the producer of an event doesn't care who consumes it or when—they just emit the fact that "something happened."
Formula / Concept Box
| Feature | Amazon SNS | Amazon SQS | Amazon Kinesis |
|---|---|---|---|
| Core Model | Pub/Sub (Push) | Queuing (Pull/Poll) | Streaming (Pull) |
| Persistence | None (Immediate delivery) | Up to 14 days | Up to 365 days |
| Consumers | Multiple (Fan-out) | One (per message) | Multiple (Parallel shards) |
| Ordering | FIFO available | FIFO available | Strict per shard |
Hierarchical Outline
- Event Sources
- State Changes: S3 Object Created, RDS Instance Rebooted.
- Monitoring/Audit: CloudTrail API calls, CloudWatch Alarms.
- External/Health: AWS Health events, Third-party SaaS (via EventBridge).
- Event Routers & Hubs
- Amazon EventBridge: Rule-based routing for system-wide events.
- Amazon SNS: High-throughput fan-out for notifications.
- Message Buffers & Queues
- Amazon SQS: Decouples producers from consumers with asynchronous processing.
- Amazon Kinesis: High-volume data ingestion and real-time analytics.
- Event Processors
- AWS Lambda: Serverless compute triggered by events.
- AWS Step Functions: Orchestrates complex, multi-step event workflows.
Visual Anchors
Fan-out Pattern Architecture
This diagram demonstrates how a single event (e.g., an S3 upload) can trigger multiple independent workflows.
Queue vs. Stream Logic
This TikZ diagram visualizes the difference between a Queue (where items are removed once read) and a Stream (a rolling log where items persist).
Definition-Example Pairs
- Message Filtering: A subscriber policy that allows them to receive only a subset of messages based on attributes.
- Example: An SNS topic receives "Order" messages. A "Shipping" service filters for messages where
status == 'paid', while a "Marketing" service filters foramount > 1000.
- Example: An SNS topic receives "Order" messages. A "Shipping" service filters for messages where
- Event Pattern: A JSON object in EventBridge used to match incoming events.
- Example: A pattern that matches only
aws.ec2events where thedetail-typeisEC2 Instance State-change Notificationand the state isrunning.
- Example: A pattern that matches only
- Dead Letter Queue (DLQ): A target for messages that cannot be processed.
- Example: If a Lambda function fails to process an SQS message 5 times because of a database timeout, SQS moves that message to a DLQ for manual inspection.
Worked Example: Automating Incident Response
Problem: A DevOps engineer needs to automatically isolate an EC2 instance if it fails an AWS Config compliance check.
Solution Steps:
- Event Source: AWS Config detects a non-compliant resource (e.g., SSH port 22 open to the world).
- Router: Amazon EventBridge captures the
Config Rules Compliance Changeevent. - Filter: Create an EventBridge Rule with a pattern matching
"complianceType": ["NON_COMPLIANT"]for the specific rule ID. - Target: The rule triggers an AWS Lambda function.
- Action: The Lambda function uses the AWS SDK to modify the instance's Security Group to remove the open port and tags the instance for investigation.
- Notification: Lambda also publishes a message to an SNS Topic to alert the security team via email.
Checkpoint Questions
- What is the main difference between the "Push" model of SNS and the "Pull" model of SQS?
- Why would you use Kinesis Data Streams instead of SQS for a real-time leaderboard application?
- How does the Fan-out pattern help in creating a decoupled architecture?
- Which AWS service is best suited for routing events between different AWS accounts or third-party SaaS applications?
Muddy Points & Cross-Refs
- SNS vs. EventBridge: It's often confusing when to use which.
- Rule of Thumb: Use SNS for high-throughput (millions of msgs/sec) and simple pub-sub. Use EventBridge for complex JSON pattern matching and connecting many AWS services together without custom code.
- Visibility Timeout: In SQS, if this is too short, a consumer might not finish processing before the message becomes visible again, leading to duplicate processing. Cross-ref: Distributed Systems Idempotency Patterns.
- Kinesis Sharding: Understanding how to scale Kinesis by adding shards is a common professional exam topic. Cross-ref: Unit 4: Monitoring and Logging for Kinesis Data Firehose.
Comparison Tables
| Attribute | Standard SQS | FIFO SQS |
|---|---|---|
| Ordering | Best-effort | First-In-First-Out (Strict) |
| Delivery | At-least-once | Exactly-once |
| Throughput | Nearly unlimited | Up to 3,000 msgs/sec (with batching) |
| Use Case | Decoupling generic tasks | Financial transactions, inventory updates |