Retention Policy

Understanding and configuring the retention policy for your Azure Event Hubs is crucial for managing data storage costs, compliance requirements, and ensuring that your applications have access to the necessary historical data. Event Hubs offers two primary retention mechanisms: time-based retention and size-based retention.

Time-Based Retention

By default, Event Hubs retains messages for a configurable period of time. Once this period expires, the messages are automatically deleted. This is the most common way to manage event data lifecycle.

How to Configure Time-Based Retention

You can set the retention policy using the Azure portal, Azure CLI, PowerShell, or SDKs.

Azure Portal:

  1. Navigate to your Event Hubs namespace in the Azure portal.
  2. Under "Settings", click on "Event Hubs".
  3. Select the specific Event Hub you wish to configure.
  4. In the Event Hub's settings blade, you will find the "Message Retention" option.
  5. Enter the desired retention period in hours or days.
  6. Click "Save".

Azure CLI:

To update the retention period for an Event Hub:

az eventhubs eventhub update --resource-group  --namespace-name  --name  --message-retention 7
            

This command sets the retention to 7 days (168 hours).

Size-Based Retention

In addition to time-based retention, Event Hubs also supports size-based retention, which allows you to limit the total size of data stored within an Event Hub. This feature is particularly useful for controlling costs in high-throughput scenarios.

How to Configure Size-Based Retention

Size-based retention is typically configured via the Azure CLI or SDKs.

Azure CLI:

To set the maximum size (e.g., 500 GB) for an Event Hub:

az eventhubs eventhub update --resource-group  --namespace-name  --name  --max-size 500
            

Note: The value is in GB. The maximum allowed value depends on your Event Hubs tier.

Important Considerations

  • Data Loss: Always ensure your retention policy aligns with your data durability and recovery needs. Accidental deletion due to misconfiguration can lead to irreversible data loss.
  • Cost: Longer retention periods and larger size limits increase storage costs. Carefully balance your requirements with budget constraints.
  • Compliance: Be aware of any industry-specific or regulatory compliance requirements that dictate how long you must retain event data.
  • Tier Limits: Retention and size limits vary across Event Hubs pricing tiers (Basic, Standard, Premium). Consult the official Azure documentation for current limits.

Choosing the Right Policy

The best retention policy depends on your specific use case: