Database / Azure Cosmos DB interview questions
How does Cosmos DB pricing work and what are the key cost drivers?
Cosmos DB billing has three main components: provisioned throughput, storage, and additional features. Understanding each is essential for cost-effective application design.
1. Throughput cost — For provisioned throughput, you are billed per 100 RU/s per hour (around $0.008/hour per 100 RU/s in East US as of 2024). For autoscale, you pay for the maximum RU/s reached in any one-hour window. For serverless, you pay per million RU consumed. Throughput is the dominant cost for most workloads, making RU optimization the most impactful cost lever.
2. Storage cost — Charged per GB per month for the data stored in the container (both the document data and index storage). Index size can be significant — excluding unnecessary fields from the indexing policy reduces both write RU cost and storage billing.
3. Multi-region replication — Each additional read region multiplies your throughput cost. Writing to a 3-region account with provisioned 10,000 RU/s is billed as 30,000 RU/s equivalent. This is often the largest surprise in Cosmos DB bills for teams that add regions without considering the cost multiplier.
4. Additional features — The analytical store has separate storage pricing. Dedicated gateway has per-hour pricing per instance. Backup storage beyond the default 7-day point-in-time window incurs additional charges. Continuous backup (30-day or 7-day with point-in-time restore) costs more than periodic backup.
Cost optimization strategies:
- Use autoscale instead of manual provisioning for variable workloads to avoid idle RU cost.
- Reduce index size by excluding large text fields and rarely-queried properties.
- Use TTL to auto-delete expired data rather than accumulating storage.
- Leverage the Integrated Cache for read-heavy hot data to reduce RU consumption.
- Keep cross-partition queries to a minimum — they consume RU proportional to the number of partitions.
More Related questions...