Database / Azure Cosmos DB interview questions
What is Cosmos DB Integrated Cache and how does it reduce RU consumption?
The Cosmos DB Integrated Cache is a server-side in-memory cache built into the dedicated gateway tier. When enabled, it caches the results of point reads and queries at the gateway layer so that repeated identical requests can be served from memory without going to the backend storage partitions — meaning those cached responses consume 0 RU/s.
This is fundamentally different from a client-side cache (like Redis). Client caches are application-managed: you maintain cache keys, TTLs, and invalidation logic in your code, and every new application instance starts with a cold cache. The Integrated Cache is managed by Cosmos DB itself, is shared across all clients connecting through the same gateway, and is warm for the first client that populates it.
How it works:
- A client sends a read request through the dedicated gateway.
- The gateway checks its in-memory cache for a matching item or query result.
- On a cache hit, the response is returned immediately — 0 RU consumed.
- On a cache miss, the backend is queried normally, the result is cached, and RU is charged as usual.
Cache invalidation is automatic: when an item is written or modified, its cached entry is invalidated. The cache respects the consistency level — if you use Session or Eventual consistency, the gateway may serve slightly stale responses (by design for those levels), which improves hit rates. Strong consistency is not compatible with the Integrated Cache.
The Integrated Cache requires using the dedicated gateway tier (not the direct connectivity mode) and is best suited for read-heavy workloads where the same data is requested repeatedly — leaderboards, product catalogs, configuration data, or user profiles with hot-spot access patterns.
More Related questions...