Limited Time Offer:Up to 20% off Hello Interview Premium
Up to 20% off Hello Interview Premium 🎉
Hello Interview
Learn System Design
Introduction
How to Prepare
Delivery Framework
Core Concepts
Key Technologies
Common Patterns
Question Breakdowns
Networking Essentials
API Design
Data Modeling
Caching
Sharding
Quick Reference
Consistent Hashing
CAP Theorem
Database Indexing
Numbers to Know
Bitly
Dropbox
Local Delivery Service
Ticketmaster
FB News Feed
Tinder
LeetCode
WhatsApp
Rate Limiter
FB Live Comments
FB Post Search
YouTube Top K
Uber
YouTube
Web Crawler
Ad Click Aggregator
News Aggregator
Yelp
Strava
Online Auction
Price Tracking Service
Instagram
Robinhood
Google Docs
Distributed Cache
Job Scheduler
Payment System
Metrics Monitoring
ChatGPT
Real-time Updates
Dealing with Contention
Multi-step Processes
Scaling Reads
Scaling Writes
Handling Large Blobs
Managing Long Running Tasks
Redis
Elasticsearch
Kafka
API Gateway
Cassandra
DynamoDB
PostgreSQL
Flink
ZooKeeper
Time Series Databases
Data Structures for Big Data
Vector Databases
Vote For New Content
Pricing
Sign in / Sign up
Search
⌘K
Pricing

Tutor

Hello InterviewQuick Reference
Full Article
Quick Reference

Sharding

Shard Decision

When To Shard

Prove the bottleneck

Identify storage, write, or read limits before proposing sharding.

Check storage limits

A single database eventually caps out; Amazon Aurora maxes around 256 TiB.

Check throughput limits

50K writes/s or 100M DAU with many queries can justify distributing load.

Avoid premature sharding

Sharding adds shard keys, routing, hotspots, rebalancing, and consistency work.

Split Types

Partitioning splits data within one database instance to improve scans and maintenance, and Sharding splits data across multiple machines to scale storage and read/write throughput.
  • Partitioning: Splits data within one database instance; improves scans and maintenance.
  • Sharding: Splits data across multiple machines; scales storage and read/write throughput.

Shard Key

Pick high cardinality

user_id gives millions of values; is_premium gives only two.

Prefer even distribution

Avoid country if 90% of users are in the US.

Match query patterns

Common reads and writes should hit one shard, such as a user's data by user_id.

Avoid time-only keys

created_at makes all new writes hit the latest shard.

Distribution

Shard Assignment

Hash-Based Sharding is the default for most designs and evenly distributes keys but needs a resharding plan, Range-Based Sharding is simple and supports range scans but skewed ranges create hotspots, and Directory-Based Sharding is flexible for moving hot users but adds a lookup and critical dependency.
  • Hash-Based Sharding: Default for most designs; evenly distributes keys but needs a resharding plan.
  • Range-Based Sharding: Simple and supports efficient range scans, but skewed ranges create hotspots.
  • Directory-Based Sharding: Flexible for moving hot users, but every request adds a lookup and critical dependency.

Resharding Methods

Consistent hashing minimizes data movement when adding or removing shards, and Simple modulo remaps almost every record when hash key modulo N changes from 4 to 5.
  • Consistent hashing: Use with hash sharding; minimizes data movement when adding or removing shards.
  • Simple modulo: Changing hash(key) % N from 4 to 5 remaps almost every record.

Sharding Pitfalls

Hot Spots

Celebrity problem means a hot user can drive 1000x more traffic to one shard and should be isolated, Compound shard keys such as hash user_id plus date spread one hot user's data over time, and Dynamic shard splitting lets the MongoDB balancer split and migrate chunks to maintain balance.
  • Celebrity problem: A hot user can drive 1000x more traffic to one shard; isolate hot keys.
  • Compound shard keys: hash(user_id + date) spreads one hot user's data across shards over time.
  • Dynamic shard splitting: MongoDB balancer splits and migrates chunks to maintain balance.

Fan-Out Reads

Cache results stores global results for 5 minutes when real-time accuracy is not required, Denormalize data duplicates related data onto one shard for common reads, Precompute globals uses background jobs for trending content, and Accept rare fan-out allows infrequent admin totals to query and aggregate all shards.
  • Cache results: Cache global results for 5 minutes when real-time accuracy is not required.
  • Denormalize data: Duplicate related data onto the same shard to avoid common cross-shard reads.
  • Precompute globals: Use background jobs for trending content instead of querying all shards per request.
  • Accept rare fan-out: Infrequent admin totals can query all shards and aggregate.

Distributed Writes

Avoid cross-shard transactions is the best solution by keeping all of a user's data on one shard, Saga pattern coordinates multiple shards with independent steps and compensating actions, Two-phase commit guarantees consistency but is slow and fragile, and Eventual consistency works for denormalized counts that can briefly differ and converge.
  • Avoid cross-shard transactions: Best solution; keep all of a user's data on their shard.
  • Saga pattern: Use independent steps with compensating actions when multiple shards must coordinate.
  • Two-phase commit (2PC): Guarantees consistency but is slow, fragile, and usually avoided.
  • Eventual consistency: Works for denormalized counts that can differ briefly and converge.

Managed Sharding

Cassandra uses a partitioner with virtual nodes to map partition keys to token ranges, DynamoDB hashes partition keys to internal partitions and splits or merges as they grow, MongoDB uses range-based chunks with hashed shard keys as ranges over hash space, and Vitess and Citus are SQL sharding layers for MySQL or PostgreSQL that handle routing and resharding.
  • Cassandra: Uses a partitioner with virtual nodes to map partition keys to token ranges.
  • DynamoDB: Hashes partition keys to internal partitions and splits or merges as they grow.
  • MongoDB: Uses range-based chunks; hashed shard keys are ranges over the hash space.
  • Vitess and Citus: SQL sharding layers for MySQL or PostgreSQL that handle routing and resharding.

Your account is free and you can post anonymously if you choose.

Reading Progress

On This Page

Shard Decision

When To Shard

Split Types

Shard Key

Distribution

Shard Assignment

Resharding Methods

Sharding Pitfalls

Hot Spots

Fan-Out Reads

Distributed Writes

Managed Sharding

Questions
Meta SWE Interview QuestionsAmazon SWE Interview QuestionsGoogle SWE Interview QuestionsOpenAI SWE Interview QuestionsEngineering Manager (EM) Interview Questions
Learn
Learn System DesignLearn DSALearn BehavioralLearn ML System DesignLearn Low Level DesignGuided Practice
Links
FAQPricingGift PremiumHello Interview Premium
Legal
Terms and ConditionsPrivacy PolicySecurity
Contact
About UsProduct Support

7511 Greenwood Ave North Unit #4238 Seattle WA 98103


© 2026 Optick Labs Inc. All rights reserved.