Partitioning refers to the process of dividing a large table(data) into smaller, more manageable segments or partitions in the same instance.
Sharding involves distributing data across multiple database systems or instances. The data may be identical or distinct, depending on the specific use case. Sharding is often used to distribute data horizontally.
Sharding and partitioning often work in tandem and can be combined in various ways:
- Neither sharded nor partitioned: This occurs when there is only one database server without any division of data.
- Partitioned but not sharded: Data is split into multiple partitions, but they are on the same database instance (server).
- Sharded but not partitioned: In this scenario, there is only one partition, and the data has been replicated to other servers. This results in multiple servers (shards) containing the same data, which is how read replicas are created.
- Both sharded and partitioned: Data is divided into multiple partitions, with each partition residing on its own server (shard). This configuration can handle large write loads effectively. This is also horizontal sharding.