DEV Community

Javier Mendoza
Javier Mendoza

Posted on

A starters guide from SQS and some learning along the way

In this guide, we will go through the basics of what SQS is and why it’s important for you to start using it.

What is it?

Is a service from AWS which is queue where messages wait their turn to be processed.

As a fun fact, SQS was the first Serverless Service launched by AWS in 2006

Why is it important?

SQS allows you to improve the resilence and retryability of your system.

Let's imagine that you've the following scenario:

Your API exposes a POST /create-order endpoint, and it’s connected directly to a Lambda function called 'CreateOrder'.

If your system receives a lot of traffic, your CreateOrder Lambda may start throttling, which means some orders could be lost.

In order to avoid this, we can put an SQS in the middle.

Having the SQS in the middle ensures that requests are not lost.

The queu will hold each request until it gets consumed or it has reached the maximum age of the message in the queue, by default is 4 days and the maximum is 14 days.).

When a consumer begins processing a message, SQS hides it temporarily so that no other consumer can process it at the same time.
This is controlled by the visibility timeout, which defines how long a message stays hidden while being processed.

The message is attempted to be consumed up to the amount of times defined by the maxReceiveCount.
This count represents how many attempts the message can go through before being considered “failed.”

DLQ

We can setup a Dead-Letter-Queue (DLQ) Attached to our SQS, so that once a message reaches the maxReceiveCount, it is moved to the DLQ for debugging.

When a message reaches your DLQ, you can redrive the message to the original queue through the AWS Console or through the CLI

Through the AWS Console:

You should go to your Queu and select ->

Start DLQ Redrive

by default it redrives to the source queu but you can select other queu to the messages to be delivered to.

Typical SQS Consumer

We've seen that you can consume SQS by using lambdas, but that's far from the only one. You can also use:

There are two types of SQS

Standard SQS where messages may be delivered out of order

Priority SQS messages are processed in order

and there are also another type of messages which deserve their own space 'fair queues' which will cover in the next post.

More to come!

Top comments (0)