AWS Messaging & Integration
EventBridge
Serverless event bus for connecting AWS services, SaaS apps, and custom events
Amazon EventBridge is a serverless event bus that makes it easy to connect AWS services, SaaS applications, and your own applications using events. It routes events from sources to targets based on rules, enabling loosely coupled, event-driven architectures without managing infrastructure. EventBridge has largely superseded CloudWatch Events and is now the primary event routing service in the AWS ecosystem.
Event Buses, Rules, and Targets
EventBridge uses three core concepts: event buses receive events, rules filter and route events, and targets process events.
| Concept | Description | Key Points |
|---|---|---|
| Event bus | Stream of events from a source | Default bus (AWS services), custom buses, partner buses |
| Event | JSON object with source, detail-type, detail, and metadata | Max 256 KB, always JSON |
| Rule | Matches events based on pattern and routes to targets | Up to 5 targets per rule, evaluated in parallel |
| Target | Destination that processes the event | Lambda, SQS, SNS, Step Functions, Kinesis, HTTP endpoint, etc. |
| Schema registry | Discovers and stores event schemas | Enables code generation for strongly-typed event handling |
# Publish a custom event to EventBridge
aws events put-events \
--entries '[{
"Source": "com.mycompany.orders",
"DetailType": "OrderPlaced",
"Detail": "{\"orderId\":\"12345\",\"customerId\":\"67890\",\"amount\":99.99}",
"EventBusName": "my-app-bus"
}]'
# Create a rule that matches OrderPlaced events
aws events put-rule \
--name catch-order-placed \
--event-bus-name my-app-bus \
--event-pattern '{
"source": ["com.mycompany.orders"],
"detail-type": ["OrderPlaced"]
}' \
--state ENABLEDEventBridge vs SNS vs SQS: Choosing the Right Service
EventBridge, SNS, and SQS all route messages between components but serve different purposes. This is a very common interview topic.
| Dimension | EventBridge | SNS | SQS |
|---|---|---|---|
| Primary use | Event routing across services, SaaS, accounts | Fan-out notifications | Queuing and buffering |
| Routing | Content-based filtering on any JSON field | Subscription filter policies on attributes | No routing - single consumer group |
| Schema | Built-in schema registry | No schema management | No schema management |
| Targets | 20+ native targets including cross-account | SQS, Lambda, HTTP, email, SMS | Only Lambda and EC2 consumers |
| Third-party sources | Native SaaS integrations (Zendesk, Stripe, etc.) | No | No |
| Cross-account | Resource policy on event bus | Topic policy | Queue policy |
| Latency | ~500ms typical | ~10ms typical | Polling adds latency |
| Throughput | 10,000 events/sec/account (increasable) | 300M+ messages/sec | Unlimited |
| Pricing | $1 per million events published | $0.60 per million deliveries | $0.40 per million requests |
Use EventBridge when: routing based on event content, integrating with SaaS event sources, routing across AWS accounts, or working with AWS service events. Use SNS when: fan-out to many subscribers with low latency matters. Use SQS when: you need buffering, exactly-once processing, or consumer-paced processing.
Common EventBridge Patterns
EventBridge enables several powerful architecture patterns that are difficult or impossible to implement with SNS/SQS alone.
| Pattern | Description | How EventBridge Helps |
|---|---|---|
| Event-driven microservices | Services publish events; other services subscribe | Central bus with per-service rules; no direct dependencies |
| Cross-account event routing | Events from account A processed in account B | Event bus resource policies allow cross-account sends |
| SaaS event integration | React to Stripe payments, Zendesk tickets, etc. | Native partner event sources - no webhook plumbing needed |
| Scheduled tasks | Replace cron jobs with managed schedules | EventBridge Scheduler - 1 minute to years, with retry |
| Audit logging | Log all API calls and state changes | Route CloudTrail events to S3 via Firehose |
| Event replay | Reprocess past events after fixing a bug | Event archive + replay feature |
# EventBridge Scheduler - create a one-time schedule
aws scheduler create-schedule \
--name send-reminder-tomorrow \
--schedule-expression "at(2024-12-15T09:00:00)" \
--flexible-time-window '{"Mode":"OFF"}' \
--target '{
"Arn": "arn:aws:lambda:us-east-1:123:function:send-reminder",
"RoleArn": "arn:aws:iam::123:role/scheduler-role",
"Input": "{\"userId\":\"abc123\",\"message\":\"Your trial ends tomorrow\"}"
}'
# Rate-based schedule (every 15 minutes)
aws scheduler create-schedule \
--name cleanup-job \
--schedule-expression "rate(15 minutes)" \
--flexible-time-window '{"Mode":"FLEXIBLE","MaximumWindowInMinutes":5}' \
--target '{"Arn":"arn:aws:lambda:...","RoleArn":"arn:aws:iam::..."}'EventBridge Pipes: Point-to-Point Event Processing
EventBridge Pipes (launched 2022) connects sources directly to targets with optional filtering and enrichment - without writing glue code. It is the simplest way to build event processing pipelines.
| Component | Options | Notes |
|---|---|---|
| Source | SQS, DynamoDB Streams, Kinesis, MSK, RabbitMQ, ActiveMQ | Polls the source automatically |
| Filter | JSON pattern matching on event content | Reduces downstream processing cost |
| Enrichment | Lambda, Step Functions, API Gateway, EventBridge ApiDestination | Optional - transform or augment event |
| Target | 14+ targets including EventBridge bus, SQS, Lambda, Kinesis, Step Functions | Final destination |
EventBridge Pipes replaces the common pattern of SQS -> Lambda -> EventBridge with a managed pipe that does the same thing. Use Pipes when you need to move events from one service to another with optional transformation - it removes boilerplate Lambda code.
EventBridge Pricing
| Feature | Price | Notes |
|---|---|---|
| Custom events published | $1.00 per million | Most common charge |
| AWS service events | Free | CloudTrail, EC2, S3 state changes |
| Cross-account events | $1.00 per million | Charged on sending account |
| Schema discovery | $0.10 per million events | Only when enabled |
| Event replay | $0.10 per GB archived | Plus $0.023 per GB replayed |
| Scheduler invocations | $1.00 per million scheduled invocations | First 14 million/month free |
| Pipes | $0.40 per million events processed | Plus source polling costs |
At $1 per million events, EventBridge is 2.5x more expensive than SNS for raw delivery. The premium buys you content-based routing, schema registry, SaaS integrations, and cross-account routing. For pure fan-out, SNS is cheaper.
Interview Focus Points
- 1What is the difference between EventBridge, SNS, and SQS? When would you use each?
- 2How does EventBridge content-based filtering differ from SNS filter policies?
- 3How would you route events from one AWS account to another using EventBridge?
- 4What is EventBridge Scheduler and how does it differ from CloudWatch Events rate/cron expressions?
- 5How would you integrate a Stripe webhook into your AWS architecture using EventBridge?
- 6What is the EventBridge schema registry and why is it useful for teams?
- 7Explain EventBridge Pipes and how they simplify event processing pipelines.
- 8How would you implement event replay after discovering a bug in an event consumer?