Azure Event Hubs Core Concepts

Understanding Consumer Groups

Consumer Groups

Consumer Groups are a fundamental concept in Azure Event Hubs that enable multiple applications or different parts of an application to read events from an Event Hub independently. Without consumer groups, only one application instance could consume events from an Event Hub at any given time.

What is a Consumer Group?

A consumer group is a view of the entire Event Hub data. Each consumer group maintains its own state with respect to the events it has consumed. This state is typically an offset (a marker indicating the position within a partition's event stream).

When you create an Event Hub, it automatically comes with a default consumer group named $Default. You can create additional consumer groups to support different consumption patterns.

Why Use Consumer Groups?

How Consumer Groups Work

Event Hubs are divided into partitions. Each consumer group reads events from all partitions within the Event Hub.

Within a specific consumer group and a specific partition, each event is delivered to only one consumer instance. The consumer group tracks the offset of the last successfully processed event for each partition. When a new consumer instance joins, it starts reading from the last known offset for that consumer group and partition.

Key Behavior

Each consumer group maintains its own independent offset track for each partition. This means that reading events in one consumer group does not affect the reading position of any other consumer group.

Creating and Managing Consumer Groups

You can create and manage consumer groups using:

When creating a consumer group, you typically give it a unique name. The maximum number of consumer groups per Event Hub varies by tier, but it's generally quite high, allowing for extensive customization.

Example Scenario:

Imagine an Event Hub named order-events. You might have the following consumer groups:

Each of these consumer groups can read the same order-events stream at their own pace, from their own starting point (offset), without impacting the others.

Consumer Group Limits

While flexible, there are limits to the number of consumer groups you can create per Event Hub, depending on your Azure Event Hubs pricing tier.

Understanding and effectively utilizing consumer groups is crucial for building robust, scalable, and decoupled event-driven architectures with Azure Event Hubs.