AWS Builder Center

Your Application Is Getting Too Much Traffic. Amazon SQS Can Help.

What happens when requests arrive faster than your application can handle them? Explore how message queues absorb traffic spikes, distribute workloads, and prevent temporary failures from bringing an entire application down.

I am a student pursuing BTech in Computer Science
Imagine you've built an online shopping application.
Everything works perfectly during testing. Users can browse products, place orders, and receive confirmations. Then, one day, your application gets a sudden spike in traffic.
Thousands of customers place orders within a short period. Your application tries to process everything immediately: save order details, update inventory, generate invoices, send emails, and notify the shipping service.
Some requests become slow. Others time out. Your database starts struggling, and suddenly a traffic spike becomes an application outage.
The problem isn't necessarily that your application is poorly written.
The problem might be that your application is trying to do too much at once.
This is where message queues become incredibly useful.
With Amazon Simple Queue Service (Amazon SQS), you can separate incoming requests from the work that needs to happen afterward. Instead of forcing every component to finish immediately, you can distribute work across independent consumers.
Let's understand how this works and how AWS makes it possible.

1. Why Do Applications Need Message Queues?

Consider two approaches to handling an order.

The traditional approach: Synchronous processing

A client sends an order request to your backend.
The backend validates the order, writes to the database, generates an invoice, sends an email, and communicates with other services before responding.
Every additional operation can increase the response time.
Worse, if an email service is temporarily unavailable, your entire request might fail even though the order itself was successfully created.

The queue-based approach: Asynchronous processing

Now imagine introducing a message queue.
The backend validates the request, saves the order, and publishes a message describing the work that needs to happen.
A separate worker retrieves that message and processes it independently.
The flow becomes:
Client → Backend API → Message Queue → Background Workers
The client no longer needs to wait for every background operation to finish.
This is called asynchronous processing.
The important distinction is that the queue does not magically make your workers faster. It helps your application absorb incoming work and process it at a manageable rate.

2. Meet Amazon SQS

Amazon SQS is a fully managed message queuing service provided by AWS.
It allows different components of an application to communicate without requiring them to be available at exactly the same time.
There are two main types of queues:

Standard queues

Standard queues are designed for high scalability and throughput.
They provide at-least-once message delivery, which means a message may occasionally be delivered more than once.
Message ordering is not guaranteed.
They are useful for workloads where messages can be processed independently and occasional duplicate delivery can be handled safely.

FIFO queues

FIFO stands for First-In-First-Out.
These queues preserve message ordering within a message group and provide deduplication features.
They are useful when processing order matters, such as workflows that require sequential handling of related operations.
An important design decision is choosing the correct queue type before building your application. AWS does not let you simply convert an existing standard queue into a FIFO queue.

3. Let's Design a Real-World Application

Let's return to our shopping application.
Whenever a customer places an order, several operations need to happen:
  • Save the order.
  • Generate an invoice.
  • Send an order confirmation email.
  • Notify the shipping system.
  • Update relevant analytics.
Not every operation needs to happen before the customer receives a response.
We can introduce Amazon SQS between the application responsible for accepting orders and the services responsible for background processing.
Our architecture looks like this:
Order API → Database + SQS → Worker Services
The API validates and records the order. It then publishes a message containing information such as:
{
"eventId": "evt-1042",
"eventType": "ORDER_CONFIRMED",
"orderId": "ORD-1042",
"timestamp": "2026-11-02T10:30:00Z"
}
The message contains an order identifier rather than the entire customer record.
Different workers can retrieve the work and perform their respective tasks.
For example:
  • An invoice worker generates the invoice.
  • A notification worker sends the confirmation email.
  • A shipping worker prepares the shipment request.
This separation makes individual components easier to maintain and scale.
One important detail: in a production system, publishing the message and saving the database record must be coordinated. A database transaction could succeed while the queue operation fails. The transactional outbox pattern is one way to address this problem.

4. How Does Amazon SQS Actually Process Messages?

Understanding the message lifecycle is important.
A message does not disappear from a queue the moment a consumer retrieves it.
Instead, SQS uses something called a visibility timeout.
Let's understand it through an example.
Suppose a worker receives a message from your order-processing queue.
For the duration of the visibility timeout, that message becomes temporarily invisible to other consumers.
The worker processes it and, after successful completion, deletes the message from the queue.
But what happens if the worker crashes?
The message becomes visible again after the visibility timeout expires and can be processed again.
This mechanism helps prevent messages from being permanently lost simply because a consumer failed during processing.
The default visibility timeout is 30 seconds, and it can be configured up to 12 hours.
However, visibility timeouts must be chosen carefully. If processing takes longer than the configured timeout, another consumer might receive the same message while the first worker is still working.
For more information, read the  official AWS visibility timeout documentation .

5. What Happens When a Message Keeps Failing?

Consider a message containing invalid order information.
Your worker tries to process it, encounters an error, and fails.
SQS makes the message available for another attempt.
But what happens if the same message fails five, ten, or even twenty times?
Repeatedly retrying a message that cannot be processed wastes resources and can slow down other work.
AWS provides a solution called a Dead-Letter Queue (DLQ).
A dead-letter queue is a separate queue that receives messages after they exceed a configured number of unsuccessful receive attempts.
For example:
  1. A message enters the main queue.
  1. A worker attempts to process it.
  1. Processing fails.
  1. The message becomes available for another attempt.
  1. After the configured receive threshold is exceeded, SQS moves it to the DLQ.
Developers can then inspect the failed messages, identify the underlying issue, and decide whether they can safely be retried.
This is especially useful when dealing with malformed data, unexpected application errors, and unavailable dependencies.
A DLQ doesn't automatically fix failed messages. It gives you a controlled place to investigate them instead of allowing them to circulate forever.
AWS explains this mechanism in its  Dead-Letter Queue documentation .

6. Connect Amazon SQS with AWS Lambda

One interesting thing about SQS is that you don't need to maintain a permanently running server just to process messages.
You can integrate an SQS queue with AWS Lambda.
The architecture becomes:
Application → Amazon SQS → AWS Lambda → Processing Logic
Here's how it works:
  1. Your application publishes a message to SQS.
  1. Lambda polls the queue through an event source mapping.
  1. Lambda receives a batch of messages.
  1. Your function processes the messages.
  1. Successfully processed messages are removed from the queue.
You can configure batch sizes and other parameters to control how messages are delivered to the function.
This also introduces an important consideration: when a batch fails, messages that were successfully processed might also be retried by default.
You can avoid unnecessary reprocessing by configuring partial batch responses. This allows Lambda to identify individual failed messages instead of treating the entire batch as unsuccessful.
For detailed instructions, explore the  AWS Lambda and SQS integration guide .

7. Three Mistakes Developers Should Avoid

Using a message queue improves flexibility, but it also introduces some responsibilities.
Mistake 1: Assuming messages are processed exactly once.
Standard SQS queues provide at-least-once delivery. Duplicate messages are possible.
Design your processing logic to be idempotent. For example, before generating an invoice, check whether an invoice for that order has already been created.
A repeated message should not result in multiple payments or duplicate invoices.
Mistake 2: Choosing an inappropriate visibility timeout.
If the timeout is too short, another worker might receive a message before the original worker finishes processing it.
If it is too long, failed messages may take unnecessarily long to become available again.
For Lambda-based SQS processing, AWS recommends configuring the queue's visibility timeout to at least six times the function timeout.
Mistake 3: Treating the queue as unlimited storage.
SQS is designed for messaging, not as a replacement for a database or object storage service.
Avoid placing large files or unnecessary amounts of data inside messages. Store the actual files in Amazon S3 and pass their identifiers or object references through the queue.
Also monitor how quickly messages are being processed. A growing backlog is a signal that your consumers might not be keeping up with incoming work.

8. Monitor Your Queues, Not Just Your Application

A queue can appear healthy even when messages are waiting too long to be processed.
This is why monitoring is important.
Amazon CloudWatch provides metrics that help developers understand queue behavior.
Some useful metrics include:
  • ApproximateNumberOfMessagesVisible: Messages currently available for processing.
  • ApproximateNumberOfMessagesNotVisible: Messages currently being processed or awaiting deletion.
  • ApproximateAgeOfOldestMessage: How long the oldest available message has been waiting.
  • NumberOfMessagesSent: Messages successfully added to the queue.
  • NumberOfMessagesDeleted: Messages successfully deleted after processing.
Pay special attention to the age of the oldest message.
A steadily increasing queue backlog might indicate that incoming traffic is exceeding your processing capacity.
You can use this information to increase consumer concurrency, investigate slow processing, or improve the efficiency of your workers.
The objective is not simply to make sure messages enter the queue. It is to make sure they leave it successfully and within an acceptable amount of time.

9. When Should You Use Amazon SQS?

Message queues are useful in many different applications.
Here are a few examples:
E-commerce: Process order confirmations, invoice generation, and shipping notifications asynchronously.
Image processing: Accept image uploads and distribute resizing or optimization jobs to background workers.
Data pipelines: Buffer incoming records before sending them to processing services.
Notification systems: Handle large volumes of email or notification requests without slowing down the primary application.
Microservices: Allow independent services to communicate without requiring all of them to be available simultaneously.
However, a queue isn't necessary for every operation. If a client needs an immediate response or the operation must be completed before proceeding, synchronous communication may still be the better choice.
The best architecture is the one that matches the actual requirements, not the one containing the largest number of AWS services.

Final Thoughts

One of the biggest challenges in software engineering isn't handling a request when everything works normally. It's handling unexpected traffic, failing dependencies, slow consumers, and operations that take longer than expected.
Amazon SQS offers a practical way to address these problems by separating the arrival of work from its execution.
It allows applications to distribute workloads, manage retries, and recover from temporary failures without forcing every component to operate at the same speed.
The most important lesson is simple:
Don't make every component wait for every other component. Design systems that can handle work independently.
A message queue might look like a small addition to your architecture, but it can fundamentally change how your application behaves under pressure.
And sometimes, the best way to make an application faster is to stop making it do everything immediately.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article