Implementing Multi-Session Sequential Convoy Pattern with Azure Service Bus and Go

In many event-driven applications, preserving the sequence of events is essential. For example, an event-driven eCommerce application might have the following states, transitions, and events.

  1. A user adds N items to the basket. This action generates the item added event.
  2. The user checks out the basket. This action generates the basket checked out event.
  3. The user pays for the items. This action generates the payment made event.
  4. Inventory decrements the count of available items by N. This action generates the inventory updated event.

For such an application to function correctly, it is critical to maintain the sequence of events. For instance, processing the payment made event before the basket checked out event might lead to errors in billing or inventory systems. In a horizontally scalable system, we can not guarantee sequential processing of messages without creating groups of messages so that the service bus always delivers the messages within a group in sequence. The message consumer must finish processing a message and update the status of the message to the service bus before the next message in the sequence is delivered to it. Azure Service Bus supports the concept of the grouping of related messages through the message sessions feature.