Skip to contentমূল লেখায় যান

Topic 15 · Architectureটপিক 15 · Architecture

Message Queue and Async Processing

In a busy restaurant, the waiter does not cook your meal while you wait at the counter. The waiter writes an order ticket, puts it on the kitchen rail, and goes back to the next guest. The cooks take the tickets one by one. A message queue is that ticket rail: the API writes a job, and background workers do the slow work later.

5 min read5 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 7 sources7টি সোর্স · updated Nov 2026আপডেট: Nov 2026

A queue between the API and the workersAPI আর worker-এর মাঝে একটি queue

Send a burst of jobs and see the queue fill, then drain faster with more consumers.একসাথে অনেক job পাঠান, দেখুন queue ভরে যায়, তারপর বেশি consumer থাকলে দ্রুত খালি হয়।

2 min2 মিনিট7 steps7টি ধাপ
  • Waitingঅপেক্ষায়1
  • API answerAPI-র উত্তর202
APIAPI202 Accepted202 AcceptedQueue · 1 waitingQueue · 1টি অপেক্ষায়#1 idle#1 অলসConsumers · 1কনজিউমার · 11 / 11 / 1

You’ll learnআপনি শিখবেন

  • Why a queue lets the API answer fastQueue থাকলে API কেন দ্রুত উত্তর দেয়✓
  • How a burst waits in a bufferহঠাৎ আসা job buffer-এ কীভাবে অপেক্ষা করে
  • Why more consumers drain it soonerবেশি consumer কেন queue আগে খালি করে
  • What happens when a worker crashesWorker crash করলে কী হয়
  • Which numbers to watchকোন সংখ্যাগুলো খেয়াল রাখবেন

In plain words

A message queue lets two parts of a system talk without waiting for each other. This is called asynchronous (async) communication Source 1সোর্স 1. A message stays in the queue until a worker processes it and deletes it Source 1সোর্স 1.

There are two roles. The producer adds a message to the queue. The consumer, often called a worker, takes the message and does the job Source 1সোর্স 1. In a simple queue, each message goes to one consumer Source 1সোর্স 1.

Common jobs are email, SMS, PDF generation, image resize, payment post-processing, analytics updates, and notifications.

A queue gives three benefits:

What happens when a worker fails? In Amazon SQS, a worker that receives a message makes it invisible to other workers for a time, the visibility timeout Source 4সোর্স 4. If the worker does not delete the message before the visibility timeout ends, for example because it crashed, the message becomes visible again, and another worker can try Source 4সোর্স 4. So a job can run more than once. For SQS standard queues, AWS also says that, on rare occasions, you can get the same message copy again. So your app must be idempotent: safe when it processes the same message twice Source 5সোর্স 5. See Idempotency.

Some messages fail every time, for example a job with bad data. A dead-letter queue (DLQ) is a side queue for messages that the worker cannot process Source 6সোর্স 6. It keeps them apart, so you can find out why they failed Source 6সোর্স 6. In SQS, maxReceiveCount sets how many times a worker can receive a message before it moves to the DLQ Source 6সোর্স 6.

A user request goes to the backend API. The API returns 'Processing' to the user and puts a job in the message queue. A worker takes the job from the queue and then generates a PDF, uploads it to object storage, sends an email, and updates the status.Open the image in full sizeছবিটি পূর্ণ আকারে খুলুন

সহজ English

With a message queue, two parts of a system talk and do not wait for each other. This is asynchronous (async) communication Source 1সোর্স 1. A message stays in the queue until a worker processes it and deletes it Source 1সোর্স 1.

The producer adds a message. The consumer (the worker) takes it and does the job Source 1সোর্স 1.

A queue gives three benefits:

In Amazon SQS, if a worker does not delete a message before the visibility timeout ends, another worker can try again Source 4সোর্স 4. So a job can run more than once. Your app must be idempotent Source 5সোর্স 5. A dead-letter queue (DLQ) keeps apart the messages that a worker cannot process Source 6সোর্স 6.

বাংলা ব্যাখ্যা

Message queue একটি system-এর দুটি অংশকে একে অপরের জন্য অপেক্ষা না করেই কথা বলতে দেয়। একে asynchronous (async) communication বলে Source 1সোর্স 1। একটি message queue-তে থাকে, যতক্ষণ না একটি worker সেটি process করে delete করে Source 1সোর্স 1।

এখানে দুটি ভূমিকা আছে। Producer queue-তে message যোগ করে। Consumer, যাকে প্রায়ই worker বলা হয়, message-টি নিয়ে কাজটি করে Source 1সোর্স 1। একটি সাধারণ queue-তে প্রতিটি message একটি consumer-এর কাছে যায় Source 1সোর্স 1। সাধারণ কাজের উদাহরণ: email, SMS, PDF তৈরি, image resize, payment post-processing, analytics update এবং notification।

Queue-এর তিনটি সুবিধা আছে:

  • দ্রুত উত্তর। API ধীর কাজের জন্য অপেক্ষা করে না। দীর্ঘ কাজের জন্য API সঙ্গে সঙ্গে 202 Accepted দিতে পারে। উত্তরটি একটি status endpoint দেখায়, যা client পরে আবার check করতে পারে Source 3সোর্স 3।
  • Peak সামলানো। Queue একটি buffer। অনেক request একসাথে এলেও worker-রা নিজের গতিতে message process করে Source 2সোর্স 2।
  • ধীর service থেকে সুরক্ষা। Worker বা তার পেছনের service down থাকলেও API job যোগ করতে পারে Source 2সোর্স 2।

Amazon SQS-এ একটি worker message পেলে সেটি কিছু সময়ের জন্য অন্য worker-দের কাছে invisible থাকে; এই সময়ের নাম visibility timeout। Worker এই সময়ের মধ্যে message delete না করলে (যেমন crash করলে) message আবার visible হয়, আর অন্য worker চেষ্টা করতে পারে Source 4সোর্স 4। তাই একটি job একাধিকবার চলতে পারে। SQS standard queue-তে খুব কম ক্ষেত্রে একই message-এর copy আবার আসতে পারে, তাই আপনার app-কে idempotent হতে হবে Source 5সোর্স 5। যে message বারবার fail করে, সেগুলো একটি dead-letter queue (DLQ)-তে আলাদা থাকে Source 6সোর্স 6। SQS-এ maxReceiveCount ঠিক করে, DLQ-তে যাওয়ার আগে একটি message কতবার receive করা যায় Source 6সোর্স 6।

When you need it

  • A task is slow or long-running.
  • An external service is slow or unreliable.
  • The user should get a fast API response.
  • The task needs retries.
  • Heavy tasks should run in the background.
  • You want to smooth out peak traffic.

সহজ English

Use a message queue in these cases:

  • A task is slow or takes a long time.
  • An external service is slow or not reliable.
  • The user should get a fast answer from the API.
  • The task needs retries.
  • Heavy tasks should run in the background.
  • You want to smooth out the peaks of traffic.

বাংলা ব্যাখ্যা

নিচের যেকোনো অবস্থায় message queue কাজে লাগে:

  • একটি task ধীর, অথবা দীর্ঘ সময় ধরে চলে।
  • একটি external service ধীর বা অনির্ভরযোগ্য।
  • User-এর দ্রুত API response পাওয়া উচিত।
  • Task-টির retry দরকার।
  • ভারী task-গুলো background-এ চলা উচিত।
  • আপনি peak traffic-কে সমান করে আনতে চান।

A real-life example

A student clicks Generate Certificate.

Bad design. The request waits 20 to 30 seconds. In that time the server makes the PDF, uploads it, and sends the email. If the browser times out, the student clicks again and gets two certificates.

Better design. The API puts a job in the queue and answers at once:

POST /certificates          -> 202 Accepted, Location: /certificates/c-981, { "jobId": "c-981", "status": "processing" }
GET  /certificates/c-981    -> 200 OK, { "status": "processing" }
GET  /certificates/c-981    -> 200 OK, { "status": "done", "url": "..." }

A worker makes the PDF, uploads it to object storage, sends the email, and sets the status to done. The page shows "Processing" until then.

সহজ English

A student clicks Generate Certificate.

Bad design. The request waits 20 to 30 seconds. In that time, the server makes the PDF, uploads it, and sends the email. If the browser times out, the student clicks again and gets two certificates.

Better design. The API puts a job in the queue and answers at once. The answer to POST /certificates is 202 Accepted, with a Location header that points to the status endpoint, the job ID c-981 and the status processing. The client then asks GET /certificates/c-981. The answer is 200 OK with the status processing, and later with the status done and a URL.

A worker makes the PDF, uploads it to object storage, sends the email, and sets the status to done. Until then, the page shows "Processing".

বাংলা ব্যাখ্যা

একজন শিক্ষার্থী Generate Certificate-এ click করেন।

খারাপ design। Request-টি 20 থেকে 30 সেকেন্ড অপেক্ষা করে। এই সময়ে server PDF তৈরি করে, upload করে এবং email পাঠায়। Browser time out হলে শিক্ষার্থী আবার click করেন এবং দুটি certificate পান।

ভালো design। API queue-তে একটি job রাখে এবং সঙ্গে সঙ্গে উত্তর দেয়। POST /certificates-এর উত্তর হলো 202 Accepted, সাথে status endpoint-এর দিকে নির্দেশ করা একটি Location header, job ID c-981 এবং status processing। এরপর client GET /certificates/c-981 দিয়ে জানতে চায়। উত্তর আসে 200 OK, status processing; পরে status done এবং একটি URL।

একটি worker PDF তৈরি করে, object storage-এ upload করে, email পাঠায় এবং status done করে দেয়। ততক্ষণ পর্যন্ত page-টি "Processing" দেখায়।

Common mistakes

  • No job status for the user. The user clicks, sees nothing, and clicks again. Give each job a status that the client can check Source 3সোর্স 3.
  • Retries on a job that is not safe to repeat. A message can arrive more than once Source 5সোর্স 5. Without idempotency, the student gets two emails or two certificates.
  • No dead-letter queue. A bad message fails, comes back, and fails again. It wastes worker time and hides the real error. A DLQ isolates it Source 6সোর্স 6.
  • No plan for a worker crash. If the visibility timeout is too short, a second worker starts the same job while the first one is still busy. If it is too long, retries come late Source 4সোর্স 4.
  • No queue monitoring. Watch the number of waiting messages and the age of the oldest message Source 7সোর্স 7. A growing queue means the workers cannot keep up.

সহজ English

Look out for these common mistakes:

  • No job status for the user. The user clicks, sees nothing, and clicks again. Give each job a status that the client can check Source 3সোর্স 3.
  • Retries on a job that is not safe to repeat. A message can arrive more than once Source 5সোর্স 5. If the job is not idempotent, the student gets two emails or two certificates.
  • No dead-letter queue. A bad message fails, comes back, and fails again. This wastes worker time and hides the real error. A DLQ keeps the bad message apart Source 6সোর্স 6.
  • No plan for a worker crash. If the visibility timeout is too short, a second worker starts the same job while the first worker is still busy. If the timeout is too long, the retries come late Source 4সোর্স 4.
  • No queue monitoring. Watch the number of waiting messages and the age of the oldest message Source 7সোর্স 7. If the queue grows, the workers cannot keep up.

বাংলা ব্যাখ্যা

এই সাধারণ ভুলগুলোর দিকে খেয়াল রাখুন:

  • User-এর জন্য কোনো job status নেই। User click করেন, কিছু দেখেন না, তাই আবার click করেন। প্রতিটি job-কে একটি status দিন, যা client check করতে পারে Source 3সোর্স 3।
  • যে job repeat করা নিরাপদ নয়, তাতে retry। একটি message একাধিকবার আসতে পারে Source 5সোর্স 5। Idempotency না থাকলে শিক্ষার্থী দুটি email বা দুটি certificate পান।
  • কোনো dead-letter queue নেই। একটি খারাপ message fail করে, ফিরে আসে, আবার fail করে। এতে worker-এর সময় নষ্ট হয় এবং আসল error চাপা পড়ে। DLQ এই message-কে আলাদা করে রাখে Source 6সোর্স 6।
  • Worker crash-এর কোনো পরিকল্পনা নেই। Visibility timeout খুব ছোট হলে প্রথম worker ব্যস্ত থাকতেই দ্বিতীয় একটি worker একই job শুরু করে। Timeout খুব বড় হলে retry দেরিতে আসে Source 4সোর্স 4।
  • Queue monitoring নেই। অপেক্ষমাণ message-এর সংখ্যা এবং সবচেয়ে পুরোনো message-এর বয়স খেয়াল রাখুন Source 7সোর্স 7। Queue বাড়তে থাকলে বোঝা যায়, worker-রা তাল মেলাতে পারছে না।

What a tester can check

Tutorial advice

  • Fast answer. Check that the API returns at once with a job ID and a "processing" status, not after the slow work.
  • Status flow. Poll the status endpoint. Check each state: processing, done, and failed.
  • Duplicate message. Send the same job twice. Check that the student gets one certificate and one email.
  • Worker crash. Kill a worker in the middle of a job. Check that another worker finishes it and that no half-made result stays.
  • Poison message. Send a job with bad data. Check that it lands in the DLQ after the set number of tries and that an alert fires.
  • Backlog. Send a burst of jobs. Check the queue length and the age of the oldest message, and check that the queue drains.

সহজ English

These test ideas are the tutorial's own advice.

  • Fast answer. Make sure that the API answers at once with a job ID and the status "processing". It must not answer only after the slow work.
  • Status flow. Ask the status endpoint again and again. Check each state: processing, done, and failed.
  • Duplicate message. Send the same job two times. Make sure that the student gets one certificate and one email.
  • Worker crash. Stop a worker suddenly in the middle of a job. Make sure that another worker finishes the job and that no half-made result stays.
  • Poison message. Send a job with bad data. Make sure that it goes to the DLQ after the set number of tries and that an alert fires.
  • Backlog. Send many jobs at one time. Check the queue length and the age of the oldest message. Make sure that the queue drains.

বাংলা ব্যাখ্যা

নিচের test ধারণাগুলো এই tutorial-এর নিজস্ব পরামর্শ।

  • দ্রুত উত্তর। দেখুন, API ধীর কাজ শেষ হওয়ার পরে নয়, সঙ্গে সঙ্গে একটি job ID এবং "processing" status দিয়ে উত্তর দেয় কি না।
  • Status flow। Status endpoint বারবার poll করুন। প্রতিটি state check করুন: processing, done এবং failed।
  • Duplicate message। একই job দুবার পাঠান। দেখুন, শিক্ষার্থী একটি certificate এবং একটি email পান কি না।
  • Worker crash। একটি job-এর মাঝখানে একটি worker kill করুন। দেখুন, অন্য একটি worker job-টি শেষ করে কি না, এবং কোনো অর্ধেক-তৈরি result থেকে যায় না কি না।
  • Poison message। খারাপ data দিয়ে একটি job পাঠান। দেখুন, নির্ধারিত সংখ্যক চেষ্টার পরে এটি DLQ-তে যায় কি না এবং একটি alert আসে কি না।
  • Backlog। একসাথে অনেক job পাঠান। Queue length এবং সবচেয়ে পুরোনো message-এর বয়স check করুন, আর দেখুন queue খালি হয়ে যায় কি না।

Key words

WordMeaning
Message queueA list of jobs that waits until a worker takes them
AsyncWork that runs later, so the caller does not wait for it
ProducerThe part that adds a message to the queue
Consumer (worker)The part that takes a message and does the job
202 AcceptedThe HTTP status code for "I got your request and will do it later"
Visibility timeoutThe time a received message stays hidden from other workers
Dead-letter queue (DLQ)A side queue for messages that keep failing
Queue lengthThe number of messages that wait to be processed

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    What is a Message Queue?

    AWS · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  2. [2]
    Queue-Based Load Leveling pattern

    Microsoft Azure Architecture Center · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  3. [3]
    Asynchronous Request-Reply pattern

    Microsoft Azure Architecture Center · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  4. [4]
    Amazon SQS visibility timeout

    AWS docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  5. [5]
    Amazon SQS at-least-once delivery

    AWS docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  6. [6]
    Using dead-letter queues in Amazon SQS

    AWS docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  7. [7]
    Available CloudWatch metrics for Amazon SQS

    AWS docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20