Course contentsShow
← Cloud and Infrastructure
Lesson 438 of 2,9898. Managed DatabasesFree lesson

Cosmos DB Partitioning and Request Units

Choosing partition keys for horizontal scale and understanding RU-based pricing for throughput provisioning.

Cosmos DB Partitioning and Request Units

What You'll Learn

You'll discover how to choose the right partition key for horizontal scaling and understand Cosmos DB's unique throughput pricing model based on Request Units (RUs).

Partitioning: The Key to Scale

In Cosmos DB, partitioning is how your data spreads across multiple servers for virtually unlimited scale. Think of it like organizing a massive library: instead of one person searching every book, you divide books by subject so multiple librarians can work in parallel.

Your partition key is the property Cosmos DB uses to distribute data. For example, in an e-commerce app, you might partition orders by customerId. All orders for one customer stay together (enabling efficient queries), while different customers' orders spread across different physical partitions.

Choosing poorly means "hot partitions"—imagine if 80% of customers had the same ID! Always pick a key with:

  • High cardinality (many unique values)
  • Even distribution of reads/writes
  • Support for common query patterns

Request Units: Throughput as Currency

Cosmos DB doesn't charge per query or storage alone—it uses Request Units (RUs) to measure throughput. One RU equals the cost of reading a 1 KB item by its ID and partition key.

  • Writing 1 KB: ~5 RUs
  • Complex query across partitions: hundreds or thousands of RUs
  • Indexing adds overhead

You provision RUs per second (like "10,000 RU/s"), and Cosmos DB guarantees that throughput. It's like buying bandwidth: provision too little and requests get throttled; provision too much and you overpay.

Key Takeaway: Choose a partition key with high cardinality and balanced distribution, and provision Request Units based on your expected throughput—both directly impact Cosmos DB's performance and cost.