A brief introduction to Message Queue

Pragya Sapkota
3 min readNov 28, 2022

--

A message is data used when two or more parties interact. A queue is a line of things in a sequence — waiting to be looked at. Hence, a message queue is a sequential line of messages sent between applications. For a formal definition, a message queue is an asynchronous service-to-service communication used in serverless and microservices architectures. When the system is large, multiple microservices run across it and communication becomes messy. To solve the problem, a separate system — Message Queue is implemented for data communication.

The most common example of a message queue is Apache Kafka, and some others are Amazon SQS, Apache RocketMQ, JORAM, and RabbitMQ. Typically, we publish our data or the messages in them and they will automatically notify the user with data.

Characteristics of a message queue

  • Messages are stored in the queue by the producer until it is processed by the user and then deleted.
  • Each message is processed once by a single user.
  • Queues can be used for fault tolerance as well. If there is a service outrage, the requests can be re-tried.
  • A message queue can decouple heavyweight processing, provide a lightweight buffer, batch work, or smooth the spiky workloads. The applications of modern cloud architecture are decoupled into small independent building blocks. This way, they are easy to develop, deploy, and maintain. The message queue is responsible for the communication and coordination of these distributed applications.

Way of communication with message queue (step-by-step)

  1. Either create a message queue or connect to an existing one.

msgget()

2. Write in the queue.

msgsnd()

3. Read from the queue.

msgrcv()

4. Perform control operations on the queue.

msgctl()

Advantages of the message queue

1. Communication protocols are not required.

2. It can be used to quickly build new applications by reusing the building blocks.

3. Improved performance

4. Reliability

5. Scalability

6. Easy decoupling

7. Rate limiting

Conclusion

The data under the message queue are generally small and can be in any form — requests, replies, error messages, or plain information. The message stays until the user retrieves it and does something with it. Since a single message can be processed only once by a single user, a message queue is also known as “one-to-one” or “point-to-point” communications. If there is a case where the message needs to be processed by more than one user, the message queue is combined with Pub/Sub messaging in a fanout design pattern.

I hope this article was helpful to you.

Please don’t forget to applaud this article and follow me!!!

Any kind of feedback or comment is welcome!!!

You can also subscribe to my stories via email so that you’ll get notified whenever I bring out an article on a new subject.

Thank you for your time and support!!!!

Keep Reading!! Keep Learning!!!

--

--