The Web: Message queue

The Web: Message queue

Introduction

In the previous article , I explained what is caching and when to use it.

Goal

By the end of this article you should be able to understand message queue and its importance

Let's delve in

Message queue

Message queuing allows applications to communicate by sending messages to each other. The message queue provides temporary message storage when the destination program is busy or not connected.

In a microservice or cloud architecture, where systems are decoupled into smaller independent modules and the modules need to communicate with each other, a message queue is very important.

A queue is a middleware where messages from a producer application are stored for the consumer application to pick up for processing.

The producer application generates a message and send it to the message queue where the message stays till the consumer application is ready to pick up the message and process it after which the message is deleted from the queue

This allows different part of a huge system to be written in different languages and managed separately by different teams and this is often times a sign of a good design architecture.

A use case for using a message queue

Imagine you have a web service that receives many requests every second and all requests need to be processed but the processing is time-consuming and your web service has to be highly available and ready to receive other new request instead of being locked by the processing of previously received requests. In this case, it is ideal to put a queue between the web service and the processing service. Messages or requests in the queue will be persisted and the server can handle them in the order it wants or a load balancer can route the messages to the appropriate server while other process can be running asynchronously.

Some message queue solutions