Support Documents

Difference between SQS Visibility Timeout and Delay Queue

Lab Details

  1. This lab will walk you through the steps to create a SQS Queue, set visibility and delivery delay time. Send a message from the queue and receive the message in the lambda function.

  2. Duration: 30 minutes

  3. AWS Region: US East (N. Virginia) us-east-1


SQS(Simple Queueing Service)

Fact: This was the first ever AWS service offering made publicly available.

  • Amazon SQS is a reliable, easy to manage,  scalable queuing service. SQS is a simple and cost effective cloud application.

  • AWS SQS can be used to transmit any amount of data, at any level of throughput, without losing messages.It doesn’t interrupt other services when run continuously.

  • SQS helps to reduce admirative task by scaling high-available messaging clusters. While we pay only for what we use. AWS SQS helps us to save important data which could be lost if an entire application goes down or if any component becomes unavailable. 

  • SQS queue acts as a buffer between the application components that receive the data and the other parts that process the data in the system.

  • SQS is used for message-oriented architecture. If the processing server cannot process the work fast enough (for whatever reason) the work is queued so that the processing servers can work on it when they have available resources to process the request. This means that work is not lost due to insufficient resources.

  • The default Amazon SQS ensures that each message is delivered at least once.


         There are two types of Queues:

What is Visibility TimeOut

  1. Visibility timeout is a time duration which AWS SQS avoids the other components from receiving and processing the messages.

  2. Case Study:

    • Lets try to understand the definition by an example. So if you keep your visibility timeout to 1 minute for a big data job, what's going to happen is the message is going to come back into the queue because it's not going to complete in 1 minute.

    • Let's say it takes five minutes to actually process the large amount of data.The message is going to become visible in the queue and then another EC2 instance will pick it up. Because of this you could be delivering your messages multiple times because your visibility timeout is too low.

  3. Default Visibility timeout is 30 seconds.

  4. Increase it if your task takes > 30 seconds.

  5. Maximum it can go up to is 12 hours.

What is Delay Queue 

  1. Delay queue allows us to delay/postpone the delivery of a new message for a given period of time. We can easily turn any queue into a delay queue by configuring SetQueueAttributes to set the queue’s DelaySeconds attribute.

    • If we create a delay queue, any message that has been sent to this queue will remain invisible to the consumer for the configured delay time.

    • To create a delay queue set DelaySeconds attribute to a value between 0 to 900 seconds.

  2. Case Study:

    • Let's try to understand the definition by an example. Consider a case where an application is trying to insert millions of data into a database. The application will send a message about the availability of this new data that has been recently inserted to other subsystems, which in turn process this message and subsequently make updates to the same row. Now there is a dependency that until the first batch completes its job and commits after the updates the next batch should not get triggered. If the message gets triggered before the updates complete, it would fail the next batch. In this case, delay delivery helps.

Architecture Diagram

Task Details

  1. Login to AWS Management Console

  2. Create an IAM Role.

  3. Create a SQS queue.

  4. Create a Lambda function.

  5. Send a message with Visibility Timeout.

  6. Purge the Queue

  7. Send a message with Delivery Delay 

  8. Purge the Queue

  9. Validation of the lab

  10. Deleting AWS resources