Database / Azure Cosmos DB interview questions
What is the difference between a point read and a query in Cosmos DB?
A point read is the most efficient read operation in Cosmos DB. It fetches a single item by specifying both the item's id and its partition key value exactly. Cosmos DB can route this operation directly to the specific replica holding that item without scanning any index. The RU cost is approximately 1 RU per 1 KB of document size, regardless of the container size.
A query uses the SQL-like query language to filter items based on conditions. Even a simple query like SELECT * FROM c WHERE c.id = 'abc' is more expensive than a point read because it goes through the query processor, which must parse the query, check indexes, and return a result set. If the query includes the partition key in the filter (WHERE c.userId = 'u123'), it is a single-partition query and stays on one physical partition. If it omits the partition key or queries across multiple partition values, it becomes a cross-partition query that fans out to every physical partition — potentially costing 10x or more depending on the number of partitions.
| Aspect | Point Read | Query |
|---|---|---|
| SDK call | container.ReadItemAsync(id, partitionKey) | container.GetItemQueryIterator(queryDef) |
| Routing | Direct to owning replica | Via query processor; may fan out |
| Typical RU cost | ~1 RU / 1 KB | 2 RU+ depending on complexity |
| Index required | No (key-based lookup) | Yes for efficient filtering |
| Use when | You know both id and partition key | You need filtered/sorted results |
The practical implication: design your application to use point reads wherever possible. If you frequently look up items by a non-id property, consider denormalizing data or creating a separate lookup container so the hot path can use a point read rather than a query.
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...
