Unit 4 of 8 · about 3 hours · explain
Partitioning, hot keys, rebalancing and stale writers
Moving bytes does not transfer exclusive ownership by itself. Partition placement, request routing and stale-writer rejection must agree before a rebalanced shard can safely accept effects.
You'll be able to
- Explain how range and hash partition keys trade scan locality against load distribution.
- Derive key movement and request skew for an explicit partition change.
- Trace a stale-owner write and explain what resource-enforced epochs do and do not prevent.
Covers
Read
In this order, only the parts listed
0 of 2 done
- DDIA, 2nd edition: partition placement and routingDesigning Data-Intensive Applications, 2nd edition - distributed data path
Chapter 7, Sharding by Key Range through Operations: Automatic Versus Manual Rebalancing, pp. 256 to 265; Request Routing, pp. 265 to 267
- DDIA, 2nd edition: enforcing ownership at the resourceDesigning Data-Intensive Applications, 2nd edition - distributed data path
Chapter 9, Distributed Locks and Leases, including Fencing off zombies and delayed requests and Fencing with multiple replicas, pp. 373 to 376
Focus on
- A partition key determines colocation. Range partitioning supports nearby-key scans but can concentrate timestamp writes; hashing spreads distinct keys, not repeated requests for one key.
- Separate keys-to-shards from shards-to-nodes. Fixed virtual shards avoid remapping every key when the node count changes.
- Routing metadata can be stale during transfer. Record an ownership epoch and decide when the new owner and receiving resource have installed it.
- A resource that remembers the greatest accepted fencing token rejects lower tokens only after learning the newer one. Persist that fence with the protected mutation; equal-token retries still need operation deduplication.
Common mistakes · 3
- Using Python's process-randomized string hash as a persistent partition function.
- Assuming balanced key counts imply balanced request load or that hashing can split a single hot key.
- Checking a lease only at the sender. Pauses and delayed requests can outlive that check; fencing is resource enforcement, not a clock trick or an exactly-once mechanism.
Try it yourself
Closed-book, before checking anything
[93,4,4]. Then trace writes at one shared resource with initial maximum token 7: A writes and receives OK; B installs token 8 and writes ; delayed A writes and is rejected. Remove the token check and A overwrites new. Also test A arriving before the resource sees token 8: a greatest-seen-token check still accepts 7. Check these counts and orders directly, not as a benchmark; issuance of token 8 elsewhere is not instantaneous revocation at this resource.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why does adding nodes not fix one overloaded partition key?Answer
If all requests for that key remain on one shard, its load stays concentrated. Splitting the logical key requires application aggregation or another workload-specific design.
2.What is stable when a fixed shard is moved to a new node?Answer
The key-to-shard mapping. Shard-to-node placement and routing metadata change.
3.Has issuing token 8 revoked token 7 at every resource?Answer
No. A greatest-seen-token resource must first install or observe 8, and all protected resources must enforce the fence.
4.Can token 8 be used for two duplicate increments?Answer
Yes, if equal tokens are accepted. Fencing blocks stale owners, not duplicate operations from the current owner. Deduplication needs an operation identity and atomic effect boundary.
You're done when
You reproduce both movement counts and the skew, then explain why the stale write is rejected only after the receiving resource installs the new fence.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 5 more in the section
- Designing Data-Intensive Applications, 2nd edition - distributed data pathMartin Kleppmann and Chris Riccomini · primary
Read the selected chapters on replication, partitioning, distributed-system trouble, consistency and consensus, batch processing and stream processing. For each guarantee, write its assumptions, a confirming history and one counterexample outside the boundary.
Also in this section
- Gossip Glomers - Echo, Unique ID and BroadcastFly.io and Jepsen · required
Complete Challenge 1 Echo, Challenge 2 Unique ID Generation and Challenge 3a Single-Node Broadcast. Add 3b Multi-Node Broadcast only after writing the delivery, duplicate and partition assumptions. Preserve protocol histories rather than relying on a success banner.
- MIT 6.5840 - MapReduce, RPC and consistency bridgeMIT PDOS · support
Use the introductory MapReduce, RPC, GFS and consistency lectures after the local RPC and store gates. The MapReduce lab is optional. Do not begin Raft or sharded KV as foundation work.
- Apache Kafka documentation - designApache Software Foundation · support
Read Persistence, The Consumer (Consumer Position), Message Delivery Semantics, Using Transactions, Replication and Log Compaction for a concrete log: offsets, consumer positions, the at-most-once, at-least-once and exactly-once boundaries, in-sync replicas and compaction guarantees. Map each guarantee onto your own log before trusting it.
- Building Distributed Systems from Scratch - one challenge pathBuild Distributed System · optional
Choose one messaging, durable-log or partitioning challenge that matches a failed checkpoint. State the model, failures and evidence independently because interactive grading behavior has not been verified.
- AlgoMaster System Design - distributed fundamentals sliceAlgoMaster · support
Use Database Replication, Consistency Models, Logical Clocks, Vector Clocks, Network Partitions, Split Brain Problem, Leader Election, Database Partitioning, Consistent Hashing, Delivery Semantics, Dead Letter Queues, Idempotency, Two-Phase Commit (2PC), Outbox Pattern and Streaming Engines as bounded review after DDIA. Attempt only the exercise that matches your implemented history, then challenge its assumptions with a node-loss, delay or duplicate case.