SQS (Simple Queue Service) is a pull-based, load balanced messaging queue service, while SNS (Simple Notification Service) is a push-based, pub-sub messaging system. Essentially, SQS is used for decoupling and buffering messages between components, while SNS is used for sending notifications to many receivers at once.
SNS is best used for time-sensitive information delivery, like sending price alerts or breaking news to various subscribers. SQS, on the other hand, is great for tasks like processing user operations in a web app asynchronously, where each task can be processed separately and in no particular order.
Describe how to use SQS and SNS in a “fanout” pattern.
In a “fanout” pattern, SNS is used to publish a message to multiple SQS queues simultaneously. This allows multiple consumers to process the message independently. For example, you could use SNS to send a new order notification to multiple SQS queues, each handling a different aspect of the order processing pipeline.
Explain how “push notifications” work, using SNS.
SNS push notifications are sent from a server to users’ devices without a specific request from the app. The server uses SNS to send a message to the appropriate endpoints (like a mobile device, email, or HTTP endpoint), which then display the notification to the user. For example, a news app might use SNS to push breaking news notifications to users’ phones.
How might a large scale, distributed application make use of a Queue system like SQS?
A large scale, distributed application might use SQS to manage and process large numbers of messages in a scalable and reliable way. For example, an e-commerce site might use SQS to handle order processing tasks, ensuring that each order is processed in the order it was received and that no orders are lost even if individual components of the system fail.