System Design Playbook
11 · Data & databases8 min read

Database partitioning strategies

Splitting a huge table into smaller pieces so queries read less data and maintenance gets easier. Range, list, hash and vertical partitioning, how partition pruning works, and how partitioning relates to sharding.

In one sentence

Partitioning divides one large table into smaller pieces by a rule (by date, by region, by hash, or by columns), so each query only reads the pieces that can contain its answer.

Why partition a table

  • Faster queries: with *partition pruning*, a query for March only reads the March partition.
  • Easier maintenance: deleting a year of old data is dropping a partition, not a giant DELETE.
  • Smaller indexes per partition, which fit better in memory.
  • A step towards scaling out: partitions can later live on different machines (that's sharding).

Pick a strategy and a query below and see how many partitions the database has to read.

Partitioning an orders table
Strategy
Query

Partition 1

Jan

#1049 · Jan · US#1050 · Jan · APAC#1051 · Jan · EU#1052 · Jan · US#1053 · Jan · LATAM

Partition 2

Feb

#1046 · Feb · US#1047 · Feb · EU#1048 · Feb · US

Partition 3

Mar

#1041 · Mar · US#1042 · Mar · EU#1043 · Mar · APAC#1044 · Mar · US#1045 · Mar · LATAM

Partition 4

Apr

#1030 · Apr · EU#1031 · Apr · US#1032 · Apr · US#1033 · Apr · LATAM#1034 · Apr · EU#1035 · Apr · US#1036 · Apr · APAC#1037 · Apr · US#1038 · Apr · EU#1039 · Apr · LATAM#1040 · Apr · US

🔥 hot: all new orders land here

Partitions read
1 / 4
Rows scanned
5
Rows matched
5
Watch out
pruned ✓
Recent data gets all the writes, so the newest partition is hot. Great for dropping old data: just detach a month. Partitioning splits one big table into smaller pieces inside the same database. The database only reads the pieces a query can touch (partition pruning), so the right key depends on your most common queries.
Highlighted partitions are the ones the query must read. Green rows match the query.

The strategies

StrategyRuleBest forWatch out
Rangecreated_at by month or yearTime-series data, logs, orders, archiving old dataThe newest partition gets all the writes (hot partition)
Listregion IN ('EU'), tenant = 'acme'Data naturally grouped by category, region or customerUneven if one value is much bigger than the rest
Hashhash(id) % NSpreading writes evenly when there is no natural rangeRange queries have to read every partition
CompositeRange by month, then hash by user insideVery large tables with two main access patternsMore complexity to manage
VerticalMove columns to another tableWide tables with a few hot columns and big, rarely-read ones (blobs, JSON, text)Joins when you need both parts
CREATE TABLE orders (
  id bigint, user_id bigint, total numeric, created_at timestamptz
) PARTITION BY RANGE (created_at);

CREATE TABLE orders_2026_03 PARTITION OF orders
  FOR VALUES FROM ('2026-03-01') TO ('2026-04-01');

Choosing the partition key

The partition key should match the filter in your most important queries. If almost every query says WHERE created_at > now() - interval '7 days', range by date is perfect. If they all say WHERE customer_id = ?, list or hash by customer is better.

Partitioning vs sharding

PartitioningSharding
Where the pieces liveSame database serverDifferent servers
Who routes queriesThe database, transparentlyYour app or a routing layer (or a distributed DB)
SolvesBig tables, slow scans, data retentionOne machine can't handle the data or the writes
ComplexityLow to mediumHigh

Sharding is horizontal partitioning across machines. Many teams partition first, and shard only when a single server isn't enough.

Key takeaways

  • 01Partitioning splits a big table into pieces by a rule, inside one database.
  • 02Range for time-based data, list for categories, hash for even spread, vertical for wide tables.
  • 03Partition pruning only helps queries that filter by the partition key.
  • 04Sharding is partitioning across servers: more scale, much more complexity.

Check your understanding

1 of 3

What is table partitioning?

Related concepts