Azure Cosmos DB for .NET Developers #4: Partition Keys Are 90% of the Game

June 02, 2026
Azure Cosmos DB for .NET Developers #4: Partition Keys Are 90% of the Game

▶ Watch this video on YouTube (opens in a new tab)

Three videos of theory, and now we finally write some code. But before the code, there's one decision that quietly runs your entire Cosmos app: the partition key.

The whole structure is four words deep — database, container, partition key, id. Easy enough. The trap is treating the partition key like a SQL primary key. It isn't. It's not unique. Identity in Cosmos is partition key plus id, together. And unlike most things you can refactor on a lazy Friday, the partition key is locked at container creation. Get it wrong and you're migrating data, not editing a line.

If you ever fought with sharding a decade ago — manually splitting data across servers and praying — this is that same idea, except automatic.

The choosing part sounds fancy ("cardinality"), but it boils down to one question: what do you actually query by? Too unique and every query fans out and bleeds money. Not unique enough and you won't scale.

Full walkthrough — including real C# against the raw SDK — is in the video.