AWS Builder Center

Amazon SQS

Queue Types, Visibility Timeout, Dead Letter Queues, and VPC Endpoints

A beginner-friendly guide to Amazon Simple Queue Service (SQS) and its role in building reliable, scalable cloud applications.

1. What Is Amazon SQS?

Amazon Simple Queue Service (Amazon SQS) is a fully managed message queuing service provided by Amazon Web Services (AWS). It allows applications and distributed systems to communicate asynchronously by sending, storing, and receiving messages through a queue.
In simple terms, SQS acts as a temporary waiting line between two applications.
Imagine a restaurant where customers place orders. The waiter records each order and sends it to the kitchen. If the kitchen is busy, the orders wait in a queue until the kitchen can process them.
Amazon SQS works in a similar way:
  • Producer: The application that sends messages.
  • Queue: The place where messages wait.
  • Consumer: The application that receives and processes messages.
  • Message: The information being transferred, such as an order ID or customer details.
The producer and consumer do not need to operate at the same time. SQS stores messages until consumers can process them, helping applications work independently.

2. Key Components of Amazon SQS

Understanding the main components makes it easier to understand how SQS works.

Producer

A producer creates and sends messages to an SQS queue.
Example: An e-commerce website sends a message whenever a customer places an order.

Queue

The queue temporarily stores messages until a consumer receives and processes them.
Example: An order queue stores incoming orders during a major sale.

Consumer

A consumer retrieves messages from the queue and performs the required operations.
Example: A worker application processes an order, updates inventory, and stores order details in a database.

Message

A message contains the information that needs to be transferred between applications.
Example: A message might contain an order ID, customer ID, and product information.

Receipt Handle

When a consumer receives a message, SQS returns a receipt handle. The consumer uses this handle to delete the received message or change its visibility.

Polling

Consumers poll the queue to check for available messages. SQS supports short polling and long polling, allowing applications to retrieve messages efficiently.

3. Types of Amazon SQS Queues

Amazon SQS provides two primary queue types: Standard and FIFO.

Standard Queue

A Standard queue is designed for very high throughput and distributed message processing.
Its main characteristics include:
  • At-least-once message delivery.
  • Best-effort message ordering.
  • Very high throughput.
  • The possibility of receiving duplicate messages.
  • Messages may be processed in a different order from which they were sent.
Standard queues are useful when applications need to process large numbers of messages and can tolerate occasional duplicate deliveries or out-of-order processing.
Example: A system processes product-view events generated by thousands of users. Each event can be processed independently, so strict ordering is not essential.

FIFO Queue

FIFO stands for First-In, First-Out. FIFO queues are designed for applications that require messages to be processed in order within a message group.
Their main characteristics include:
  • Ordered message processing within each message group.
  • Deduplication support.
  • Suitability for workflows where message order matters.
FIFO queues are useful when processing one operation before another is important.
Example: A banking application must process account operations in the correct sequence to maintain consistent account balances.

Standard vs. FIFO Queue

FeatureStandard QueueFIFO Queue
OrderingBest-effort orderingPreserves order within a message group
DeliveryAt least onceDeduplication support
ThroughputVery highDepends on FIFO throughput configuration
Duplicate messagesPossibleDeduplication reduces duplicate sends within the deduplication interval
Best suited forIndependent tasks and high-volume processingOrdered workflows and sequence-sensitive operations
Important: Amazon SQS is a message broker, not a database. Messages are retained for a configured period and can be removed after successful processing by deleting them from the queue.

4. Why Do We Use Amazon SQS?

Amazon SQS helps developers build reliable, scalable, and loosely coupled applications.

Reliability

The producer and consumer do not need to run at the same time. Messages can remain in the queue until consumers are available to process them.

Buffering

SQS absorbs temporary differences between the rate at which messages arrive and the rate at which consumers process them.

Scalability

Consumer applications can scale according to the volume of messages waiting in the queue.

Fault Tolerance

Messages can become available for retry when processing fails. Dead Letter Queues can isolate messages that repeatedly fail.

Real-World Example: An E-Commerce Sale

Imagine an e-commerce website receives 10,000 orders during a major sale.
Without a queue, the website might need to wait for order processing to complete before responding to every request. This can increase latency and put pressure on backend services.
With SQS, the workflow becomes:
  1. Customers place orders on the website.
  2. The application sends each order to an SQS queue.
  3. Worker applications retrieve orders as they have capacity.
  4. Workers process orders and update the order database.
  5. Failed messages can be retried or moved to a Dead Letter Queue when the configured threshold is reached.
This design separates order submission from order processing and helps the application handle traffic spikes.

5. Visibility Timeout in Amazon SQS

Visibility Timeout is the period during which a message becomes temporarily invisible to other consumers after it has been received.
The message remains in the queue during this period. If the consumer processes it successfully, the consumer deletes it. If the consumer fails to delete it before the visibility timeout expires, the message can become available for another receive attempt.

Example

Suppose a worker receives an order at 10:00 AM and the visibility timeout is five minutes.
  • At 10:00 AM, the worker receives the message.
  • During processing, the message is temporarily invisible to other consumers.
  • If processing succeeds, the worker deletes the message.
  • If processing fails and the message is not deleted, it can become visible again after the timeout expires.
Visibility timeout helps prevent multiple consumers from processing the same message simultaneously under normal conditions. It does not guarantee that duplicate processing can never occur.
Best practice: Configure the visibility timeout to accommodate the expected processing time. For longer-running tasks, a consumer can extend the timeout when appropriate.
The default visibility timeout is 30 seconds, and the maximum is 12 hours.

6. What Is an SQS Delay Queue?

A Delay Queue temporarily hides a newly sent message from consumers for a configured period.
Unlike visibility timeout, which begins when a consumer receives a message, a queue delay affects the message's initial availability after it is sent.

Example: Scheduling an Email

Suppose an application sends a message at 10:00 AM with a two-minute delay.
  • At 10:00 AM, the producer sends the message.
  • The message is not yet available to consumers.
  • At approximately 10:02 AM, the delay expires.
  • A consumer can then retrieve and process the message.
Delay queues are useful when a task should not become available immediately.
The default delay is zero seconds, and the maximum is 15 minutes. For scheduling tasks hours or days into the future, a service such as Amazon EventBridge Scheduler may be more appropriate.

7. Visibility Timeout vs. Delay Queue

Although both features temporarily prevent consumers from receiving messages, they serve different purposes.
FeatureVisibility TimeoutDelay Queue
PurposeGives a consumer time to process a received messageDelays initial message availability
Starts whenA consumer receives the messageThe message is sent
Message stateTemporarily invisible after receiptInitially unavailable
Typical useProcessing an orderDelaying a task or notification
Default30 seconds0 seconds
Maximum12 hours15 minutes
An easy way to remember the difference:
  • Visibility Timeout: The consumer has received the message; give it time to finish.
  • Delay Queue: Do not let the consumer receive the message yet.

8. What Is a Dead Letter Queue (DLQ)?

A Dead Letter Queue is a separate SQS queue used to isolate messages that cannot be successfully processed after a configured number of receive attempts.
Repeatedly processing a problematic message can waste resources and interfere with normal application workflows. A DLQ allows such messages to be examined separately.

How Does a DLQ Work?

Consider an order-processing application.
  1. A producer sends an order to the main SQS queue.
  2. A consumer receives the order.
  3. Processing fails, or the consumer does not delete the message.
  4. The message can become visible again after the visibility timeout expires.
  5. SQS tracks the receive count for redrive purposes.
  6. When the configured threshold is reached, the message becomes eligible to be moved to the configured DLQ under the queue's redrive policy.
For example, suppose the main queue is named OrdersQueue, the DLQ is named OrdersDLQ, and maxReceiveCount is configured as 3.
If an order repeatedly fails processing and reaches the configured receive-count threshold, it can be moved to OrdersDLQ.

Benefits of a DLQ

  • Isolation: Problematic messages are separated from normal messages.
  • Debugging: Developers can inspect failed messages to understand the cause.
  • Reliability: Repeated failures do not endlessly consume normal processing capacity.
  • Recovery: Messages can be reviewed, corrected, and potentially redriven after the underlying problem is fixed.

Common Reasons for Messages Entering a DLQ

  • Invalid message formats.
  • Errors in the consumer application.
  • Temporarily unavailable dependencies.
  • Business logic that consistently fails for a particular message.
Important: A DLQ does not automatically diagnose or fix an error. Developers must inspect the message, application logs, and processing logic to determine the cause.

9. What Is an Amazon VPC Interface Endpoint for SQS?

Applications running inside private subnets often need to communicate with AWS services without accessing them through the public internet.
An Amazon VPC interface endpoint provides private connectivity to supported AWS services, including Amazon SQS, using AWS PrivateLink.
Without an interface endpoint, an EC2 instance in a private subnet generally needs a suitable network path, such as a NAT Gateway, to reach the public regional SQS endpoint.
An interface endpoint provides an alternative by creating endpoint network interfaces with private IP addresses inside the VPC.

Example Architecture

Consider an EC2 instance running an application in a private subnet of a VPC.
The application needs to send messages to and receive messages from an SQS queue.
The communication flow is:
  1. The EC2 application sends an HTTPS request to the regional SQS endpoint.
  2. With private DNS enabled, the SQS hostname resolves to private IP addresses associated with the interface endpoint.
  3. Traffic travels through AWS PrivateLink.
  4. AWS evaluates the applicable network permissions, IAM permissions, queue policies, and endpoint policies.
  5. The application performs authorized SQS operations.
This architecture allows the EC2 instance to communicate with SQS privately without requiring a NAT Gateway or Internet Gateway for that SQS connection.

Benefits of an Interface Endpoint

  • Private connectivity: SQS requests can travel through private networking.
  • Reduced internet exposure: The SQS connection does not need to traverse the public internet.
  • Network design: Private-subnet workloads can access supported AWS services without using a NAT Gateway for that traffic.
  • Access control: Security groups, IAM permissions, queue policies, and endpoint policies can help control access.
An interface endpoint does not automatically grant permission to access SQS. The application's identity, endpoint configuration, queue policy, and network rules must still permit the requested operations.

10. Best Practices for Using Amazon SQS

When designing an SQS-based application, consider the following practices:
  1. Choose the correct queue type. Use Standard queues when high throughput and flexible ordering are acceptable. Use FIFO queues when ordered processing is required.
  2. Configure visibility timeout carefully. Allow enough time for normal processing and extend the timeout when necessary for longer tasks.
  3. Make consumers idempotent. Design processing so that repeated delivery of a message does not cause unintended duplicate effects.
  4. Configure a DLQ for failure isolation. Choose a suitable receive-count threshold and monitor failed messages.
  5. Monitor queue behavior. Track metrics such as the number of available messages, messages in flight, and messages sent to a DLQ.
  6. Use appropriate polling. Consider long polling to reduce unnecessary empty receives.
  7. Apply least-privilege permissions. Grant applications only the SQS actions and resources they require.
  8. Use private endpoints when appropriate. Interface endpoints can provide private access to SQS from VPC workloads.

Conclusion

Amazon SQS is an important AWS service for building reliable, scalable, and loosely coupled distributed applications. It enables asynchronous communication between producers and consumers, buffers traffic spikes, and helps applications continue processing work when individual components are temporarily unavailable.
Understanding Standard and FIFO queues, visibility timeout, delay queues, Dead Letter Queues, and VPC interface endpoints provides a strong foundation for designing practical cloud architectures.
Whether you are building an e-commerce order-processing system, a background job processor, or a private-subnet application on AWS, Amazon SQS can help separate workloads and improve the resilience of your architecture.

Suggested tags: Amazon SQS, AWS, Cloud Computing, AWS Architecture, Distributed Systems, Message Queues, Cloud Engineering, AWS PrivateLink
Author's note: This article is intended as a beginner-friendly educational guide. For production deployments, consult the official AWS documentation for current service limits, queue configuration, security requirements, and architecture recommendations.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article