An e-commerce application uses an Azure Cosmos DB SQL API container named `Orders` partitioned by `/customerId`. You are implementing two new independent microservices:
* `OrderArchiver` to archive order documents to Azure Blob Storage.
* `InventoryUpdater` to update external inventory counts.
Both microservices will scale out across multiple host instances, and both are configured to use the same lease container named `leases`. During testing, you observe that when both microservices are running, each order event is processed by either `OrderArchiver` or `InventoryUpdater`, but never by both.
You need to ensure that all instances of both microservices process every event from the change feed.
What should you do?
- Configure each microservice to use a unique `processorName` when calling `GetChangeFeedProcessorBuilder`.Answer
- BSet the partition key of the `leases` container to `/customerId` to match the partition key of the `Orders` container.
- CChange the default consistency level of the Azure Cosmos DB client to Strong to guarantee that both processors read identical replicas.
- DAcquire a blob lease using the Azure Storage SDK to lock the lease container prior to starting each change feed processor instance.
Answer
Configure each microservice to use a unique `processorName` when calling `GetChangeFeedProcessorBuilder`.
The processor name parameter represents a logical group of instances (consumer group) that share the processing of the change feed. When two different workloads (like the archiver and inventory updater) share the same lease container and the same processor name, they are treated as a single consumer group. Consequently, the leases are distributed among all instances of both applications, causing each event to be processed by only one of them. Assigning a unique processor name to each microservice allows them to act as separate consumer groups, enabling both to receive a full copy of all change feed events.
Step-by-Step Solution
Key Concept
Cosmos DB Change Feed Processor Consumer Groups