message queue

/ˈmes.ɪdʒ kjuː/noun

A message queue temporarily stores messages until another software component processes them. The sender does not have to wait for the recipient to finish.

The online shop puts each new order in a message queue for payment and inventory processing.

A message queue helps software components work together asynchronously. The sender submits a message and continues its work. The receiving component retrieves the message when it has capacity. The components do not have to be available at the same time.

How are messages processed?

The component sending messages is called the producer. It might place an instruction to create an invoice in the queue. A consumer retrieves the instruction, carries it out and confirms that the message has been processed. A broker usually manages the queue and message delivery.

Messages are often processed in order, but this depends on the technology and settings. Some systems allow several consumers to retrieve messages simultaneously, so processing can scale when many messages arrive at once.

When should you use a message queue?

A message queue suits work that does not need to finish immediately, such as sending email, processing payments or generating documents. The queue absorbs short bursts of work and retains messages when a consumer is temporarily unavailable.

A message queue also requires additional precautions. A message may be delivered again if no acknowledgement arrives. The consumer must therefore be able to process the same message again without unwanted effects. You also need to monitor how long messages wait and decide what happens to messages that keep failing after several attempts.