Skip to main content
Database sharding is one of the most important concepts in scalable systems and a frequent system-design interview topic. Before describing how to shard, it helps to understand the signals that indicate a single database is no longer sufficient.
A dark-themed illustration showing four orange-outlined database shards (labeled Shard 01–04) partially filled, with the word "SHARDING" beneath them. Below that are simple interviewer and candidate icons, the interviewer asking in a speech bubble, "How would you shard this?"
Real-world example — the story of Chirp
  • John and Alan launch a simple social app, Chirp: users sign up, post short public messages, and follow each other.
  • Day 1: one app server and one database serve a few hundred users. The team focuses on features and user growth, not scaling.
What is the database doing for Chirp?
  • Chirp’s data is stored in structured tables: a Users table (one row per user) and a Chirps table (one row per post).
  • Reads: fetching data — opening a profile or viewing a feed.
  • Writes: creating or updating data — posting a Chirp, following someone, incrementing counters.
As Chirp grows, the single-database setup begins to show limits. Scaling the single instance
  • At 200 users, a standard instance is fine.
  • At thousands, the team upgrades to larger machines (vertical scaling).
  • At millions of users, vertical scaling runs into practical and cost limits: providers may not offer larger instances, or costs spike sharply.
A stylized "Scaling Up" diagram showing a mobile app feed on the left, an app server in the middle, and a database on the right with example user and chirp tables. It notes "users 200" and uses arrows to show data flow between the phone, server, and database.
Symptom: slow reads
  • As more clients request data concurrently, read queries queue up and latency increases.
  • Example: a profile view that was ~30 ms can slow to ~3 seconds as the single database becomes overloaded.
A diagram titled "Slow Reads" showing a mobile profile screen on the left, many users' requests hitting app servers in the middle, and queries piling up to a large database on the right. A progress bar under the phone shows "Open a profile" taking 3.0 s.
Short-term relief: replicas
  • Industry best practice avoids relying on a single machine: add read replicas.
  • A replica is a copy of the primary database. It provides:
    • High availability (a replica can be promoted if the primary fails)
    • Read scaling (replicas serve read-only queries)
Load-balancing read traffic across replicas reduces read latency for profiles and feeds.
A stylized diagram showing a mobile app on the left connecting to an app server and a load balancer that spreads read traffic to a primary database and two replica databases on the right. The image is titled "Replicas" and includes a sample UI and a 1.7s "Open a profile" timing.
Read replicas are commonly asynchronous: the primary applies writes, then changes are replicated to replicas. This can introduce replication lag, meaning a replica’s data may be slightly behind the primary for a short period.
Why replicas don’t solve write scaling
  • All writes must go to the primary to maintain a single source of truth.
  • High write volume (tens of thousands of posts per minute) concentrates on the primary, producing throughput limits, slow writes, or failed writes during spikes.
A stylized architecture diagram titled "Slow Writes" showing users with mobile apps connecting to an app server that routes through a load balancer to a primary database and two replicas. The primary database is annotated with metrics: 8,412 saved and 137 dropped, highlighting write performance issues.
Consistency example (why writes must be centralized)
  • Imagine a post shows 99 likes. Chris and Martin like it simultaneously.
    • If Chris’s like is processed by the primary and updates to 100, a replica that hasn’t applied that update yet will still show 99.
    • If Martin’s like is routed to that lagging replica and increments locally to 100, the system reports conflicting totals (both 100) even though the true total should be 101.
  • Without a single authoritative writer, independent updates on different machines cannot be deterministically reconciled.
A stylized diagram showing a mobile app talking to an app server and load balancer that routes read traffic to multiple database replicas while all writes go to a single primary database. The image is labeled "Writes hit primary machine" with the note "Reads got easier. Writes did not."
Because the primary must accept every write to guarantee consistency, write throughput and concurrency are limited by the primary machine. When write latency or errors rise despite vertical scaling and replication, it’s time to consider horizontal partitioning (sharding).
When to consider sharding
  • Horizontal scaling (sharding) splits your data across multiple smaller database instances so both reads and writes can be distributed.
  • Typical triggers for sharding:
    • Sustained write throughput exceeds primary capacity.
    • Read replicas cannot keep up (replication lag causes user-visible inconsistencies).
    • Cost or availability limits prevent further vertical scaling.
Quick reference — symptoms and actions Next step: sharding
  • When a single primary is the bottleneck and replicas no longer provide enough headroom, the natural next step is horizontal partitioning: split the database into multiple independent shards. Sharding distributes both reads and writes across many machines, reducing the load on any single primary and enabling larger overall throughput.
Further reading and references

Watch Video