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.
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...
