Skip to content
Glossary · System design

Sharding

Also called horizontal partitioning, database sharding.

Definition

Splitting one large dataset across several databases, called shards, by a key such as customer ID, so each shard holds only part of the data.

Last updated

What it is.

Each row belongs to one shard, chosen by a shard key. For example, customers 1 to 1,000 on shard A and the rest on shard B, or by a hash of the customer ID. The app, or a routing layer, sends each query to the right shard.

Sharding spreads both storage and write load, which a read replica cannot do. In exchange, queries across shards, joins and moving data between shards all get harder.

Why it matters

Sharding lets a database grow past what one machine can handle. It is also a big, lasting design choice. Most products never need it, and those that do want a shard key that matches how data is used, often the tenant in multi-tenant SaaS.

In a product build

We design data so that a natural shard key exists, such as a tenant ID on every table, even when we start on one database. That keeps sharding possible later without rewriting the data model. Before sharding we use indexes, caching, replicas and a bigger primary first.

Watch out

Common mistakes.

  1. 01

    Sharding too early, adding complexity years before it is needed.

  2. 02

    Picking a shard key that most queries do not use, so they hit every shard.

  3. 03

    Hot shards, where one huge customer or date range takes most of the load.

Related

Related terms.

Building something with this? Ask an engineer.

OceanLab designs and builds production software. Tell us what you are planning and we will reply with how we would approach it.

OceanLab

Enterprise Software Engineering - Human + AI

Languages

Locations

Global Headquarters

21 Merchant Road, 3rd Floor, Singapore 058267

Main corporate office and leadership operations

North America Office

548 Market Street, PMB 12472, San Francisco, CA 94104

Client operations and business development

India Office

402 Shivalik Shilp II, SG Highway, Ahmedabad 380015

Engineering and delivery center

© 2026 - Copyright. All Rights reserved OceanLab