Introduction
Amazon Simple Queue Service, Amazon Simple Notification Service, and Amazon EventBridge are three services that move messages and events between the parts of a system. They are commonly confused because their purposes overlap. This guide compares the three and explains when each should be used. The broader pattern of connecting components through events is covered in the guide on event-driven architecture.
What is being compared?
Amazon SQS is a queue, which is a buffer that holds messages until a consumer is ready to process them. Amazon SNS is a publish-subscribe service, in which a message that is published to a topic is delivered to every subscriber. A topic is a channel to which subscribers are attached. Amazon EventBridge is an event bus, which receives events and routes each one to the targets that its rules match.
Why the choice matters
Each service solves a different problem. Using a queue where broadcasting is required, or a broadcast where routing is required, leads to awkward designs. Understanding whether the need is to buffer work, to deliver to many consumers, or to route by content allows the correct service to be selected.
How each works
In SQS, a producer sends a message to a queue. The message is held until a consumer retrieves it, processes it, and deletes it. Only one consumer processes each message, which makes SQS suited to distributing work and absorbing bursts.
In SNS, a publisher sends a message to a topic, and SNS delivers a copy to every subscriber at once. This is the fan-out pattern, in which one message reaches many consumers.
In EventBridge, a producer sends an event to a bus. The bus evaluates its rules, which can match on the content of the event, and delivers the event to each matching target. EventBridge also receives events from many AWS services and can trigger targets on a schedule.
Comparison diagram
Where each is strongest
- SQS is strongest for decoupling a producer from a consumer and absorbing bursts of work.
- SNS is strongest for delivering one message to many consumers at once.
- EventBridge is strongest for routing events by content, integrating with many AWS services, and scheduling.
Limitations to consider
- SQS delivers each message to only one consumer, so it does not broadcast on its own.
- SNS pushes messages immediately, so a slow subscriber may need a queue in front of it to buffer.
- EventBridge adds routing rules that must be designed and maintained.
When to choose each
- SQS suits work queues, buffering, and the smoothing of traffic spikes.
- SNS suits notifications and fan-out to several consumers.
- EventBridge suits content-based routing, integration between AWS services, and scheduled actions.
Best practices
- A queue should be placed in front of a slow consumer so that bursts are absorbed.
- An SQS queue should be subscribed to an SNS topic when a broadcast message must be buffered per consumer.
- A dead-letter queue should be configured so that messages that cannot be processed are preserved.
- EventBridge rules should be written to match precisely, so that targets receive only the events they need.
Common mistakes
- SQS is used to broadcast a message to many consumers, which it does not do on its own.
- SNS is used to buffer work, when a queue is required to absorb bursts.
- EventBridge rules are written too broadly, so targets receive events they do not need.
- No dead-letter queue is configured, so failing messages are lost.
Related AWS services
- AWS Lambda is a common consumer of all three services.
- AWS Step Functions can be started by EventBridge and can send messages to a queue.
- Amazon CloudWatch records the metrics of each service.
Frequently Asked Questions
- What is the core difference between SQS, SNS, and EventBridge?
- SQS is a queue that holds messages until a consumer processes them. SNS delivers a message to many subscribers at once. EventBridge routes events to targets according to rules. One buffers, one broadcasts, and one routes.
- When should SQS be used?
- To decouple a producer from a consumer and to absorb bursts of work. Messages are held until a consumer is ready, which prevents the consumer from being overwhelmed.
- When should SNS be used?
- To deliver the same message to many subscribers at once, a pattern known as fan-out. Each subscriber receives its own copy.
- When should EventBridge be used?
- When events must be routed to different targets based on their content, when integrating with many AWS services, or when scheduling actions.
- Can they be combined?
- Yes. A common pattern places an SQS queue as a subscriber of an SNS topic, so that a broadcast message is buffered for each consumer. EventBridge can also deliver events into a queue.
This article is the summary. The book is the full, continuously updated reference: messaging patterns, fan-out, routing, error handling, and complete serverless architectures.
View the book