Soru

Zorluk: OrtaConfigure Partition Keys and Partitioning Strategies in Azure Cosmos DB

A sports platform manages live match telemetry. Each match has a unique matchId. The platform stores match events (such as goals, penalties, and player substitutions) as separate documents in an Azure Cosmos DB for NoSQL container.

The application must meet the following requirements:
- Guarantee ACID compliance when executing updates on multiple event documents belonging to the same match using transactional batches.
- Avoid hot partitions during peak hours when many live matches are played simultaneously.
- Maintain high write throughput to handle real-time event ingestion.

Which property should you configure as the partition key for the container?

  1. matchIdCevap
  2. B
    eventId
  3. C
    tournamentId
  4. D
    sportType

Cevap

matchId
Configuring matchId as the partition key meets all requirements. Because Azure Cosmos DB transactional batches are scoped to a single logical partition, using matchId ensures that all events for a given match reside in the same logical partition, allowing transaction execution. Furthermore, because there are many concurrent matches, matchId provides high cardinality, which distributes write throughput (RUs) and storage requirements evenly across physical partitions, avoiding the hot partition problem.

Adım Adım Çözüm

1
Analyze the transactional requirement.
In Azure Cosmos DB, transactional batches are scoped to a single logical partition. Therefore, all items participating in the transaction must share the same partition key value.
This guarantees ACID compliance across the targeted documents.
2
Analyze the scale and cardinality requirements.
A high-cardinality key like matchId or eventId is needed to distribute writes evenly. However, eventId cannot support multi-document transactions for a single match.
Choosing a key with too low cardinality (like sportType or tournamentId) leads to hot partitions and limits scalability.
3
Select the key that satisfies both constraints.
matchId is the correct partition key.
It groups all events of a match into the same logical partition for transactions while providing sufficient cardinality across many concurrent matches to avoid hot partitions.

Anahtar Kavram

Azure Cosmos DB logical partitions serve as the boundary for both scalability (distribution) and transactions (ACID transactional batches).
Bu soruyu puanla