Sobes.tech
Senior

What are partitioning, replication, sharding?

sobes.tech AI

Answer from AI

This involves three different approaches to organizing and scaling data in a database:

  • Partitioning — dividing a large table into several parts (partitions) based on a specific criterion (e.g., date or value range). This helps speed up queries and simplifies data management. Partitions are usually stored in one database but are logically separated.

  • Replication — copying data from one database server to others to increase fault tolerance and distribute read load. Typically, there is a master (primary) server and one or more replicas that synchronize with the master.

  • Sharding — horizontal division of data across different servers (shards), where each server stores only a part of the data (e.g., by key range). This allows horizontal scaling of the database, increasing capacity and performance.

Example:

  • Partitioning: the orders table is divided by months.
  • Replication: the primary server handles writes, replicas handle reads.
  • Sharding: users with IDs 1-10000 on one server, 10001-20000 on another.