stackbook.io
🔍
← Back to Syllabus
Day 3Level 2 — Scale and Placement

Partitioning and Replication

Learn: 45 minMap: 30 minDesign: 55 min

Core Concepts (5)

  • 1.Partitioning splits data to scale capacity and throughput
  • 2.A partition key decides hot spots and query cost
  • 3.Replication copies data for availability and read scale
  • 4.Quorums tune consistency against latency
  • 5.Rebalancing is where partitioned systems get hurt

Map to Your Experience

Recall a table or queue that became too large for one machine. How was it split, and which queries became harder afterwards?

Design Brief: Shard and Replicate an Activity Feed

Learn

One machine eventually runs out of disk, memory, or throughput. Partitioning, also called sharding, splits data across machines so that each holds a slice. Replication keeps several copies of each slice. Partitioning scales capacity; replication scales availability and sometimes reads. Most large systems need both.

The partition key is the most consequential choice. Hashing the key spreads data evenly but makes range queries scatter across every partition. Ranges keep neighbours together, which helps scans but risks hot spots, such as all new writes landing on the latest time range. Pick the key from your dominant query, then test it against skew.

Hot keys deserve special attention. A celebrity account or a popular product can overload one partition while others idle. Mitigations include adding a random suffix to spread writes, caching the hot item, or splitting it deliberately. The right answer depends on whether the load is reads or writes.

Replication raises the question of agreement. In single leader setups, writes go to one node and flow to followers, which can lag. In leaderless setups, a write succeeds after enough replicas acknowledge it, and a read asks enough replicas to overlap with that set. If writes need W acknowledgements and reads need R, then choosing W plus R above the replica count gives overlap.

Consistent hashing reduces the data that moves when nodes join or leave, which makes rebalancing manageable. Even so, rebalancing competes with live traffic. Plan it as an operation with limits on bandwidth, a way to pause it, and clear signals that tell you it is healthy.

Map

Sketch how one of your data stores is partitioned and replicated today. Name the partition key, the replica count, and the read and write consistency level. Then list the two queries that cross partitions and estimate how often they run. Share the result with a colleague and note where their reading differs from yours.

Design

Design the feed storage for two billion events. State the partition key and why, how you handle one very popular account, the replication factor, and the quorum settings for reads and writes. Describe step by step how a node is added without hurting latency, and what you would watch while it happens. Keep the output to a single page that a peer could review in ten minutes without your help.

Requirements

  • •Choose and defend a partition key
  • •State the replication factor and read quorum
  • •Describe how a new node joins

Constraints

  • •Reads must stay under 100 milliseconds at the 99th percentile
  • •Survive the loss of one availability zone

Must Cover

partition-keyhot-keysquorumrebalancing

Trade-off Axis

consistency vs availability

Competencies Advanced

data state → L3distribution communication → L2

Ready to Design?

Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.

Open in Studio →