Saturday, 27 July 2024

Amazon SQS Visibility Timeout Explained for Beginners | Amazon SQS Tutorial

🚀 Master AWS Cloud!

Join the Ram N Java family for professional Java and AWS tutorials.

SUBSCRIBE ON YOUTUBE

Introduction

In a distributed system, you don't want two different workers processing the exact same order at the same time. Amazon SQS Visibility Timeout is the mechanism that prevents this duplication by hiding a message while it is being worked on.

What is Visibility Timeout?

When a consumer receives a message from a queue, SQS doesn't delete it immediately. Instead, it makes the message "invisible" to other consumers for a specific period. This period is the Visibility Timeout.

  • Default: 30 seconds.
  • Minimum: 0 seconds.
  • Maximum: 12 hours.

How the Lifecycle Works

  1. Receive: A worker picks up a message. The clock starts ticking on the timeout.
  2. Process: The message is invisible to all other workers.
  3. Delete: If the worker finishes and deletes the message, it's gone forever.
  4. Expire: If the worker fails or takes too long, the timeout expires and the message becomes visible again for another worker to try.

Why is it Important?

This setting is the backbone of reliability in AWS. It ensures that if a worker crashes, the task isn't lost—it just goes back into the queue. It also prevents duplicate work, saving you money and processing power.

Conclusion

Choosing the right visibility timeout depends on how long your tasks take. Set it too short, and you'll get duplicates; set it too long, and failed tasks will stay hidden for hours. Watch the full tutorial above to see how to configure this in the AWS Console!

No comments:

Post a Comment

Tutorials