Partitioning and sharding distribute data for better performance and scalability.
Partitioning vs Sharding
Partitioning: Single database, multiple tables/partitions
┌─────────────────────────────────────┐
│ PostgreSQL │
│ ┌──────┐ ┌──────┐ ┌──────┐ │
│ │2024Q1│ │2024Q2│ │2024Q3│ │
│ └──────┘ └──────┘ └──────┘ │
└─────────────────────────────────────┘
Sharding: Multiple databases
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Shard 1 │ │ Shard 2 │ │ Shard 3 │
│ Users A-I│ │Users J-R │ │Users S-Z │
└──────────┘ └──────────┘ └──────────┘
PostgreSQL Partitioning
Loading code block...
Sharding Strategy
Loading code block...
Sharded Repository
Loading code block...
Consistent Hashing
Loading code block...
Cross-Shard Joins
Loading code block...
Partitioning improves single-database performance; sharding enables horizontal scaling across databases.