Decoupling With Amazon SQS
Part of the AWS Roadmap
In short
When a sale starts and 10,000 orders land in a minute, your email service can't keep up. A queue lets orders pile up safely and get processed at a pace the workers can handle.
Amazon SQS is a managed message queue that lets one part of a system send work for another part to process later. Standard queues offer very high throughput with at-least-once delivery, while FIFO queues preserve order and support exactly-once processing.

Think of it like this
The dosa counter spike
Waiters jam order slips onto a metal spike. The cook pulls one, makes the dosa, pulls the next. A rush just means a taller pile, not a crashed kitchen. Waiters never wait for the cook. That spike is a queue.
Watch it happen
Orders through an SQS queue
Front of the queue is coloured
1/6The checkout service sends a message and immediately replies to the customer.
The big ideas
What you need to know
Buffer and decouple
The producer doesn't need the consumer to be up, fast or even deployed yet. Messages wait.
Visibility timeout
A received message hides for a while. Delete it when done, or it comes back for another try.
Dead-letter queue
After a set number of failed attempts, a message moves to a DLQ so one bad message doesn't block everyone.
Queue vs pub/sub
SQS gives each message to one worker. Pub/sub topics like SNS or Google Pub/Sub copy it to every subscriber.
See it in code
Walk through the code
1import json, boto32 3sqs = boto3.client("sqs")4URL = "https://sqs.ap-south-1.amazonaws.com/123456789012/orders"5 6sqs.send_message(QueueUrl=URL, MessageBody=json.dumps({"orderId": 101}))7 8resp = sqs.receive_message(QueueUrl=URL, MaxNumberOfMessages=10, WaitTimeSeconds=20)9for msg in resp.get("Messages", []):10 order = json.loads(msg["Body"])11 print("sending receipt for", order["orderId"])12 sqs.delete_message(QueueUrl=URL, ReceiptHandle=msg["ReceiptHandle"])1/4Producer side: send a message and move on.
WaitTimeSeconds=20 turns on long polling: fewer empty responses and fewer billed requests.
Save yourself the pain
Common mistakes
Oops
Deleting the message as soon as it's received, before processing.
Do this instead
Delete after the work succeeds. Otherwise a crash mid-way loses the order forever.
Oops
Setting visibility timeout shorter than the job takes.
Do this instead
Make it longer than your slowest processing time, or two workers will handle the same message.
Your mission
Feel the buffer
Quick check
A worker crashes after receiving a message but before deleting it. What happens?
Go deeper
- 1Send and receive messages with the CLI and observe the visibility timeout.
- 2Add a dead-letter queue and send a message that fails processing repeatedly.
- 3Connect SQS to a Lambda function so messages are processed automatically.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.