Simple use cases of amazon’s SQS
By: Harshil Shah
Tags: Aws Simple Queue Service, NASA, AWS, Arth, Vimal Daga

What’s SQS and how it works ?

I will try my best to explain what is SQS and how it works in simplest form.

SQS is a service that provides functionality of Message Queue ( MQ ).

Message queues decouple your processes. All that is required is that the sender and the receiver agree on a common format for messages and their content and that they are using the same message broker. When part of your architecture fails, it doesn’t need to take the entire system down with it. Messages can still be added to the queue and be processed when the system has recovered. If a message fails to be delivered, the message can be redelivered until the message is processed.

SQS was the first service available on AWS back in 2004. SQS is used between microservices of a single application to communicate with each other. Hence also known as middleware. As the name suggests, it is a queue that stores messages generated from one service and needed to be delivered to other service so that further actions can be performed on basis of that message.

simple architecture of SQS.

Messages sent to SQS are usually metadata and hence maximum message size in SQS is just 256KB. One of the reason for this much message size limit is to achieve higher throughput. The service or for the sake of understanding let’s say when one server (server-A , mainly webserver) sends message or generates message than server-A is known as producer and that message is than stored in SQS. Now the other server ( server-B, here let’s say database server), will poll for this message to queue and downloads it. So server-B is known as consumer (also known as processing server since it processes message ). Figure explains it how. Now once message is stored in queue, it is consumer’s responsibility to check and poll for message and than download it. Once downloaded, consumer uses it and deletes the message from queue so that no other consumers (other servers in backend- There are multiple servers running in backend for high availability of data) can poll for same data.

These → download , use and delete of data is known as processing and hence consumer server is also known as processing server.

Now understand, when two servers are connected directly then they are known as tightly coupled or highly synchronized. But when we put SQS in middle of this two servers than these two servers are decoupled. Meaning even if processing server goes down, producer server won’t stop or will not be affected. A decoupled application architecture allows each component to perform its tasks independently — it allows components to remain completely autonomous and unaware of each other. A change in one service shouldn’t require a change in the other services. It is the process of separating services so that their functionality is more self-contained.

Different parts of your app can evolve independently if your architecture is decoupled.

By default in-transit messages are encrypted and SQS gives further facility of server side encryption also.

This is how SQS can be used with lambda function.

We can use Amazon Simple Queue Service to trigger AWS lambda functions. Lambda is a compute service that lets you run code without provisioning or managing servers and it launched the serverless revolution back in 2014.

→ SQS gives two types of queues:

Simple queue where data is randomly oriented gives guarantee of at least once delivery of data or message. FIFO ( First In First Out ) where data is exactly once processed.

I hope you understood so far. If not, feel free to ask in comments :)