Skip to content

SQS

Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications .

SQS eliminates the complexity of managing message-oriented middleware, allowing software components to communicate asynchronously at any volume without losing messages .


Amazon SQS is a fully managed message queuing service that enables you to send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available .

BenefitDescription
Fully ManagedNo software to install, configure, or maintain—AWS handles all ongoing operations and underlying infrastructure
Elastic ScalingQueues automatically scale to handle any load without provisioning instructions
High AvailabilityMessages are stored redundantly across multiple Availability Zones
SecureServer-side encryption (SSE) with AWS KMS integration for sensitive data
Cost-EffectivePay-as-you-go pricing with no upfront costs; free tier includes 1 million requests monthly

AWS Free Tier includes 1 million Amazon SQS requests per month .


Message queues enable you to build applications as independent components that communicate asynchronously . This decoupling provides several advantages:

AdvantageDescription
Fault ToleranceIf a component fails, messages remain in the queue for later processing
ScalabilityEach component can scale independently based on demand
Load LevelingQueues buffer requests, smoothing out traffic spikes
DecouplingProducers and consumers don’t need to be available simultaneously

In an e-commerce application, when a customer places an order:

  1. The order service sends a message to an SQS queue
  2. The payment service, inventory service, and fulfillment service each process messages independently
  3. If the fulfillment service is temporarily unavailable, messages remain in the queue until it recovers

Amazon SQS offers two queue types, each designed for different messaging requirements .

FeatureStandard QueueFIFO Queue
ThroughputNearly unlimited TPS per API actionUp to 3,000 TPS (batch) or 300 TPS (non-batch)
Message OrderingBest-effort orderingStrict First-In-First-Out
Delivery GuaranteeAt-Least-Once DeliveryExactly-Once Processing
DeduplicationNot supportedAutomatic or manual deduplication
Use CasesHigh-throughput, order-tolerant workloadsOrder-critical, duplicate-sensitive workloads
CostLower per requestHigher per request

Standard queues are designed to support a nearly unlimited number of transactions per second (TPS) per API action . They offer:

  • At-Least-Once Delivery: Messages are delivered at least once, but occasionally more than one copy may be delivered
  • Best-Effort Ordering: Messages might occasionally be delivered in a different order than they were sent

Best for: High-throughput applications where occasional duplicates or out-of-order messages are acceptable .

FIFO (First-In-First-Out) queues are designed to enhance messaging when the order of operations is critical or duplicates cannot be tolerated .

Key guarantees:

  • Exactly-Once Processing: Each message is delivered once and remains available until a consumer processes and deletes it
  • First-In-First-Out Delivery: The order in which messages are sent and received is strictly preserved

Best for: Financial transactions, price updates, sequential command processing .


A distributed messaging system with Amazon SQS consists of three main parts :

ComponentDescription
ProducerComponents that send messages to the queue
QueueDistributed storage for messages across SQS servers
ConsumerComponents that receive and process messages from the queue

The lifecycle of an Amazon SQS message follows these steps :

1. Producer sends message → Queue stores message redundantly
2. Consumer polls queue → Message is returned (locked)
3. Consumer processes message during visibility timeout
4. Consumer deletes message → Message removed from queue

Detailed Steps:

StepDescription
1. SendA producer sends message to the queue; it’s distributed across Amazon SQS servers redundantly
2. ReceiveA consumer polls the queue and receives the message
3. LockThe message is locked (visibility timeout) preventing other consumers from processing it simultaneously
4. ProcessThe consumer processes the message according to application logic
5. DeleteThe consumer deletes the message to prevent it from being received again

When a message is received, it becomes “locked” while being processed. This prevents other computers from processing the same message simultaneously. If message processing fails, the lock expires and the message becomes available again .

Default visibility timeout: 30 seconds (configurable up to 12 hours).

Amazon SQS automatically deletes messages that have been in a queue longer than the maximum message retention period .

ParameterValue
Default retention4 days
Configurable range60 seconds to 1,209,600 seconds (14 days)

5. Step-by-Step: Creating Your First SQS Queue

Section titled “5. Step-by-Step: Creating Your First SQS Queue”
  • AWS account
  • AWS Management Console access
  1. Sign in to AWS Management Console
  2. Navigate to SQS (search in services bar)
  1. Click Create queue
  2. Select queue type:
    • Standard (default, higher throughput)
    • FIFO (message ordering, exactly-once processing)
SettingDescriptionTypical Value
Queue nameUnique identifiermy-queue (FIFO: .fifo suffix)
Visibility timeoutTime to process messages30 seconds (adjust based on processing time)
Message retention periodHow long messages persist4 days (60s - 14 days)
Delivery delayDelay before message becomes visible0 seconds (0-15 minutes)
Maximum message sizePer-message size limit256 KB (1 KB - 256 KB)
Receive message wait timeLong polling duration0-20 seconds

Step 4: Configure Dead-Letter Queue (Optional)

Section titled “Step 4: Configure Dead-Letter Queue (Optional)”
  1. Toggle Dead-letter queue to enable
  2. Select target queue (must be same type: Standard or FIFO)
  3. Set Maximum receives (e.g., 3 = move after 3 failed processing attempts)
  1. Toggle Encryption to enable
  2. Choose encryption key type:
    • AWS owned key (default, no cost)
    • AWS managed key (aws/sqs)
    • Customer managed key (your KMS key)

Click Create queue

Terminal window
# Create a standard queue
aws sqs create-queue --queue-name MyStandardQueue
# Create a FIFO queue
aws sqs create-queue --queue-name MyFifoQueue.fifo --attributes FifoQueue=true

Send a message:

  1. Select your queue
  2. Click Send and receive messages
  3. Click Send message
  4. Enter message body
  5. (FIFO) Enter Message Group ID and (optional) Message Deduplication ID

Receive messages:

  1. Click Poll for messages
  2. Messages appear in “Messages available” section
  3. Click Receive next to a message
  4. After processing, click Delete
Terminal window
# Send a message
aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue \
--message-body "Hello from CLI"
# Send with delay (FIFO example)
aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue.fifo \
--message-body "Order #12345" \
--message-group-id "Orders" \
--message-deduplication-id "order-12345"
# Receive messages
aws sqs receive-message \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue \
--max-number-of-messages 10 \
--wait-time-seconds 20
# Delete a message (using receipt handle)
aws sqs delete-message \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue \
--receipt-handle "ABC123..."
import boto3
sqs = boto3.client('sqs', region_name='us-east-1')
# Send a message
response = sqs.send_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue',
MessageBody='Hello from Python!',
DelaySeconds=10
)
print(f"Message ID: {response['MessageId']}")
# Receive messages
response = sqs.receive_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue',
MaxNumberOfMessages=5,
WaitTimeSeconds=10
)
for message in response.get('Messages', []):
print(f"Processing: {message['Body']}")
# Process the message...
# Delete after successful processing
sqs.delete_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue',
ReceiptHandle=message['ReceiptHandle']
)

Long polling reduces extraneous polling to minimize cost while receiving new messages as quickly as possible . When your queue is empty, long-poll requests wait for a specified amount of time for the next message to arrive .

BenefitDescription
Cost reductionFewer empty receive requests
Lower latencyMessages delivered immediately upon arrival
Configuration1-20 seconds (default: 0)

You can send, receive, or delete messages in batches. Batches cost the same amount as single messages, making SQS even more cost-effective for customers that use batching .

Batch APIMaximum Messages
SendMessageBatch10 messages per request
ReceiveMessage10 messages per request (max)
DeleteMessageBatch10 messages per request

Message payloads up to 256 KB are supported . For larger messages:

  • Use the Amazon SQS Extended Client Library for Java, which uses S3 to store the message payload
  • A reference to the payload is sent using SQS

SQS supports setting a specific delivery time for messages :

  • Per-message delay: Set when sending individual messages
  • Queue-level delay: Default delay applied to all messages in the queue (0-15 minutes)

When a message is received, it becomes “locked” while being processed. This is designed to keep other computers from processing the message simultaneously. If the message processing fails, the lock will expire and the message will be available again .

Amazon SQS queues can be shared:

  • Anonymously or with specific AWS accounts
  • Restricted by IP address and time-of-day
  • Via queue policies (similar to S3 bucket policies)

A dead-letter queue is a queue that other (source) queues can target for messages that can’t be processed successfully . When a message’s maximum receive count is exceeded, Amazon SQS moves the message to the DLQ associated with the original queue .

Source Queue → Message fails processing (max receives exceeded) → DLQ
StepDescription
1Consumer receives message from source queue
2Consumer fails to process and does NOT delete message
3Visibility timeout expires, message returns to queue
4Counter increments for each receive attempt
5After “max receives” threshold, message moves to DLQ
RequirementDescription
Type matchingDLQ must be same type as source queue (Standard or FIFO)
ConfigurationSet RedrivePolicy attribute on source queue
Max receivesNumber of times a message can be received before moving to DLQ

Once you’ve remediated the issues, you can move the messages from the DLQ to their respective source queues .

Use DLQs to:

  • Debug problematic messages without blocking queue processing
  • Identify and fix consumer issues
  • Prevent infinite retry loops

Amazon SQS offers server-side encryption (SSE) to protect the contents of messages .

FeatureDescription
Encryption at restMessages are encrypted as soon as SQS receives them
DecryptionSQS decrypts messages only when sent to an authorized consumer
Key managementUses keys managed in AWS Key Management Service (AWS KMS)
IntegrationAmazon KMS logs encryption key usage to CloudTrail
OptionDescription
AWS owned keyDefault, no additional cost
AWS managed keyaws/sqs key in your account
Customer managed keyYour own KMS key with custom policies

SQS provides multiple access control mechanisms :

MethodDescription
IAM policiesControl which users/roles can perform SQS actions
Queue policiesResource-based policies for cross-account access
VPC endpointsAccess SQS without traversing the public internet

Amazon SQS integrates with CloudWatch to provide queue-level metrics .

MetricDescription
ApproximateNumberOfMessagesVisibleMessages available for retrieval
ApproximateNumberOfMessagesNotVisibleMessages in flight (locked)
ApproximateNumberOfMessagesDelayedMessages delayed and not yet available
NumberOfMessagesReceivedMessages received by consumers
NumberOfMessagesSentMessages sent by producers
NumberOfMessagesDeletedMessages successfully deleted
SendMessageLatencyTime to send a message
ApproximateAgeOfOldestMessageAge of the oldest message in queue

SQS logs API calls to CloudTrail for auditing purposes, including:

  • Queue creation, deletion, and modification
  • Policy changes
  • Encryption key usage

11. SQS vs. SNS: Choosing the Right Service

Section titled “11. SQS vs. SNS: Choosing the Right Service”

Amazon SQS and SNS are both messaging services but serve different purposes .

AspectAmazon SQSAmazon SNS
PatternPoint-to-point (queue)Publish-subscribe (topic)
Message DeliveryPull-based (consumers poll)Push-based (subscribers receive immediately)
Message RetentionUp to 14 daysNo retention (real-time delivery)
Fan-outSingle consumer per messageMultiple subscribers per message
When to UseTask distribution, decouplingBroadcast notifications, alerts
FeatureSQSSNS
Messaging PatternQueue (point-to-point)Topic (publish-subscribe)
SubscribersSingle consumer per messageMultiple subscribers per message
Message PersistenceMessages stored until deletedNo persistence—real-time delivery only
Retry LogicVisibility timeout + DLQConfigurable retry policies
ProtocolsSDK, CLI, APIEmail, SMS, HTTP/HTTPS, Lambda, SQS, mobile push
ScenarioRecommended Service
One service needs to process a taskSQS
Many services need to receive the same notificationSNS
Need message durability and retrySQS
Need to broadcast real-time alertsSNS

You can combine both services for robust event-driven architectures :

Event → SNS Topic → Multiple SQS Queues → Multiple Consumer Services

Benefits of combining:

  • SNS handles fan-out to multiple subscribers
  • Each SQS queue provides durable storage and retry logic
  • Each consumer processes independently

Separate frontend and backend systems so they can scale independently .

Example: Banking application where customers receive immediate response while bill payments are processed asynchronously in the background .

Place work in a single queue where multiple workers in an Auto Scaling group scale up or down based on workload and latency requirements .

Example: Processing high numbers of credit card validation requests across multiple worker nodes .

Batch messages for future processing .

Example: Schedule multiple entries to be added to a database or process uploaded media (images, videos) while resizing or encoding .

Buffer requests during traffic spikes to prevent backend overload.

Example: E-commerce checkout system during holiday sales.

Enable components to communicate without needing to be available simultaneously.

Example: User uploads media file; downstream services process it independently when resources are available.


SQS pricing is based on requests and data transfer .

ComponentStandard QueueFIFO Queue
Requests$0.40 per 1 million$0.50 per 1 million
Data transferStandard AWS ratesStandard AWS rates

Each of the following API actions counts as one request :

  • SendMessage
  • ReceiveMessage
  • DeleteMessage
  • ChangeMessageVisibility
  • Batch variants (each message in batch counts separately)

Note: Batching messages costs the same as sending single messages, making it more cost-effective .

The AWS Free Tier includes 1 million requests per month .

StrategyDescription
Use batchingSend, receive, or delete up to 10 messages per API call
Enable long pollingReduce empty receive requests
Right-size retention periodShorter retention reduces storage costs
Delete unused queuesNo cost for queue metadata, but unused queues can be cleaned up

LimitationValue
Maximum message size256 KB
Message retention14 days maximum
Visibility timeout12 hours maximum
Delivery delay15 minutes maximum
Batch size10 messages per batch API call
CategoryPractice
DesignMake message processing idempotent to handle potential duplicates
ConfigurationSet appropriate visibility timeout based on processing time
Error handlingConfigure dead-letter queues for unprocessable messages
ScalingUse multiple consumers for increased throughput
SecurityEnable encryption for sensitive data
MonitoringSet CloudWatch alarms for queue depth and message age
CostUse long polling and batching to reduce API calls

This glossary includes key terms directly related to Amazon SQS.


At-Least-Once Delivery Delivery guarantee for standard queues where a message is delivered at least once, but occasionally more than one copy may be delivered . Consumers should be idempotent to handle duplicates.


Batch Operations API actions that send, receive, or delete up to 10 messages in a single request. Batching reduces costs as each message in a batch counts as one request .

Best-Effort Ordering Ordering guarantee for standard queues where messages might occasionally be delivered in a different order than they were sent .


Dead-Letter Queue (DLQ) A queue that receives messages from another queue when the source queue’s consumer fails to process them successfully after a specified number of receive attempts . DLQs help with debugging and prevent infinite retry loops.

Delivery Delay A configurable period (0 seconds to 15 minutes) that delays message delivery after being sent to the queue .


Exactly-Once Processing Delivery guarantee for FIFO queues where each message is delivered once and remains available until a consumer processes and deletes it, preventing duplicates .


FIFO Queue (First-In-First-Out) Queue type that guarantees strict message ordering and exactly-once processing. Messages are sent and received in the same order . Queue names must end with .fifo.

Fan-Out Messaging pattern where one message is delivered to multiple subscribers. SNS provides native fan-out; SQS with SNS enables fan-out with durable queues .


Long Polling A receive message request that waits up to 20 seconds for a message to arrive in the queue, reducing empty responses and lowering costs .


Message Group ID (FIFO) A FIFO queue attribute that groups messages within the same queue. Messages with the same group ID are processed in order; different groups can be processed in parallel.

Message Retention Period The duration (60 seconds to 14 days) that SQS stores messages before automatic deletion. Default is 4 days .

Message Visibility Timeout The period during which a received message is locked and invisible to other consumers. If not deleted within this period, the message becomes available again .


Producer A component that sends messages to an SQS queue .

Publish-Subscribe (Pub/Sub) Messaging pattern where publishers send messages to topics and subscribers receive them. SNS implements this pattern; SQS uses point-to-point .

Pull-Based Delivery A delivery model where consumers actively request messages from the queue. SQS uses pull-based delivery .


Queue A distributed storage system for messages, redundantly stored across multiple Availability Zones .

Queue Policy A resource-based IAM policy attached to an SQS queue that controls access, including cross-account permissions and IP-based restrictions .


Standard Queue Queue type supporting high throughput (nearly unlimited TPS) with at-least-once delivery and best-effort ordering .


Visibility Timeout See Message Visibility Timeout.


Amazon SQS is a foundational service for building decoupled, scalable, and fault-tolerant applications on AWS. By providing reliable message queuing without infrastructure management, SQS enables you to focus on application logic rather than message delivery concerns.

Key Takeaways:

  • Two queue types: Standard (high throughput) and FIFO (ordered, exactly-once)
  • Fully managed: No servers to provision, patch, or scale
  • Decoupled architecture: Components communicate asynchronously for better fault tolerance
  • Reliable delivery: At-least-once for Standard, exactly-once for FIFO
  • Dead-letter queues: Handle failed messages without blocking processing
  • Secure by design: Encryption at rest with KMS integration

Getting Started Recommendations:

  • Start with Standard queues for most use cases
  • Use FIFO queues when message order or deduplication is critical
  • Enable dead-letter queues for production workloads
  • Configure long polling to reduce costs
  • Set appropriate visibility timeouts based on processing time
  • Monitor queue metrics with CloudWatch alarms