Azure Cosmos DB: Latency spikes during concurrent request bursts
0 reputation · 06 Aug 2021, 18:39 UTC
0 reputation · 06 Aug 2021, 18:39 UTC
Azure Cosmos DB manages resource consumption via Request Units (RUs). When concurrent requests exceed the provisioned RU/s limit, the system returns HTTP 429 (Too Many Requests) responses to protect the database from overloading.
While these responses are expected, the interaction between high concurrency and SDK-level retry policies can introduce significant end-to-end latency. When the SDK automatically retries throttled requests, the resulting queuing behavior may manifest as a latency spike rather than an immediate failure, potentially masking the underlying throughput bottleneck.
This behavior is particularly complex in environments using autoscale throughput, where the RU/s limit fluctuates dynamically up to a defined maximum ceiling.
It is unclear how to distinguish between latency caused by physical resource contention (such as hot partitions) and latency induced by the SDK's internal retry mechanisms during transient bursts.
Your end-to-end p99 during concurrent bursts is usually not the raw server-side latency. When demand exceeds provisioned or autoscale RU/s, Cosmos DB returns HTTP 429. The SDK then retries with backoff, so client-observed p99 can include queued retries and multiple round trips even when server-side latency remains normal. There is no universal documented threshold where autoscale inevitably produces 429-induced latency; the boundary depends on your maximum RU/s, per-request cost, concurrency, and partition distribution.
Likely explanation: a retry storm. High concurrency produces many 429s; each retry adds load and delay, and the slowest requests are retried longest, inflating p99. Confirmed: Cosmos DB enforces RU/s per container or database and returns 429 when exceeded. Autoscale adjusts only within the configured maximum ceiling and cannot serve sustained instantaneous demand above it.
The single detail that changes the recommendation is the latency split between SDK retry/backoff wait and server processing. If most p99 time is client-side retry wait, tune concurrency/retry and reduce request cost. If most time is server-side and skewed toward one partition-key range, adjust capacity or partition design instead of retry settings.
Because SDK defaults and autoscale behavior evolve, verify against your current SDK version and Azure Monitor data before changing production settings.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.