Modern applications don’t just write data and move on. They react to it. A new order triggers an inventory update. A profile change syncs to a search index. A deleted record kicks off a compliance workflow. Azure Cosmos DB’s change feed makes this possible by giving you a real-time stream of every change happening in your container, and it’s one of the most powerful capabilities of the platform. Today, we’re excited to announce that all versions and deletes change feed mode is generally available in Azure Cosmos DB for NoSQL! This mode gives you the full picture of what’s changing in your data, including deletes and intermediate updates that were previously invisible in the change feed.
What is all versions and deletes mode?
Azure Cosmos DB’s change feed gives you a real-time stream of changes to your data. The default latest version mode shows you the most recent state of each item after a create or update, but it doesn’t capture deletes, and if an item changes multiple times between reads, you only see the final version.
All versions and deletes mode gives you the full picture. Every create, every update, and every delete shows up in the feed with metadata that tells you exactly what happened:
- Creates and updates include the full current document plus the operation type (create or replace)
- Deletes include the item’s id, partition key, and whether it was an explicit delete or a TTL expiration
- Ordering is preserved: changes appear in the order they occurred, including intermediate versions between reads
This means you can build patterns that were difficult or impossible with the default mode: audit trails, real-time data synchronization without soft deletes, delete-triggered cleanup, and branching logic based on whether a change was a create, update, or delete.
Can I use both modes?
One of the most common questions we hear: do I have to choose one mode for my entire account? No. You enable all versions and deletes as a capability on the account, but you choose which mode to use in code per processor, trigger or pull mode iterator. You can even run both modes simultaneously on the same container with separate lease containers! For example, one processor in latest version mode syncing orders to a search index, another in all versions and deletes mode for audit logging.
When to use it
- Audit and compliance. Capture a complete record of every change, including deletes and TTL expirations, for regulatory or debugging purposes.
- Real-time sync without soft deletes. Replicate data to a secondary system and keep it accurate when items are deleted, without adding isDeleted flags and cleanup logic to your application.
- Delete-triggered workflows. Kick off downstream actions like sending notifications, cleaning up related data, or updating caches when items are removed.
- Event sourcing. Process every intermediate state change, not just the final version, to reconstruct the full history of an item.
New: Azure Functions trigger support
The easiest way to continuously process changes on a container is with an Azure Functions trigger. You write a function, point it at your container, and Azure Functions handle the rest: lease management, checkpointing, and scaling. One of the most requested features during preview was support for all versions and deletes mode in the trigger, and now it’s here! You can use the Azure Cosmos DB trigger with all versions and deletes mode in both the .NET isolated worker and in-process hosting models, with support for all other languages coming soon.
Here’s an example that processes changes on an orders container. When an order is created or updated, the function logs the order details. When an order is deleted or expires via TTL, it logs the removal:
public class Order
{
public string id { get; set; } = string.Empty;
public string CustomerId { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public decimal Total { get; set; }
}
public class OrderChangeFeedFunction
{
private readonly ILogger<OrderChangeFeedFunction> _logger;
public OrderChangeFeedFunction(ILogger<OrderChangeFeedFunction> logger)
{
_logger = logger;
}
[Function(nameof(OrderChangeFeedFunction))]
public void Run(
[CosmosDBTrigger(
databaseName: "store-db",
containerName: "orders",
Connection = "CosmosDBConnection",
LeaseContainerName = "leases",
CreateLeaseContainerIfNotExists = true,
ChangeFeedMode = CosmosDBChangeFeedMode.AllVersionsAndDeletes)]
IReadOnlyList<ChangeFeedItem<Order>> changes)
{
foreach (var change in changes)
{
switch (change.Metadata.OperationType)
{
case ChangeFeedOperationType.Create:
_logger.LogInformation(
"New order {Id} from customer {CustomerId}, total: {Total}",
change.Current.id, change.Current.CustomerId, change.Current.Total);
break;
case ChangeFeedOperationType.Replace:
_logger.LogInformation(
"Order {Id} updated, status: {Status}",
change.Current.id, change.Current.Status);
break;
case ChangeFeedOperationType.Delete:
var reason = change.Metadata.IsTimeToLiveExpired ? "TTL expired" : "deleted";
_logger.LogInformation(
"Order {Id} removed ({Reason})",
change.Metadata.Id, reason);
break;
}
}
}
}
The ChangeFeedItem<T> wrapper gives you both the document (Current) and metadata (Metadata) for each change. On deletes, Current is null but the metadata includes the id, partition key, and whether it was a TTL expiration. See the full working sample on GitHub.
If you need more control over how changes are consumed, you can also use the change feed processor for hosted applications, or the change feed pull model for on-demand reads. Both support all versions and deletes mode.
Get started
To get started, follow the steps in change feed modes to enable all versions and deletes on your account. You’ll need continuous backup enabled first, then turn on the feature from the Features page in the Azure Portal or via the REST API.
For the Azure Functions trigger, install the appropriate NuGet package for your hosting model and set CosmosDBChangeFeedMode to AllVersionsAndDeletes on the CosmosDBTrigger attribute as shown above.
What will you build?
All versions and deletes mode unlocks the full event stream from your Azure Cosmos DB container: every create, every update, every delete, with the metadata to tell them apart. We’re excited to see what you build with it!
📘 Change feed modes documentation
📘 Change feed overview
0 comments
Be the first to start the discussion.