DEV Community

Cover image for Understanding Message Queue in a Simple Way
Moinul Islam
Moinul Islam

Posted on

Understanding Message Queue in a Simple Way

A Message Queue basically works as an intermediate storage between a Producer and a Consumer. It enables asynchronous communication, meaning two services do not need to be online at the same time for the system to work properly.

*## πŸ“Œ Figure 1 β€” Basic Message Queue Architecture:
*

Message Queue
Here, the Producer publishes messages to the queue.

Then the Consumer takes messages from the queue and processes them.

Let’s take a Food Delivery App as an example:

Step 1: A customer places an order

Step 2: The app instantly saves the order in the database and sends a message to the queue

Step 3: The restaurant service later takes the order from the queue and starts processing it

Even if the restaurant server becomes busy or temporarily down, the order will not be lost. Because the message queue safely stores the messages until they are processed.

This is what makes the system scalable and reliable.

*## πŸ“Œ Figure 2 β€” Real-Life Example
*

Message Queue

In this example, Web Servers are publishing photo processing jobs to the queue.Then Photo Processing Workers consume those jobs asynchronously from the queue.

For example, when you upload a photo on Facebook or Instagram:

  • Image resizing
  • Blur effects
  • Sharpening
  • Applying filters

These tasks are not processed instantly. The web server receives the user request and pushes the job into the queue.

Background workers then take the jobs from the queue and process them asynchronously.

One of the biggest advantages here is scalability.

When image uploads increase:

β†’ More workers can be added

When traffic decreases:

β†’ Workers can be reduced to save resources

That’s why Message Queue is such an important concept in modern microservices architecture.

SystemDesign #MessageQueue #Microservices #Scalability #SoftwareEngineering

Top comments (0)