How I Choose The Right Serverless Tool For Event-Driven Architectures
Taking a look at the 3 most popular tools: Amazon SQS vs SNS vs EventBridge.
When designing scalable event-driven systems, using one of the following services is a must:
Amazon SNS: a serverless pub/sub messaging service that lets you decouple microservices and send out notifications to multiple subscribers.
Amazon SQS: a serverless messaging queue service that allows you to decouple and scale your microservices and serverless applications. SQS is super useful for processing workloads asynchronously in a queue.
Amazon EventBridge: a serverless event bus that lets you route events from various sources to different targets based on rules you define.
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.
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:
In-app notifications such as push notifications for web and mobile apps.
Send mass emails concurrently to a list of contacts.
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 putting together a FREE email course to help you learn DynamoDB design patterns that are not taught in other courses, you can sign up here:
https://www.buildawaitlist.com/waitlist/dynamodb-course
👋 My name is Uriel Bitton and I’m committed to helping you master Serverless, Cloud Computing, and AWS.
🚀 If you want to learn how to build serverless, scalable, and resilient applications, you can also follow me on Linkedin for valuable daily posts.
Thanks for reading and see you in the next one!