Database / Azure Cosmos DB interview questions
What is the Cosmos DB Bulk Executor and how do you use bulk operations in the SDK?
Bulk operations in Azure Cosmos DB allow you to send multiple create, upsert, replace, delete, or read operations in a single SDK call that the library optimizes internally — batching by partition, retrying 429 throttles automatically, and maximizing throughput by saturating available RU/s concurrently. This is far more efficient than issuing individual operations in a loop because each individual await creates a round-trip overhead and underutilizes provisioned throughput.
In the v3 .NET SDK, bulk execution is enabled by setting AllowBulkExecution = true on the CosmosClientOptions. Once enabled, you can create a list of tasks and await them all together — the SDK transparently groups them into optimized batches per partition:
CosmosClient client = new CosmosClient(endpoint, key,
new CosmosClientOptions { AllowBulkExecution = true });
Container container = client.GetContainer("mydb", "mycontainer");
List<Task> tasks = new List<Task>();
foreach (var item in itemsToUpsert)
{
tasks.Add(container.UpsertItemAsync(item, new PartitionKey(item.PartitionKey)));
}
await Task.WhenAll(tasks);
Internally the SDK groups operations by partition key, packs them into micro-batches that fit within the 2 MB request limit and 100-operation transactional batch limit, and dispatches multiple batches concurrently. It handles 429 retries with the retry-after delay automatically so your code does not need to implement backoff logic manually.
For Java and Python SDKs, similar bulk APIs exist. In Java the CosmosBulkOperations builder pattern is used. Bulk mode is best for initial data loads, migrations, large backfills, or any scenario where you need to insert or update tens of thousands of items quickly.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
