AWS: Events

My reading notes for Code Fellows


AWS: Events

AWS SQS vs SNS

What is the difference betweeen SQS and SNS?

SNS is a distributed publish-subscribe service. Messages are pushed to subscribers as and when they are sent by publishers to SNS.

SQS is distributed queuing service. Messages are not pushed to receivers. Receivers have to poll SQS to receive messages.

Key Differences

Entity Type SQS : Queue (similar to JMS, MSMQ). SNS : Topic-Subscriber (Pub/Sub system).

Message consumption SQS : Pull Mechanism — Consumers poll messages from SQS. SNS : Push Mechanism — SNS pushes messages to consumers.

Persistence SQS : Messages are persisted for some duration is no consumer available. The retention period value is from 1 minute to 14 days. The default is 4 days. SNS : No persistence. Whichever consumer is present at the time of message arrival, get the message and the message is deleted. If no consumers available then the message is lost.

In SQS the message delivery is guaranteed but in SNS it is not.

Consumer Type SQS : All the consumers are supposed to be identical and hence process the messages in exact same way. SNS : All the consumers are (supposed to be) processing the messages in different ways.

What are some use cases for both SNS and SQS?

Choose SNS if:

You would like to be able to publish and consume batches of messages. You would like to allow same message to be processed in multiple ways. Multiple subscribers are needed.

Choose SQS if:

You need a simple queue with no particular additional requirements. Decoupling two applications and allowing parallel asynchronous processing. Only one subscriber is needed.

AWS SNS and SQS

Describe how to use SQS and SNS in a “fanout” pattern.

One can design fanout pattern by using both SNS and SQS. In this pattern, a message published to an SNS topic is distributed to multiple SQS queues in parallel.

Explain how “push notifications” work, using SNS. Messages are pushed to subscribers as and when they are sent by publishers.

SQS and SNS Basics

How might a large scale, distributed application make use of a Queue system like SQS?

SQS Use Cases

Work Queues Decouple components of a distributed application that may not all process the same amount of work simultaneously.

Buffer and Batch Operations Add scalability and reliability to the architecture and smooth out temporary volume spikes without losing messages or increasing latency

Request Offloading Move slow operations off of interactive request paths by enqueueing the request.

Fan-out Combine SQS with SNS to send identical copies of a message to multiple queues in parallel for simultaneous processing.

Auto Scaling SQS queues can be used to determine the load on an application, and combined with Auto Scaling, the EC2 instances can be scaled in or out, depending on the volume of traffic