1At-Least-Once Delivery
With SQS Standard queues, AWS guarantees that a message will be delivered at least once, but occasionally, a copy of that message might be delivered twice. Therefore, your consumer application must be 'idempotent'—meaning if it processes the exact same message twice, the end result in your database remains the same.
2Step-by-Step Breakdown
The Tightly Coupled Problem. When Server A talks directly to Server B synchronously, if Server B crashes or gets overwhelmed, Server A fails too. This is tightly coupled architecture.
What is Amazon SQS?. Simple Queue Service (SQS) is a fully managed message queuing service that acts as a buffer between microservices, allowing them to scale independently.
Decoupling Architecture. Server A sends a message to SQS. Server B polls SQS and processes the message. If Server B crashes, the message stays safely in the queue until Server B recovers.
Standard vs FIFO Queues. Standard Queues offer massive throughput with 'at-least-once' delivery and best-effort ordering. FIFO Queues guarantee exact ordering and 'exactly-once' processing.
Knowledge Check. Which SQS queue type guarantees that messages are processed exactly once and in the exact order they were sent?
- →Standard Queue
- →FIFO Queue
Visibility Timeout. When a consumer pulls a message, SQS hides it from other consumers for a set time. If the consumer finishes, it deletes the message. If it fails, the message reappears for retry.
Dead-Letter Queues (DLQ). If a message fails processing multiple times (e.g., due to bad data), SQS moves it to a DLQ so it doesn't block the main queue forever, allowing you to debug it later.
Long Polling. Long Polling reduces costs by waiting (up to 20 seconds) for a message to arrive before returning an empty response. This drastically reduces empty API calls.
Scaling with SQS. A powerful cloud pattern is triggering an Auto Scaling Group to add more EC2 instances when the SQS queue length grows too large.
Summary. SQS provides an infinite buffer to absorb massive traffic spikes without losing data.
