You are developing a microservice using the Azure Cosmos DB .NET SDK v3 to process product updates from a source container partitioned by `/productId`. The microservice is deployed as multiple instances in an Azure Kubernetes Service (AKS) cluster to handle high-throughput workloads.
You notice that when multiple instances of the service run concurrently, they all process the exact same partition updates, resulting in duplicate processing and database write conflicts in downstream services.
The microservice initializes the Change Feed Processor using the following code:
csharp
Container source = client.GetContainer("Db", "Catalog");
Container leases = client.GetContainer("Db", "LeaseStore");
ChangeFeedProcessor processor = source
.GetChangeFeedProcessorBuilder<Product>(
processorName: $"SyncProcessor-{Environment.MachineName}",
onChangesDelegate: HandleChangesAsync)
.WithInstanceName(Guid.NewGuid().ToString())
.WithLeaseContainer(leases)
.Build();
You need to ensure that the partition workload is dynamically distributed across all running replicas, and that each partition is leased and processed by exactly one instance at any given time.
Which modification should you make to resolve this issue?
- Set the `processorName` argument in `GetChangeFeedProcessorBuilder` to a constant string value shared by all host instances, and ensure the `LeaseStore` container is partitioned by `/id`.Answer
- BSet the `WithInstanceName` argument to a constant string value shared by all host instances, and keep the dynamic `processorName` argument.
- CConfigure the `LeaseStore` container to be partitioned by `/productId` to match the source container's partition key, and keep the dynamic `processorName` argument.
- DConfigure the `LeaseStore` container to be partitioned by `/SyncProcessor` to match the prefix of the dynamic processor name, and set `WithInstanceName` to a static value.