AWS Simple Queue Service

Photo by Meizhi Lang on Unsplash

AWS Simple Queue Service

Introduction

Suppose there are 4 counters at the billing. I spent less time waiting in line. However, on weekdays when there is a little rush, 4 people will be paid. What are the four people doing at the counter?

Whether it is Amazon, Snapdeal or YouTube everywhere, there is not a single job to be done. There are many multiple jobs handled by different servers. Amazon also needs to sign in and that is done by the first server. From the first server, it will be transferred to the second server. which will show the contents and this process goes on.

In an application, if too many servers are working and too many requests are coming in, then to manage this we need SQS. Once the work of one server is done it notifies the other server as well.

Visibility timeout

So for Tseconds, the message is not shown in the queue so that others won't consider processing it again and once the process is done API is called and the message is deleted.

In Amazon Simple Queue Service (SQS), the visibility timeout is a setting that determines how long a message remains invisible in the queue after being retrieved by a consumer. During this period, the message is considered to be "in-flight" and cannot be received by other consumers. The visibility timeout provides a window of time for a consumer to process and delete the message without other consumers receiving the same message.

When a consumer retrieves a message from an SQS queue, it becomes invisible to other consumers for the duration of the visibility timeout. If the consumer successfully processes and deletes the message within this timeframe, the message is removed from the queue. However, if the consumer fails to delete the message within the visibility timeout, the message becomes visible again and can be received by another consumer.

The default visibility timeout in SQS is 30 seconds. However, you can adjust the visibility timeout according to your requirements. The maximum allowed visibility timeout is 12 hours (43,200 seconds). You can specify the visibility timeout when creating or updating an SQS queue using the AWS Management Console, AWS CLI (Command Line Interface), or AWS SDKs (Software Development Kits).

Here is an example of setting the visibility timeout using the AWS CLI:

aws sqs create-queue --queue-name my-queue --attributes VisibilityTimeout=60

This command creates a queue named "my-queue" with a visibility timeout of 60 seconds.

Why SQS?

  1. AWS SQS (Simple Queue Service) is a fully managed message queuing service provided by Amazon Web Services (AWS). It enables decoupling and asynchronous communication between distributed software components and systems.

  2. SQS allows applications to send, store, and receive messages between different software components or systems. It acts as a buffer, allowing the sender and receiver to operate independently, without needing to be connected at the same time.

  3. SQS offers a reliable and scalable solution for handling message-based communication. It provides redundant storage and high availability to ensure that messages are not lost even if a component or system fails.

  4. With SQS, messages can be sent and received using various programming languages, making it suitable for building distributed systems with different technology stacks. It supports both standard and FIFO (First-In-First-Out) queues, providing different ordering and delivery guarantees depending on the use case.

  5. AWS SQS integrates seamlessly with other AWS services, such as AWS Lambda, Amazon EC2, and AWS CloudFormation, allowing you to build complex and scalable architectures. It also offers features like message retention, dead-letter queues, and message visibility timeout to handle various messaging scenarios and ensure reliable message processing.

AWS Queue types

Amazon Simple Queue Service (SQS) provides two types of queues: Standard and FIFO (First-In-First-Out).

  1. Standard Queue:

    • Standard queues provide at-least-once delivery, where a message can be delivered multiple times but duplicate messages may occur.

    • They offer high throughput and can scale to handle a virtually unlimited number of transactions per second.

    • Standard queues provide best-effort ordering, which means that the order of messages is generally preserved but not guaranteed.

    • This type of queue is suitable for most common messaging scenarios.

  2. FIFO Queue:

    • FIFO queues guarantee exactly-once processing, ensuring that each message is processed only once and remains in the order it was sent.

    • They are designed for applications that require strict ordering and exact processing of messages.

    • FIFO queues have a limited throughput compared to standard queues, supporting up to 300 transactions per second (TPS) with batching and up to 3,000 TPS without batching.

    • FIFO queues are recommended when you have applications that require message deduplication or strict message ordering.

SQS retention

  1. SQS messages can remain in the queue for 14 days.

  2. The range is one minute to 14 days.

  3. The default is 4 days.

  4. Once the maximum retention period of a message is reached, it will be deleted from the queue automatically.

  5. Messages can be sent to the queue and read from the queue simultaneously.

  6. You can have multiple queues of different priorities.

Delivery delay

  1. AWS SQS provides delivery delay options to postpone the delivery of new messages to a queue.

  2. If a delivery delay is defined in a queue, any new message will not be visible to the server for the duration of the delay.

  3. The minimum delay can be zero seconds and the maximum delay can be 15 seconds.