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.
More Related questions...