Search⌘ K

Database Partitioning and Sharding in System Design

Learn how partitioning and sharding divide large databases into smaller, manageable parts to improve scalability, performance, and reliability.

As applications grow, so do their users and the amount of data they generate.

A system that once served a few hundred users may eventually need to handle millions of requests per second. This rapid growth often exposes a common bottleneck in System Design, the database. Databases must be able to store vast amounts of data, respond to queries efficiently, and remain highly available, even under heavy load or hardware failure.

Achieving this reliability and responsiveness requires thoughtful scalability strategies.

Have you ever wondered how applications like Netflix or Amazon handle millions of users simultaneously without crashing? The secret is not a single, super-powered database. Instead, these companies employ a range of effective strategies to manage and access data efficiently at a massive scale.

When a single database server can no longer handle the workload, engineers turn to effective techniques to scale the database and distribute the load.

In this lesson, we’ll explore how modern systems scale their databases through partitioning and sharding, the fundamental techniques that enable large-scale systems to remain fast, consistent, and resilient. Let’s start by understanding database partitioning.

Database partitioning

At its core, database partitioning means breaking a large database table into smaller, more manageable pieces.

Imagine a massive filing cabinet containing every customer record from the last 20 years. Finding a specific file would be incredibly slow. Partitioning is like organizing that cabinet into separate drawers, perhaps one for each year.

Now, when we need a record from 2025, we only have to search that specific drawer, making the process much faster. This all happens within a single database server.

Primarily, we have the following two strategies of partitioning the data:

  • Horizontal partitioning: This partitioning involves dividing data into smaller sub-tables horizontally, while maintaining the original schema. For example, in a database, a table with one million rows can be partitioned horizontally into two sub-tables, each with half a million rows.

An example of horizontal database partitioning
An example of horizontal database partitioning
  • Vertical partitioning: This type of partitioning alters the table schema by dividing the data vertically, thereby optimizing storage efficiency and performance. It divides a table by columns, splitting different types of information into separate tables. For example, one table holds customer details, and another stores order preferences, instead of a single table containing both.

An example of vertical database partitioning
An example of vertical database partitioning

With this basic distinction in mind, we can now look at the specific ways to partition data within a single database.

Partitioning techniques

Once we decide to partition a table, the next question is how to divide the data.

The method we choose depends entirely on our data and how we access it. Choosing the right strategy is crucial for optimal performance, as it determines how efficiently the database can locate the information it needs to access.

A poor choice ...