AWS in 1 Min · Episode 125

Amazon SQS explained: send, receive, delete

Send, receive, delete. Watch the one-minute video, then read the details.

David Gomez1:13 video · 3 min read

"Once a worker reads a message, it's gone." Not in Amazon SQS. Reading a message only hides it for a while. The message is removed only when the worker deletes it after finishing the job. That small detail is how SQS makes sure work is not lost when a worker crashes.

What SQS is

Amazon Simple Queue Service (SQS) is a fully managed message queue. There are no servers or brokers to run, and it scales with your traffic. You create a queue, give your apps permission to use it, and pay per request.

A message is text: XML, JSON or plain text, up to 1 MiB. For bigger payloads, AWS's extended client libraries store the body in Amazon S3 and send a pointer through the queue.

The life of a message

  1. Send. A producer calls SendMessage. SQS stores the message redundantly across several Availability Zones. It keeps it for four days by default, configurable from one minute up to fourteen days.
  2. Receive. A consumer calls ReceiveMessage. SQS is pull-based: consumers ask for work. With long polling (WaitTimeSeconds up to 20 seconds) the call waits for a message to arrive instead of returning empty right away, which means fewer empty responses and a lower bill.
  3. Hide. As soon as a message is received, it becomes invisible to other consumers for the visibility timeout: 30 seconds by default, up to 12 hours.
  4. Delete. When the consumer finishes, it calls DeleteMessage. Only now is the message gone.

If the consumer crashes or takes too long, the visibility timeout expires, the message reappears, and another consumer retries it.

Common mistakes

  • Visibility timeout shorter than the job. If processing takes two minutes and the timeout is 30 seconds, a second worker picks up the same message while the first is still working. Set the timeout longer than your slowest normal job, or extend it from the worker.
  • Forgetting to delete. The job succeeds, the message comes back, and the work runs again and again.
  • Assuming exactly-once. Standard queues deliver at least once, so design workers to be idempotent. Order and duplicates are the subject of the next episode: standard versus FIFO queues.

Lambda and SQS

You don't have to write the polling loop yourself. An AWS Lambda event source mapping polls the queue, sends batches to your function, and deletes the messages when the function succeeds. It scales the number of concurrent invocations up as the queue grows.

Where AI fits

Model calls are slow and limited by quotas, so a queue in front of the model is a natural buffer. Your app sends each request to SQS and returns immediately. Lambda reads the queue and calls the model, for example on Amazon Bedrock. The event source's maximum concurrency setting (between 2 and 1,000) caps how many invocations run at once, and therefore how many model calls hit Bedrock at the same time. A spike becomes a backlog that drains at a safe pace instead of a burst of throttling errors.

Quick recap

  • Send, receive, delete: reading only hides a message.
  • The visibility timeout (30 s by default) protects work in progress; crashed work reappears.
  • Messages are kept up to 14 days (4 by default), up to 1 MiB each.
  • Lambda plus maximum concurrency turns SQS into a buffer in front of a model.
AWS in 1 Min #125 · 1:13

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS