Decoupling and Buffering with Amazon SQS
This lesson explains Amazon SQS, a fully managed message queue for decoupling and buffering, and the most common answer to exam questions about decoupling.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between standard and FIFO queues.
- Explain visibility timeouts, retention and dead-letter queues.
- Apply patterns such as load levelling.
Standard or FIFO
SQS offers two queue types. A standard queue supports nearly unlimited throughput but delivers each message at least once and in best-effort order, so a consumer occasionally receives a duplicate or an out-of-order message and must be idempotent. It suits most decoupling and buffering workloads.
A FIFO queue, whose name ends in .fifo, delivers messages in strict order within each message group and removes duplicates using deduplication IDs, giving exactly-once processing. Messages in different groups are processed in parallel, so using, for example, the customer ID as the group ID keeps each customer's messages in order while allowing concurrency. FIFO throughput is lower, though high-throughput mode raises it. The following table summarises the differences.
.fifo)Message lifecycle settings
SQS messages are not pushed to consumers; consumers poll the queue, process each message and then delete it. Several settings govern this cycle. The visibility timeout hides a received message from other consumers while it is processed; if the consumer does not delete it in time, it becomes visible again and is processed twice, so the timeout must exceed the processing time. Long polling makes a receive request wait up to 20 seconds for messages instead of returning empty, which reduces empty responses and cost.
The retention period decides how long an unprocessed message is kept, from one minute to 14 days. A delay queue postpones the delivery of new messages for up to 15 minutes. A dead-letter queue receives messages that have failed more than maxReceiveCount times, so they stop blocking the queue and can be examined and redriven once the problem is fixed. The following table summarises the settings.
| Setting | Value | Purpose |
|---|---|---|
| Visibility timeout | 30 s default, max 12 h | Hides a received message; set longer than processing or it reappears |
| Long polling | Up to 20 s | Fewer empty responses, lower cost |
| Retention | 1 min – 14 days (4 days default) | How long unprocessed messages stay |
| Delay queue | Up to 15 min | Postpone delivery |
| Dead-letter queue | After maxReceiveCount | Isolate failing messages; redrive once fixed |
Consumers poll, process, then delete. Large payloads use the Extended Client Library (S3). Encrypt with SSE-SQS or KMS; control access with queue policies.
The following diagram shows a message's path and the settings that act on it.

12hours
Maximum visibility timeout
20s
Maximum long-polling wait
14days
Maximum retention
15min
Maximum delivery delay
Queue problems
Patterns
Amazon SQS supports several common patterns. In load levelling, a queue sits in front of a back end with limited capacity, such as one that can process 100 orders per second: the queue accepts bursts far above that rate, and the back end works through them at its own pace, so no requests are lost.
In independent scaling, consumers scale with the queue's backlog: EC2 Auto Scaling groups scale on the backlog per instance, Lambda event source mappings scale automatically, and ECS services scale on queue metrics. SQS has no message priorities, so priority is implemented with separate high-priority and low-priority queues, polling the high-priority queue first or giving it more consumers.
SQS patterns
A queue for an overloaded back end
An application's order processing sometimes cannot keep up, and orders are lost when the processing servers are overwhelmed.
| Design choice | Setting |
|---|---|
| Decouple the web tier from processing | Web tier sends orders to an SQS queue |
| Never lose an order | Messages stay in the queue until processed and deleted (retention up to 14 days) |
| Each order processed in sequence per customer | FIFO queue with the customer ID as message group |
| Bad orders do not block the queue | Dead-letter queue after 5 failed attempts |
| Scale processing with the backlog | Auto Scaling on queue depth per instance |
The queue turns a fragile synchronous chain into a buffered, scalable design: the web tier stays fast, and processing catches up at its own pace.
Which queue type guarantees order and removes duplicates?
Show answer
A FIFO queue, which preserves order within each message group and deduplicates messages sent within five minutes. Standard queues may deliver duplicates and out of order.
Exam Tips
Remember for the exam
- To decouple tiers and absorb spikes, use SQS.
- For strict ordering and no duplicates, use a FIFO queue with message group IDs.
- When messages are processed twice, increase the visibility timeout beyond the processing time.
- To isolate messages that repeatedly fail, use a dead-letter queue.
- When a back end cannot handle bursts of traffic, put an SQS queue in front of it to level the load.
- For message priorities, use a separate queue for each priority.