The message queue
A message queue, or technically a FIFO (First In First Out) queue is a fundamental and
well-studied data structure. There are different queue implementations such as priority
queues or double-ended queues that have different features, but the general idea is
that the data is added in a queue and fetched when the data or the caller is ready.
Imagine we are using a basic in-memory queue. In case of an issue, such as power
outage or a hardware failure, the entire queue could be lost. Hence, another program
that expects to receive a message will not receive any messages.
However, adopting a message queue guarantees that messages will be delivered to
the destination no matter what happens. Message queuing enables asynchronous
communication between loosely-coupled components and also provides solid queuing
consistency. In case of insufficient resources, which prevent you from immediately
processing the data that is sent, you can queue them up in the message queue server
that would store the data until the destination is ready to accept the messages.
Message queuing has an important role in large-scaled distributed systems
and enables asynchronous communication. Let's have a quick overview on
the difference between synchronous and asynchronous systems.
In ordinary synchronous systems, tasks are processed one at a time. A task is
not processed until the task in-process is finished. This is the simplest way to
get the job done.