AWS · Application Integration
Amazon SQS
A fully managed message queue that decouples producers from consumers, so work is buffered and processed at the consumer's pace.
What it is and what problem it solves
Amazon SQS (Simple Queue Service) is a managed queue. A producer sends messages to the queue; consumers poll, process and then delete each message. Until it is deleted, a message stays in the queue, so a crashed consumer does not lose work.
This puts a buffer between two parts of a system: a traffic spike makes the queue longer rather than overloading the consumers, and a slow or failing consumer does not slow down the producer.
There are two queue types. Standard queues give very high throughput with at-least-once delivery and best-effort ordering, so consumers must handle duplicates. FIFO queues keep order within a message group and avoid duplicates inside a deduplication window, at lower throughput.
When to use it
- One part of a system hands work to another and the producer should not wait: order processing, image resizing, email sending.
- Load is bursty and you want consumers to scale on queue depth (an Auto Scaling group or Lambda consuming the queue).
- You need retries with a dead-letter queue for messages that keep failing.
- Each message should be handled by one consumer, not broadcast to many.
When to avoid it
- Broadcasting one message to many subscribers: use SNS (or EventBridge) in front of queues; an SQS queue delivers each message to one consumer.
- Routing by event content across many targets: EventBridge rules do this without code.
- Strict ordering at very high throughput across all messages: ordering applies per message group in FIFO queues, and FIFO throughput is capped; consider a stream such as Kinesis.
- Replaying history: a deleted message is gone. A stream keeps data for replay.
Scaling model and bottlenecks
Standard queues scale automatically and have no practical limit on throughput; you scale the consumers. A common design scales an Auto Scaling group on the queue's backlog per instance, or lets Lambda scale its pollers with the queue. FIFO queues scale by message group: messages in one group are processed in order, so many groups run in parallel, and one very busy group becomes the bottleneck.
Performance, latency and throughput
Use long polling (waiting up to the maximum wait time for a message) to cut empty responses and cost, and batching (up to ten messages per call) to raise throughput per API call. FIFO queues have lower default throughput than standard queues, with a high-throughput mode that raises it by Region.
Limits and quotas
A message has a fixed maximum size; larger payloads are usually stored in S3 with the queue carrying a pointer, and the Extended Client Library does this for you.
| Item | Value | Context | Source |
|---|---|---|---|
| Maximum message size | 1,048,576 bytes (1 MiB) | Larger payloads can be handled with the Extended Client Libraries, which store the payload in S3. | Source checked |
| Message retention | 1 minute to 14 days | The default is 4 days. | Source checked |
| Visibility timeout | 0 seconds to 12 hours | The default is 30 seconds. | Source checked |
| Delay (timer) for a message | 0 seconds to 15 minutes | Source checked |
|
| Messages per batch request | 10 | Source checked |
|
| Long polling maximum wait | 20 seconds | Source checked |
|
| In-flight messages, standard queue | About 120,000 Can be raised with a quota request |
Received but not yet deleted messages. | Source checked |
| FIFO throughput without high-throughput mode | 300 per API action; up to 3,000 messages per second with batching per second | Per message-group partition, for each of SendMessage, ReceiveMessage and DeleteMessage. | Source checked |
Quotas and limits change. Check the linked source before designing around a number.
Cost model
What you pay for
- Requests: every API call counts, and each 64 KB chunk of a payload is billed as one request, so a 1 MiB message is sixteen requests.
- Queue type: FIFO requests are billed at different rates from standard requests.
- Data transfer: free inside a Region; cross-Region and internet transfer is billed at standard data transfer rates.
- Related charges: KMS for server-side encryption with your own key, and S3 when using the Extended Client Library.
Where it is cost-efficient
Bursty or low-volume workloads: there is no charge for an idle queue, and long polling plus batching keep the request count low.
Where costs grow
- Consumers short-polling an empty queue in a tight loop, paying for many empty receives.
- Very large messages sent one at a time, because each 64 KB chunk is another request.
- Millions of tiny messages that could have been batched.
Cost controls and common surprises
Use long polling, batch sends, receives and deletes, keep payloads small, and set a sensible visibility timeout so messages are not processed twice. Review the request count in Cost Explorer.
Prices differ by Region and change over time; see the pricing page linked under Sources.
Security
Controls the service provides
- Encryption at rest with SQS-managed keys by default for new queues, or with a KMS key you control.
- Encryption in transit over HTTPS.
- Queue policies (resource-based) and IAM identity policies control who can send and receive, including other accounts.
What you configure
Grant producers only sqs:SendMessage and consumers only receive and delete on specific queue ARNs; use a
queue policy to allow SNS or EventBridge to deliver into the queue; use a VPC interface endpoint if
consumers have no internet path; use your own KMS key if you must control and audit key usage.
Logging and monitoring
CloudTrail records queue API calls; CloudWatch metrics show queue depth, age of the oldest message and empty receives.
Related security services
KMS (encryption keys), VPC endpoints (private access), IAM (permissions).
Shared responsibility
AWS runs and secures the service. You control who may use each queue, the encryption key, and what the messages contain.
Availability, backup and failure behavior
SQS stores each message redundantly across multiple Availability Zones in the Region, so a zone failure does not lose messages. A dead-letter queue collects messages that fail processing more than a configured number of times, so one bad message cannot block the rest. A queue is regional; for cross-Region resilience the producer or another service must send to a second Region.
Common service combinations
SNS then SQS (fan-out: one event, several queues); EventBridge rules targeting a queue; Lambda or an Auto Scaling group of EC2 workers consuming; S3 event notifications into a queue; DynamoDB for idempotency records.
Business application examples
- An online shop puts each paid order on a queue; fulfilment workers take them at their own pace.
- A photo site queues resize jobs so an upload spike does not overwhelm the image workers.
- A billing system sends failed charges to a dead-letter queue for review instead of retrying forever.
Exam cues and common confusions
- Decouple tiers / absorb spikes: SQS between them; scale consumers on queue depth.
- Ordering: FIFO queue. Maximum throughput, order not required: standard queue.
- Duplicates: standard queues can deliver a message more than once, so processing must be idempotent.
- Visibility timeout should be longer than the processing time, or another consumer sees the message again.
- Failed messages: a dead-letter queue.
- One message, many consumers: SNS topic with SQS subscriptions (fan-out), not a single queue.
Related
Courses and lessons
- Amazon SQS: queues, FIFO, visibility timeout and dead-letter queues · AWS Solutions Architect – Associate (SAA-C03) · Members
- Amazon SNS and the fan-out pattern · AWS Solutions Architect – Associate (SAA-C03) · Members
Services, comparisons and patterns
- Amazon SNS · Service
- Amazon EventBridge · Service
- AWS Lambda · Service
- Amazon Kinesis · Service
- SQS vs SNS vs EventBridge · Comparison
- Event-driven order processing · Solution pattern
- Kinesis Data Streams vs MSK vs SQS · Comparison
Sources
Independent study material, not affiliated with or endorsed by Amazon Web Services. AWS and service names are trademarks of Amazon.com, Inc. or its affiliates.