AWS Builder Center
๐Ÿ“จ Day 16/30: Message Queues & Asynchronous Processing โ€” How Do Cloud Systems Handle Thousands of Tasks? โ˜๏ธ

๐Ÿ“จ Day 16/30: Message Queues & Asynchronous Processing โ€” How Do Cloud Systems Handle Thousands of Tasks? โ˜๏ธ

Discover how Amazon SQS, AWS Lambda, and Amazon SNS help cloud applications manage sudden bursts of work without making every task happen immediately. ๐Ÿš€ Follow our college examination portal as we explore message queues, asynchronous processing, retries, dead-letter queues, and reliable background tasks!

Series: Cloud Computing (25 articles)

  1. โ€ฆ
  2. 17
    ๐Ÿ“จ Day 16/30: Message Queues & Asynchronous Processing โ€” How Do Cloud Systems Handle Thousands of Tasks? โ˜๏ธ This article
Tech Enthusiast | Exploring AWS, Data Structures & Web Dev

๐Ÿ“จ Day 16/30: Message Queues & Asynchronous Processing โ€” How Do Cloud Systems Handle Thousands of Tasks? โ˜๏ธ

๐ŸŽฎ Mission 16: The Registration Rush That Almost Broke Everything!

It's 9:00 AM.
The college examination portal is ready.
CloudFront is delivering content closer to students. ๐ŸŒ
The Load Balancer is distributing incoming traffic. โš–๏ธ
Auto Scaling is adjusting the number of EC2 instances. ๐Ÿ“ˆ
AWS Lambda is processing event-driven tasks. โšก
Everything looks perfect.
Suddenlyโ€ฆ
20,000 students start registering for examinations at the same time! ๐Ÿ˜ฑ
Rahul clicks the registration button.
His friend does the same.
Thousands of students submit their forms within seconds.
But each registration triggers several additional tasks:
  • Save registration details.
  • Send a confirmation email.
  • Generate a registration receipt.
  • Update a reporting system.
  • Notify the examination department.
Our application is trying to do everything immediately.
1
2
3
4
5
6
7
8
9
10
11
12
๐Ÿ‘จโ€๐ŸŽ“ 20,000 Students
|
v
Exam Registration
|
+-----------+-----------+
| | |
v v v
Save Data Send Email Generate Receipt
| | |
v v v
Database Email Report Service
What happens if the email service becomes slow?
What if the report-generation system temporarily stops responding?
Should students have to wait for every background task before they can finish registering?
Absolutely not!
The cloud architect has a new idea:
"Let's separate the important registration request from the extra work that can happen afterward."
Welcome to Day 16 of our 30-Day Cloud Computing & Cloud Architecture Challenge!
Today, we'll discover how message queues help cloud systems handle bursts of work without forcing every task to happen immediately.

๐Ÿซ 1. Imagine a College With One Busy Office

Forget AWS for a moment.
Imagine 1,000 students arrive at the college office to submit examination forms.
The clerk receives each form and must immediately:
  1. Verify the submission.
  2. Enter the details into a computer.
  3. Print a receipt.
  4. Send a notification.
  5. Update the daily report.
The queue grows longer and longer.
Now imagine a better process.
The clerk accepts each valid form and places follow-up work into organized trays.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Students
|
v
Registration Counter
|
v
+------------------------+
| Work Queue |
| |
| Send confirmation |
| Generate receipt |
| Update report |
| Notify examination team|
+------------------------+
|
v
Staff process each task
when they are ready
The registration counter no longer has to finish every additional task immediately.
The background staff can process the queued work separately.
That is the basic idea behind a message queue.

๐Ÿ“จ 2. What Is a Message Queue?

A message queue is a mechanism for storing messages until a consumer can process them.
A message might contain information about work that needs to happen.
For example:
1
2
3
4
5
{
"eventType": "RegistrationSubmitted",
"registrationId": "REG-1042",
"task": "SendConfirmation"
}
This is an illustrative message, not a real registration record.
The application can place a message into a queue. A separate worker can retrieve the message and perform the requested task.
Conceptually:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Producer
|
| Sends message
v
+-------------------+
| Message Queue |
| |
| Task 1 |
| Task 2 |
| Task 3 |
+-------------------+
|
| Consumer retrieves message
v
Worker processes task
Let's understand the three important parts.
Producer: The component that sends a message.
Queue: The component that holds messages until they can be processed.
Consumer: The component that receives and processes messages.
Think of it like a restaurant.
  • The waiter takes an order.
  • The order ticket waits in the kitchen queue.
  • A chef prepares the food when ready.
The waiter doesn't have to stand in the kitchen until every meal is prepared!

โ˜๏ธ 3. Meet Amazon SQS

AWS provides a managed message-queuing service called Amazon Simple Queue Service (Amazon SQS).
SQS helps applications communicate through messages without requiring the producer and consumer to complete their work at the same time.
Our college portal can use SQS to buffer background work.
Here's the basic architecture:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
College Application
|
| Send message
v
+----------------+
| Amazon SQS |
| |
| Registration |
| Notifications |
| Report Tasks |
+----------------+
|
| Consumer receives message
v
Worker / Lambda
|
+--------+--------+
| |
v v
Send Email Generate Receipt
The application can submit a task and continue with its own workflow while the consumer processes the queued message.
This is called asynchronous processing.

โšก 4. What Does Asynchronous Processing Mean?

The word asynchronous sounds complicated, but the idea is simple.
It means the caller does not have to wait for the entire follow-up operation to finish before continuing.
Imagine Rahul submits his examination form.

Synchronous approach

The application waits for multiple operations:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Rahul submits form
|
v
Save registration
|
v
Send confirmation email
|
v
Generate receipt
|
v
Update report
|
v
Show final response
If one of those operations is slow, Rahul may have to wait longer.

Asynchronous approach

The application saves the registration and queues the follow-up work:
1
2
3
4
5
6
7
8
9
10
11
12
13
Rahul submits form
|
v
Validate registration
|
v
Save registration
|
v
Queue follow-up tasks
|
v
Confirm submission
Meanwhile, background workers process the queued tasks:
1
2
3
4
5
6
7
Amazon SQS
|
+----> Send confirmation
|
+----> Generate receipt
|
+----> Update report
The student can receive a registration confirmation without waiting for every background task to finish.
Important: The application should only confirm a successful registration after the required registration operation has succeeded. Queuing a message alone does not mean the registration itself has been saved successfully.

๐Ÿ—๏ธ 5. Let's Upgrade Our College Portal Architecture

Remember the architecture we built in Day 15?
We introduced AWS Lambda for event-driven tasks.
Now let's connect Lambda with SQS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
๐Ÿ‘จโ€๐ŸŽ“ Students
|
v
๐ŸŒ CloudFront
|
v
โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
v
College Application
|
+----------+----------+
| |
v v
Amazon RDS Amazon SQS
Registration Data Background Tasks
|
v
AWS Lambda
|
+------------+------------+
| | |
v v v
Confirmation Receipt Reports
Email Generation
Let's follow Rahul's request.
  1. Rahul submits his examination registration.
  2. The application validates the required information.
  3. The registration is saved in the database.
  4. The application submits a message for background processing.
  5. A worker, such as AWS Lambda, receives the message.
  6. The worker performs the requested task.
  7. The message is removed from the queue after successful processing and acknowledgment.
The exact implementation depends on the application, but the architectural goal is to keep important user-facing work separate from tasks that can run in the background.

๐Ÿšฆ 6. What Happens When 20,000 Tasks Arrive at Once?

Let's imagine that thousands of registration events create thousands of notification tasks.
Without a queue, the notification service may receive a sudden burst of requests directly.
1
2
3
4
5
6
7
20,000 Registration Events
|
v
Notification Service
|
v
Traffic Spike!
If the service cannot process the requests quickly enough, latency may increase and failures may occur.
Now introduce SQS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
20,000 Registration Events
|
v
Amazon SQS
|
v
Messages Wait Safely
|
+----+----+
| |
v v
Worker 1 Worker 2
| |
v v
Process Process
Messages Messages
The queue acts as a buffer between producers and consumers.
If messages arrive faster than workers can process them, the backlog can grow.
Workers can then process messages as capacity becomes available.
This is particularly useful during sudden traffic spikes.
However, a queue doesn't make unlimited work disappear. If messages arrive faster than consumers can handle them for a long time, the backlog continues growing. We must monitor queue depth, processing delays, errors, and consumer capacity.

๐Ÿง  7. Queues Help Reduce Tight Coupling

Here's another important benefit.
Imagine our college application directly calls three separate services:
1
2
3
4
5
6
7
Application
|
+----> Email Service
|
+----> Receipt Service
|
+----> Reporting Service
If the reporting service is unavailable, the application may need additional error-handling logic just to deal with that dependency.
Now let's introduce a queue:
1
2
3
4
5
6
7
8
9
10
Application
|
v
Amazon SQS
|
+----> Email Worker
|
+----> Receipt Worker
|
+----> Reporting Worker
The producer and consumer no longer need to be active at precisely the same moment.
The queue provides a buffer between them.
This reduces direct dependency on the immediate availability of downstream consumers.
The application can place work into the queue, and consumers can process it later.
That separation is one of the most useful ideas in distributed systems.

๐Ÿ”„ 8. What If a Worker Fails?

Now let's introduce a problem.
Our queue contains a message:
1
Task: GenerateRegistrationReceipt
Lambda receives it.
But something goes wrong.
Perhaps a temporary dependency fails.
Should the task disappear forever?
We need a way to handle processing failures.
Amazon SQS supports a mechanism called a visibility timeout.
When a consumer receives a message, the message becomes temporarily invisible to other consumers while it is being processed.
If processing succeeds and the consumer deletes the message, it is removed from the queue.
If the message is not deleted before the visibility timeout expires, it can become available for processing again.
Conceptually:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Message in Queue
|
v
Consumer receives it
|
v
Visibility Timeout
|
+----> Success
| |
| v
| Delete message
|
+----> Failure / No acknowledgment
|
v
Message may become
available again
This can help with temporary failures.
But it also introduces an important lesson: a message might be processed more than once.
Our consumer should be designed to handle that possibility.

๐Ÿ›ก๏ธ 9. The Secret Weapon: Idempotency

Imagine Rahul's registration confirmation message is processed twice.
The first time:
1
2
3
4
Send confirmation email
|
v
Email sent โœ…
The second time:
1
2
3
4
Send confirmation email
|
v
Duplicate email? ๐Ÿ˜ฑ
We don't want students to receive multiple identical confirmations just because a message was retried.
A useful design principle is idempotency.
In simple terms, an operation is idempotent when repeating it with the same input doesn't create additional unintended effects.
For example, instead of blindly creating a new receipt every time a message arrives, the worker could check a stable registration or task identifier and recognize that the receipt has already been generated.
Conceptually:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Receive Message
|
v
Check Task ID
|
+----> Already processed?
| |
| v
| Avoid duplicate effect
|
+----> Not processed
|
v
Process task
|
v
Record success
The exact technique depends on the operation and storage system.
This matters because message queues and distributed systems commonly require careful handling of retries and duplicate delivery.

โ˜ ๏ธ 10. What If a Message Keeps Failing?

Suppose one registration receipt message fails repeatedly.
Our worker retries it.
It fails again.
And again.
We don't want one problematic message to consume resources forever or repeatedly block normal processing.
This is where a Dead-Letter Queue (DLQ) can help.
A dead-letter queue receives messages that could not be processed successfully after the configured redrive policy allows the specified number of receives or attempts.
Conceptually:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Main SQS Queue
|
v
Worker
|
+------+------+
| |
v v
Success Failure
| |
v v
Delete Message Retry
|
v
Repeated Failure
|
v
Dead-Letter Queue
|
v
Investigate Problem
A DLQ helps isolate problematic messages so the team can inspect them and decide how to recover.
It doesn't automatically fix the problem.
Developers still need to investigate the cause and establish a safe process for redriving or handling failed messages.

๐Ÿ“ฌ 11. Meet Two Types of SQS Queues

Amazon SQS offers two main queue types.

Standard Queue

A Standard queue offers very high throughput and at-least-once message delivery.
Messages may occasionally be delivered more than once, and ordering is not guaranteed.
This is useful for many background-processing workloads where consumers can safely handle duplicate messages.

FIFO Queue

A FIFO queue supports first-in, first-out processing semantics and is designed for workloads that need ordering guarantees within the queue's supported model.
FIFO queues also support deduplication features, but applications must still be designed carefully around retries and side effects.
For example, the college might care about the order of certain related registration-processing events.
A FIFO queue may be worth evaluating for that kind of requirement.
The correct choice depends on whether the application prioritizes throughput, ordering, and particular delivery semantics.

๐Ÿ”” 12. SQS vs SNS: Are They the Same?

You may remember that we discussed sending notifications in Day 15.
Now you might be wondering:
"If SQS carries messages, what does Amazon SNS do?"
They solve related but different problems.
Amazon SQS is a message-queuing service. Messages wait in a queue for consumers to process them.
Amazon SNS is a publish/subscribe messaging service. Publishers send messages to a topic, and SNS distributes them to subscribed endpoints.
Imagine the examination department announces that registration has closed.
Several systems need to react:
  • Send a notification.
  • Update an analytics workflow.
  • Start a reporting task.
A publish/subscribe approach can help distribute the announcement to multiple subscribers.
Conceptually:
1
2
3
4
5
6
7
8
9
10
11
12
13
Registration Closed
|
v
Amazon SNS
|
+-----------+-----------+
| | |
v v v
SQS Queue SQS Queue Notification
Reporting Analytics Subscriber
| |
v v
Worker A Worker B
This is a simplified architecture. SNS can deliver to multiple supported subscriber types, and SQS can buffer work for independent consumers.
The key distinction:
  • SQS: Hold messages for consumers to process.
  • SNS: Distribute published messages to subscribers.
They can also be combined.

๐ŸŽฎ 13. The College Portal's New Workflow

Let's put everything together.
Rahul clicks Register for Examination.
Here's how our improved workflow might operate:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
๐Ÿ‘จโ€๐ŸŽ“ Rahul
|
v
College Application
|
v
Validate Registration
|
v
Save in RDS
|
v
Registration Saved
|
v
Send Message to SQS
|
v
Return Confirmation
Meanwhile, background processing continues:
1
2
3
4
5
6
7
8
9
10
Amazon SQS
|
v
AWS Lambda
|
+-----------+-----------+
| | |
v v v
Send Email Create Update
Receipt Report
If one background operation temporarily fails, the queue and retry strategy can help the system recover without requiring the student to submit the entire registration again.
Of course, this only works when the application correctly separates the registration transaction from the follow-up tasks and handles failures safely.
A queue can improve resilience, but it doesn't replace correct application design.

๐Ÿงช 14. Cloud Architect Challenge

You're now responsible for designing our college portal.
Let's test your knowledge!

Challenge 1: Email Service Is Slow

Thousands of students register, and the email provider is temporarily slow.
What could help separate registration from email delivery?
A. Force every registration request to wait for email delivery.
B. Place notification tasks into an SQS queue and process them asynchronously.
C. Store every email task inside the application's source code.
Answer: B. A queue can buffer notification tasks so a consumer can process them when capacity is available.

Challenge 2: The Same Message Arrives Twice

A worker receives the same receipt-generation message twice.
What should the application do?
A. Generate unlimited duplicate receipts.
B. Use idempotency or deduplication logic appropriate to the task.
C. Delete the entire queue.
Answer: B. Consumers should handle duplicate delivery safely.

Challenge 3: A Message Fails Repeatedly

What can help isolate messages that cannot be processed successfully after the configured retries?
A. A Dead-Letter Queue.
B. A larger website logo.
C. A public subnet.
Answer: A. A DLQ helps isolate problematic messages for investigation.

Challenge 4: Three Systems Need the Same Announcement

The examination department wants several independent systems to receive a registration-closed event.
Which service could distribute the event to multiple subscribers?
A. Amazon SNS.
B. Amazon EBS.
C. An EC2 instance type.
Answer: A. SNS supports publish/subscribe messaging, and it can be combined with SQS queues.

๐Ÿ—๏ธ 15. Our Complete Architecture So Far

Let's look at how far we've come in 16 days!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
๐Ÿ‘จโ€๐ŸŽ“ Students
|
v
๐ŸŒ CloudFront
|
v
โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+----------+----------+
| | |
v v v
EC2-1 EC2-2 EC2-3
| | |
+----------+----------+
|
+------+------+
| |
v v
Amazon RDS Amazon S3
Student Data Student Files
|
v
Registration Workflow
|
v
Amazon SQS
|
v
AWS Lambda
|
+--------+--------+
| | |
v v v
Email Receipt Reports
Tasks Tasks Tasks
This diagram is conceptual: the exact connections depend on the application's implementation and event flow.
Our architecture now includes multiple layers, each solving a different problem.
  • ๐ŸŒ CloudFront helps deliver cacheable content closer to users.
  • โš–๏ธ The Load Balancer distributes application traffic.
  • ๐Ÿ“ˆ Auto Scaling adjusts EC2 capacity.
  • ๐Ÿ” IAM controls access to AWS resources.
  • ๐Ÿ—„๏ธ RDS stores relational application data.
  • ๐Ÿชฃ S3 stores objects and files.
  • โšก Lambda runs event-driven code.
  • ๐Ÿ“จ SQS buffers tasks for asynchronous processing.
  • ๐Ÿ”” SNS can distribute events to multiple subscribers.
We aren't just connecting AWS services anymore. We're designing how the entire system behaves when demand increases, dependencies slow down, or individual tasks fail.

๐Ÿ† Mission Complete!

Today, Rahul's college portal learned an important lesson.
Not every task needs to happen immediately.
Some work must be completed before we confirm a registration. Other work, such as sending a confirmation email or generating a report, can often happen asynchronously.
Message queues help separate those responsibilities.
Today, we learned:
  • ๐Ÿ“จ Amazon SQS: Stores messages until consumers process them.
  • โšก Asynchronous processing: Allows follow-up work to happen independently of the initial request.
  • ๐Ÿ”„ Visibility timeout: Temporarily hides a received message while it is being processed.
  • ๐Ÿ›ก๏ธ Idempotency: Helps prevent duplicate side effects when messages are retried.
  • โ˜ ๏ธ Dead-Letter Queues: Isolate messages that repeatedly fail.
  • ๐Ÿ”” Amazon SNS: Distributes published messages to subscribers.
  • ๐Ÿง  Event-driven architecture: Connects components through events instead of requiring every component to complete work immediately.
Our college portal can now separate critical registration work from background processing.
But we still have another challenge.
What happens when our application grows so much that different parts of the system need to evolve independently?
What if registration, payments, notifications, and reporting each need different scaling strategies?
Do we keep building one giant application?
Or do we split it into smaller services with clear responsibilities?

๐Ÿš€ Coming Up on Day 17/30

๐Ÿงฉ Monolith vs Microservices โ€” Should We Build One Big Application or Many Small Services?

Our college portal is growing.
Soon, it may include:
  • Student registration
  • Examination scheduling
  • Online payments
  • Result processing
  • Notifications
  • Reporting and analytics
Should all these features live inside one application?
Or should we separate them into independently developed and deployed services?
On Day 17, we'll explore the trade-offs between monolithic and microservices architectures, using our college portal as the real-world example.
The next question in our cloud journey is no longer just how to run an application. It's how to organize an application that keeps growing.
โ˜๏ธ Build it. Secure it. Scale it. Accelerate it. Automate it. Connect it.
#CloudComputing #AWS #CloudArchitecture #AmazonSQS #AWSLambda #AmazonSNS #EventDrivenArchitecture #30DaysOfCloud

Series: Cloud Computing (25 articles)

  1. โ€ฆ
  2. 17
    ๐Ÿ“จ Day 16/30: Message Queues & Asynchronous Processing โ€” How Do Cloud Systems Handle Thousands of Tasks? โ˜๏ธ This article
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