Ace Cloud Interviews
Home/AWS Tutorial/EventBridge
📨

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.

ConceptDescriptionKey Points
Event busStream of events from a sourceDefault bus (AWS services), custom buses, partner buses
EventJSON object with source, detail-type, detail, and metadataMax 256 KB, always JSON
RuleMatches events based on pattern and routes to targetsUp to 5 targets per rule, evaluated in parallel
TargetDestination that processes the eventLambda, SQS, SNS, Step Functions, Kinesis, HTTP endpoint, etc.
Schema registryDiscovers and stores event schemasEnables code generation for strongly-typed event handling
bash
# 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 ENABLED

EventBridge 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.

DimensionEventBridgeSNSSQS
Primary useEvent routing across services, SaaS, accountsFan-out notificationsQueuing and buffering
RoutingContent-based filtering on any JSON fieldSubscription filter policies on attributesNo routing - single consumer group
SchemaBuilt-in schema registryNo schema managementNo schema management
Targets20+ native targets including cross-accountSQS, Lambda, HTTP, email, SMSOnly Lambda and EC2 consumers
Third-party sourcesNative SaaS integrations (Zendesk, Stripe, etc.)NoNo
Cross-accountResource policy on event busTopic policyQueue policy
Latency~500ms typical~10ms typicalPolling adds latency
Throughput10,000 events/sec/account (increasable)300M+ messages/secUnlimited
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.

PatternDescriptionHow EventBridge Helps
Event-driven microservicesServices publish events; other services subscribeCentral bus with per-service rules; no direct dependencies
Cross-account event routingEvents from account A processed in account BEvent bus resource policies allow cross-account sends
SaaS event integrationReact to Stripe payments, Zendesk tickets, etc.Native partner event sources - no webhook plumbing needed
Scheduled tasksReplace cron jobs with managed schedulesEventBridge Scheduler - 1 minute to years, with retry
Audit loggingLog all API calls and state changesRoute CloudTrail events to S3 via Firehose
Event replayReprocess past events after fixing a bugEvent archive + replay feature
bash
# 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.

ComponentOptionsNotes
SourceSQS, DynamoDB Streams, Kinesis, MSK, RabbitMQ, ActiveMQPolls the source automatically
FilterJSON pattern matching on event contentReduces downstream processing cost
EnrichmentLambda, Step Functions, API Gateway, EventBridge ApiDestinationOptional - transform or augment event
Target14+ targets including EventBridge bus, SQS, Lambda, Kinesis, Step FunctionsFinal 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

FeaturePriceNotes
Custom events published$1.00 per millionMost common charge
AWS service eventsFreeCloudTrail, EC2, S3 state changes
Cross-account events$1.00 per millionCharged on sending account
Schema discovery$0.10 per million eventsOnly when enabled
Event replay$0.10 per GB archivedPlus $0.023 per GB replayed
Scheduler invocations$1.00 per million scheduled invocationsFirst 14 million/month free
Pipes$0.40 per million events processedPlus 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?