Database / Azure Cosmos DB interview questions
What are Request Units (RU/s) in Azure Cosmos DB?
Request Units (RU/s) are the currency of throughput in Azure Cosmos DB. Rather than expressing capacity in CPU cores, memory, or IOPS — which are hard to reason about at the application level — Cosmos DB normalizes all database operations into a single unit. One RU is defined as the cost of reading a 1 KB item by its partition key and ID (a point read). Every operation has an RU cost computed from CPU, memory, and I/O it consumes.
Typical RU costs to internalize:
- Point read (GET by id + partition key): ~1 RU per 1 KB
- Write (upsert/insert): ~5 RU per 1 KB (writes cost more because they update indexes)
- Query with filter on partition key: varies — simple filters may be 2-3 RU; complex cross-partition queries can be 10-100+ RU
- Cross-partition fan-out query: multiplied by number of physical partitions scanned
Provisioned throughput is set in RU/s at either the container level (dedicated throughput) or the database level (shared throughput distributed across all containers in that database). When your workload exceeds the provisioned RU/s, Cosmos DB returns HTTP 429 (Too Many Requests) responses and includes a x-ms-retry-after-ms header indicating how long to back off before retrying.
The Cosmos DB SDKs handle 429 retries automatically with exponential backoff, but you will see increased latency. To avoid this: provision adequate RU/s, use autoscale to handle peaks automatically, or distribute workload more evenly across time.
You can check the actual RU cost of any operation via the x-ms-request-charge response header or via the SDK's response diagnostics, which is the primary way to identify expensive queries and optimize them.
More Related questions...