"Just call the other service directly." It is the simplest thing to build, and it works on a quiet day. But when services are tightly coupled, each one waits on the next. If one gets slow or breaks, everything waiting on it slows down or breaks too. A queue between them changes that.
What decoupling means
In a direct call, the sender asks the receiver to do something and waits for the answer. Both must be up, fast and healthy at the same moment.
With a queue in the middle:
- The sender drops a message in the queue and moves on. The user gets a fast response.
- The receiver (often called a worker or consumer) picks the message up when it is ready.
- The two sides no longer need to be up at the same time, run at the same speed, or even know much about each other.
AWS's own example for Amazon SQS is exactly this: let users upload media quickly, and resize or encode it in the background.
What a queue protects you from
- Traffic spikes. A burst of orders or uploads lands in the queue instead of hammering the workers. They drain it at a steady pace. The backlog grows for a while, but nothing falls over.
- Crashes. If a worker dies halfway through a job, the message is not lost. In SQS it becomes visible again after its visibility timeout, and another worker retries it. Messages are kept for four days by default, up to fourteen.
- Scaling headaches. Each side scales on its own. When the queue grows, add workers; when it is quiet, remove them. Queue depth is a simple, honest metric to scale on.
The trade-offs
Decoupling is not free:
- The work becomes asynchronous. The user does not get the final result in the same request, so you need a way to report back (polling a status, a notification, a webhook).
- Most queues deliver at least once, so a message can occasionally be processed twice. Workers should be idempotent: doing the same job twice must not do harm.
- You need to watch for messages that keep failing. That is what dead-letter queues are for.
A common mistake is putting a queue in front of something that must answer the user right now, like a login check. Queues fit work that can happen a moment later.
Where AI fits
AI models are the textbook case for a queue. Calls are slow (seconds, not milliseconds) and rate limited: Amazon Bedrock sets quotas on requests and tokens per minute, and calls over your quota are rejected with a throttling error. If your app calls the model directly during a spike, users see errors.
Put the requests in a queue instead, and let workers feed the model at a pace it accepts. With AWS Lambda reading from Amazon SQS, the maximum concurrency setting on the event source caps how many invocations, and so how many model calls, run at once. The spike becomes a short wait instead of a wall of failures.
Quick recap
- A queue lets the sender drop a message and move on.
- Queues absorb spikes, and failed work is retried, not lost.
- Workers must handle duplicates, and the work becomes asynchronous.
- For AI, a queue keeps you under the model's rate limits.