AWS SQS
AWS Simple Queue Service (SQS) is a fully managed, highly available message queuing service that decouples and scales microservices, distributed systems, and serverless applications. It reliably stores messages until they are processed and deleted by consumers.

Key capabilities
- Durable, highly available queue storage across multiple AZs.
- Two queue types: Standard (high throughput, at-least-once delivery, best-effort ordering) and FIFO (exactly-once processing and strict ordering).
- Visibility timeout to prevent duplicate processing while a consumer handles a message.
- Dead-letter queues (DLQ) for failed messages.
- Long polling to reduce empty responses and cost.
- Message attributes to pass metadata.
- Server-side encryption (SSE) with AWS-managed or customer-managed KMS keys.
- Access control via IAM and resource policies; VPC endpoints (AWS PrivateLink) for private access.
- Integration with Lambda (event source mapping), SNS (fan-out), EventBridge, Step Functions, ECS/EC2, and more.
- CloudWatch metrics and CloudTrail logging for observability and audit.
Types of SQS
- FIFO
- Exactly-once processing (with deduplication).
- Preserves message order within a message group (MessageGroupId).
- Limited throughput per message group (can be increased via batching and message groups).
- Queue name ends with .fifo and supports content-based or explicit deduplication.
- Standard
- Unlimited throughput.
- At-least-once delivery (duplicates possible).
- Best-effort ordering (messages might be delivered out of order).
Core concepts
- Visibility Timeout: Period a message is invisible after being received. If the consumer fails to delete it before this expires, it becomes available again.
- Long Polling: ReceiveMessage waits up to N seconds for messages; reduces empty responses and API costs.
- Dead-Letter Queue (DLQ): Receives messages that exceed a max receive count. Use to inspect and handle poison messages.
- Message Retention: Messages retained from 1 minute to 14 days (default 4 days).
- Maximum Message Size: 256 KB (SQS extended with S3 for larger payloads via pointers).
- Batching: SendMessageBatch and ReceiveMessage support up to 10 messages per batch for efficiency.
Example CLI snippets
Create standard queue:
aws sqs create-queue --queue-name my-app-queue
Create FIFO queue:
aws sqs create-queue --queue-name my-app-queue.fifo \
--attributes FifoQueue=true,ContentBasedDeduplication=true
Send a message (with attributes):
aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue \
--message-body "OrderCreated: {\"orderId\":\"1234\"}" \
--message-attributes '{"eventType":{"DataType":"String","StringValue":"OrderCreated"}}'
Receive and delete:
# Receive (long poll up to 10s)
aws sqs receive-message --queue-url <URL> --wait-time-seconds 10 --max-number-of-messages 5
# Delete (after processing)
aws sqs delete-message --queue-url <URL> --receipt-handle <ReceiptHandle>
Configure DLQ (redrive policy example when creating consumer queue):
# redrive-policy JSON: { "deadLetterTargetArn":"arn:aws:sqs:...:dlq", "maxReceiveCount":"5" }
aws sqs set-queue-attributes --queue-url <consumer-queue-url> \
--attributes RedrivePolicy='{"deadLetterTargetArn":"arn:aws:sqs:us-east-1:123456789012:my-dlq","maxReceiveCount":"5"}'
Common use cases
- Decoupling microservices (producer and consumer scale independently).
- Buffering and smoothing traffic spikes (e.g., order ingestion).
- Asynchronous processing (image/video processing, email sending).
- Work distribution among worker fleets.
- Reliable handoff between systems (legacy integrations, batch jobs).
- Event-driven architectures (SNS → SQS → consumers).
Limitations & considerations
- Per-message max size 256 KB. Use pointer pattern for larger payloads.
- FIFO queues have throughput limits per message group; design message groups to scale.
- SQS guarantees at-least-once delivery for Standard queues; handle duplicates.
- Visibility timeout must be managed to avoid duplicate processing or message loss.
- Pricing is per request and payload transferred; evaluate batching to reduce cost.
