Database Partitioning vs Sharding
🔹 What is Database Partitioning? Partitioning means splitting a large table into smaller pieces ( partitions ) to make queries faster and maintenance easier. Importantly, all partitions live inside the same database instance . Types of partitioning: Horizontal partitioning : Splits data by rows (e.g., orders by year). Vertical partitioning : Splits data by columns (e.g., frequently used vs. rarely used columns). ✅ Good for performance tuning when data still fits on one server. 🔹 Partitioning in Action (PostgreSQL Example) Imagine an orders table with millions of rows. We want to split it by year. Step 1: Create a partitioned table CREATE TABLE orders ( order_id BIGSERIAL PRIMARY KEY, customer_id INT NOT NULL , order_date DATE NOT NULL , amount NUMERIC ( 10 , 2 ) NOT NULL ) PARTITION BY RANGE (order_date); Step 2: Create partitions CREATE TABLE orders_2023 PARTITION OF orders FOR VALUES FROM ( '2023-01-01' ) TO ( ...