Deleting message from SQS FIFO queue The receipt handle has expired
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding SQS FIFO Queues
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. It offers two types of queues: Standard and FIFO (First-In-First-Out). For applications where order is paramount and messages should be processed exactly once, FIFO queues are the preferred choice.
In a FIFO queue, messages are processed in the exact order they are sent and are not delivered more than once. This article focuses on a common issue encountered when working with FIFO queues: deleting a message when the receipt handle has expired.
What is a Receipt Handle?
When a consumer retrieves a message from the SQS queue, it receives a unique identifier known as the receipt handle. It is essential to understand that:
- The receipt handle is used to delete or change the visibility of the message.
- It is unique for each message received from the queue.
- If the visibility timeout expires before the message is deleted, the receipt handle becomes invalid.
Causes and Solutions for Receipt Handle Expiration
Cause of Expiration
A receipt handle expires primarily due to the message's visibility timeout elapsing before the consumer acknowledges its processing through deletion. The visibility timeout is the period during which a message is invisible to other consumers after being received by a consumer. Here are the common scenarios that might lead to expiration:
- Long Processing Time:
- If your application takes longer than the visibility timeout to process a message, the receipt handle will expire.
- Network Delays or Errors:
- Network issues can prevent timely deletion, causing the receipt handle to expire.
- Code Bugs:
- Logic errors might prevent deletion requests from being sent.
- Incorrect Visibility Timeout Configuration:
- The visibility timeout is set lower than necessary for your processing time.
Solutions
- Adjust the Visibility Timeout: Modify the visibility timeout settings based on your application's message processing time.

