Understanding Service Bus Partitioning
  • 17 May 2022
  • 1 Minute to read
  • Contributors
  • Comments
  • Dark
    Light
  • PDF

Understanding Service Bus Partitioning

  • Comments
  • Dark
    Light
  • PDF

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

In 2013 Microsoft introduced the partitioning of an Azure Service Bus queue or topic to provide users with more reliability and higher message throughput. With partitioning of a queue or topic messages will be handled by multiple message brokers and stored in various messaging stores.

By creating a queue or topic in a Service Bus namespace in the Azure Portal, you will see the option of ‘enabling partitioning’. A partitioned queue or topic consists of multiple so-called fragments – each fragment is stored in a different messaging store can be handled by a different messaging broker.

Azure Service Bus Tip 06 - Picture 1.png

When for instance an application sends a message to a partitioned queue, the Azure Service Bus assigns the message to one of the fragments in random order (round-robin) in case no partition key is set. However, in case there is a partition key specified by the sender to support transactions or sessions (first-in, first-out scenario) then the Service Bus will send the messages to a specific fragment using the key; which can be SessionId, PartitionKey or MessageID message property.

With SessionID message property set and not a PartitionKey message property the Service Bus will use that property for partition key and assign all messages with the same SessionID to the same fragment – and thus the same message broker will handle all the messages in order. Moreover, when PartitionKey message property is set, and SessionID is not, the Service Bus will use that property for the partition key and again all messages with the same value for the PartitionKey will end up in the same fragment. And finally, when setting the MessageID property for messages going to a partitioned queue or topic with duplicate detection enabled, the Service Bus will use that property as the partition key and thus sending messages with the same id to the same fragment allowing duplicate detection by the message broker handling the fragment.

Lastly, a receiver (client) listening to the partitioned queue or topic the Service Bus will check the fragments for messages and pick and pass them to the receiver. Furthermore, note that partitioning of queues and topics is not possible within the premium tier and you can only set partitioning when creating a queue or topic (for more details see partitioning limitations).

Also, get insights into Azure Service Bus messaging issues and improve monitoring.

Service Bus-2


Was this article helpful?