Message Delivery Guarantee Models
This post summarises the various Delivery Guarantees available in Azure Service Bus.
A message is considered ‘settled’ or persisted to a Message Broker storage in the following scenarios:
- A Sender has successfully sent a message to the Message Broker.
- A Message Broker has successfully delivered a Message to a Receiver.
In this model, the Message Broker will try to deliver the message to the Consumer a single time. After this, the Broker is not concerned with what happens to the message. If the message is lost in transit or the Receiver fails to process a message, the message is lost.
The Message Broker pushes the message out, or the Consumer pulls the message out from the Message Broker. Once this happens the Message Broker marks this message as delivered.
In the At-Most-Once model, the Message Broker counts any messages that leave the Broker, as delivered.
In this model, the Receiver application sends an ACK response back to the Message Broker advising that the Message has been processed and should be removed from the queue. On receiving this ACK, the Message Broker will remove the message from the queue.
Different Message Brokers handle this differently, though the general principle is the same. In Azure Service Bus, for example, an ACK is sent back to the Message Broker with a complete. The Message Broker then removes the message from the queue. In other scenarios, the Receiver may choose to abandon or defer a message for later retrieval.
The Exactly-Once model is a difficult delivery model to achieve. There are algorithms such as Two-Phase Commit and Paxos and Raft that try and help solve the problem to some degree.
In the Exactly-Once model, the Message Broker attempts to deliver the message to the Receiver. With every delivery, the message is considered delivered on the premise that the Receiver has successfully processed the message on the first try.
There is no universal definition of the three delivery models; Apache Kafka, RabbitMQ and Azure Service Bus all provide vague terminology and definitions of the delivery models. For the most part, the definitions are vendor and technology-specific.