SNS vs SQS vs EventBridge: Choosing the Right Serverless Tool for Event-Driven Architectures
🙌 Hello there! Welcome to The Serverless Spotlight!
In this week's edition, let's take a look at 3 of the most popular AWS services for designing event-driven architectures.
When designing scalable event-driven systems, using one of the following services is a must:
Key Differences
SNS, SQS, and EventBridge differ in their system's structure as well as their uses cases. Here are some key ways in which they behave differently and support different types of workloads.
Messages Model
SNS uses a push-based system where messages are delivered instantly to all subscribers. Subscribers can be Lambda functions or HTTP endpoints.
SQS uses a pull-based model where messages are sent to a queue and consumers can pull the messages and process them as needed.
EventBridge, similarly to SNS is push-based but has more routing and filtering options. Events are routed to a target you specify allowing for more complex event-driven workflows.
Message Filtering & Routing
SNS allows subscribers to filter messages based on its attributes but does not support complex routing.
With SQS, all messages are delivered to the queue, and does not support filtering or routing. Receivers must specify their own filtering and routing logic.
EventBridge provides the most advanced routing and filtering based on the content of the event. With EventBridge, you can create rules that route events to targets you specify based on event details.
Scalability & Throughput
SNS can support sending millions of messages per second.
SQS offers virtually unlimited message queueing for applications with high traffic.
EventBridge allows you to handle millions of events per second.
When I Use Which Service
I've built enough applications with the cloud to find a need for all three services, but like always there are one or two I'll use more consistently.
SQS
I've used SQS the most.
Perhaps due to its power, simplicity, and integration with other AWS services.
For any high-traffic or burst-potential workloads, I'll use SQS. Instead of routing requests to API Gateway or AWS Lambda, I'll pass them straight into an SQS message queue.
Recommended by LinkedIn
The requests are stored in a message queue and processed as they are received (potentially preserving their order). This offers me scalability and performance on any traffic size.
In this past month, I've used SQS a few times already in client web applications.
Recently one of my clients asked me to build him an order delivery microservice. Amongst other serverless services, I used an SQS queue to route incoming delivery requests (made on his website) to the message queue, and from there a Lambda function processes these messages as they arrive.
SNS
I tend to use SNS for two use cases mostly:
This week, one of my clients needed to send emails to a large list of contacts and the most efficient and scalable method of achieving this was for me to create an SNS topic and send out the emails to all subscribers.
EventBridge
I've mostly used EventBridge to schedule workloads using scheduled rules in combination with AWS Lambda.
Scheduled functions are simple to create and trigger at scale with Eventbridge.
A year ago, I built a small social media platform application that allowed users to schedule posts and messages.
Using EventBridge I was able to write some cron expressions and support scheduled posts and messages for every hour of the day.
Conclusion
SNS, SQS, and EventBridge all allow you to design and build scalable event-driven architectures. Choosing the right one depends on the use cases you require.
SNS is ideal for sending messages to multiple subscribers; SQS is ideal for queuing requests; EventBridge is ideal for routing events across multiple services based on rules and conditions you define.
By analyzing your applications and their needs, you can choose the right tool for the right job.
📖 P.S. I'm creating a free email course on DynamoDB that will teach you concepts and design patterns not taught in any existing course out there. Signup for free here:
👋 My name is Uriel Bitton and I hope you learned something in this edition of The Serverless Spotlight
🔗 You can share the article with your network to help others learn as well.
📬 If you want to learn how to save money in the cloud you can subscribe to my brand new newsletter The Cloud Economist.
🙌 I hope to see you in next week's edition!
Helping Businesses Grow Online with High-Converting Websites | I Create Sites That Get Results 💹💸 → Website Developer & Designer
3moThanks for sharing