Pub/sub topic / event bus
Amazon SNS / Amazon EventBridge
Broadcasts each event to every subscriber, so producers don’t know who’s listening.
In a monolith
In-process events
An event dispatcher inside the app: OrderPlaced → call every registered handler, in the same process and transaction.
In a distributed system
Event fan-out between services
Services publish domain events; any number of services subscribe without the producer changing. Each subscriber usually gets its own queue.
On AWS
Amazon SNS / Amazon EventBridge
SNS: high-throughput fan-out to SQS, Lambda, HTTP, SMS, email, push. EventBridge: event bus with content-based routing rules, archive/replay and SaaS integrations.
- SNS → SQS fan-out$Each subscriber gets a durable queue
- EventBridge event bus$Rule-based routing, archive and replay
- Redis Pub/Sub (ElastiCache)$Fast fire-and-forget, no durability
- Reach for it when
- One event matters to several independent consumers (email, analytics, search indexing, fraud).
- What it costs you
- Harder to trace who reacts to what
- Event schemas become contracts — version them
- At-least-once and unordered unless you use FIFO variants
- When it dies
- Managed buses are multi-AZ. A subscriber that’s down keeps its events if it has a queue; push-only subscriptions may drop them.
Interview follow-ups
Why SNS → SQS instead of SNS → Lambda directly?
The queue buffers and retries per subscriber, so a slow or failing subscriber can’t lose events or affect the others.
Event notification vs event-carried state transfer?
Notification: “order 42 changed” (consumer calls back for details). State transfer: the event carries the data (no callback, but bigger events and duplicated data).
Connection rules
It talks to
- App server
- Service
- Worker
- Realtime server
- Queue
- Third-party APIOnly when: Managed delivery to SMS, email or mobile push endpoints (SNS).
Gets traffic from
- App server
- Service
- Worker
- Scheduler
- Realtime server
- Workflow
- Object storage
- API gatewayOnly when: AWS API Gateway service integrations (e.g. POST /events → SQS, Kinesis or EventBridge) for ingestion and webhooks — fine when there’s no business logic beyond request mapping.
- SQL databaseOnly when: A CDC connector or outbox relay tails the log and publishes — the transactional outbox pattern.
- NoSQL storeOnly when: A CDC connector or outbox relay tails the log and publishes — the transactional outbox pattern.
Never
- Pub/sub topic → SQL databaseTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → Read replicaTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → NoSQL storeTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → CacheTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → Object storageTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → SearchTopics don’t run code. A subscriber receives the event and does the write.
- Pub/sub topic → DB proxyTopics don’t run code. A subscriber receives the event and does the write.
- Clients → Pub/sub topicClients can’t be trusted to enqueue directly — there’s no validation or auth in between.