Core system concepts · Concept lesson
Partitioning
Divide a large dataset across logical or physical partitions to manage scale while preserving query, ordering, and rebalancing semantics.
Written for readers who already know the basics. If the words here are new to you, read The request lifecycle and Capacity estimation first.
Original educational architecture · Version 2026-11-12.1 · Examples use stated hypothetical assumptions, not a company's actual design.
What you will be able to explain
- Distinguish table partitioning from distributing data across nodes.
- Choose a partition key using access patterns and distribution.
- Recognize hot partitions, cross-partition queries, and rebalancing costs.
How partitioning works
Partitioning divides a dataset into manageable subsets using a routing rule. A relational database may partition one logical table by date range so retention and scans target relevant chunks. A distributed key-value store may hash a partition key to assign records across nodes. These are related but distinct operations: table partitioning can happen on one server, while sharding distributes responsibility across machines. The key determines locality, load, and which queries are easy. A good key sends related reads to one partition while spreading hot writes enough for the workload. Poor keys create skew, where one partition receives most traffic, or scatter, where every query becomes a fan-out. Partitioning does not itself guarantee ordering or global transactions. The design must explain how records are routed, how a query finds partitions, how data moves when capacity changes, and what happens to a request when a target partition is unavailable.
Carries an entity identifier or partition key.
Maps range, hash, or list value to a partition.
Stores one subset of the dataset.
Stores another subset of the dataset.
Returns one-partition data or merges bounded fan-out.
- Request → Routing rule: key and operation
- Routing rule → Partition A: route to A
- Routing rule → Partition B: route to B
- Partition A → Query result: partial or complete result
- Partition B → Query result: partial result for fan-out
Worked example: partitioning event records
Averages can hide a disastrous key distribution. Suppose a service stores 16 million events per day across 16 hash buckets and most tenants contribute evenly; the expected mean is about 1 million events per bucket per day. If one tenant generates 40% of all events and the key is only tenant_id, one partition may receive 6.4 million events per day while the others remain lightly used. Adding more machines does not divide that hot key automatically. A compound route such as (month, hash(tenant_id, event_id)) can spread a large tenant across buckets, but then a tenant's daily history must query each bucket and merge results in event-time order. That fan-out increases work and complicates pagination; a continuation token must preserve a stable position across all buckets. Before changing the key, measure per-tenant write rates, largest-key share, and query shapes, then rehearse a migration with one authoritative writer and verified copies. Partition movement also consumes network and disk I/O, so throttle it to protect foreground requests. A routing rule is part of the data contract: changing it without a copy, verification, and cutover plan can make existing records appear missing.
Assume an event table grows by 12 million records each month and a common maintenance job deletes data older than 18 months. Monthly range partitions allow the system to identify 12 million records as one old partition and remove or archive that partition without scanning 216 million retained records row by row. If each record averages 700 bytes before indexes, the monthly raw data is 12,000,000 × 700 = 8.4 billion bytes, about 8.4 GB in decimal units; actual disk use is larger after indexes, metadata, replication, and backups. For distributed writes, partitioning only by month can make the current month a hot key. A compound route such as (month, hash(account_id)) can spread writes into, for example, 16 buckets, while an account history query still targets one bucket per month. That query may fan out across 18 months, so its work and merge behavior need a bound. The arithmetic exposes retention and query costs but must be checked against measured row sizes and skew.
Partitioning alternatives
Range partitioning supports ordered ranges and time-based lifecycle operations, but the newest range can become hot. Hash partitioning tends to distribute keys evenly, but range scans and rebalancing can be harder. List partitioning maps a known set of values, which may help tenant or region isolation but can leave unknown values awkward. Composite partitioning combines dimensions with more routing complexity. Consistent hashing can reduce movement as node counts change, while virtual nodes or managed placement may smooth distribution. A single database with table partitions can simplify transactions and operations compared with a distributed shard, but it cannot exceed the host's limits indefinitely. An index may solve a query bottleneck without partitioning. Archive tables or tiered storage can address retention cheaper than keeping all data hot. Choose the least complex technique that addresses a measured size, maintenance, or throughput limit.
Failure and recovery
A hot partition can exhaust CPU, storage I/O, or write capacity even when the cluster average looks healthy. Rebalancing may temporarily move large amounts of data and increase latency or replication lag. A routing-table mismatch can send writes to the wrong owner; stale clients may continue using old placement. Design a controlled migration with versioned routing, bounded copy, dual-read comparison, and a clear point of write ownership. If a partition is unavailable, define whether requests fail, queue, or use a replica under known consistency limits. Cross-partition transactions can be expensive or unsupported, so business operations that frequently span keys may signal a poor key choice. Monitor per-partition traffic, storage, queue age, and skew, not only cluster totals. Recovery requires restoring the correct mapping and verifying data completeness; adding nodes without rebalancing or fixing a hot key will not necessarily restore capacity.
When not to partition
Do not partition a small dataset merely to anticipate hypothetical scale. Partitioning adds routing, schema, query-planning, migration, and operational burden. If a database index and retention policy meet current needs, use those first. Avoid partition keys that are monotonic and concentrated unless range locality is intentional and the storage engine handles the write pattern. A tenant key may seem natural but can leave one large tenant as a hot partition; a hash suffix can spread writes at the cost of more complex reads. Avoid a design that requires frequent global joins or atomic cross-partition updates unless the technology supports them and the cost is acceptable. Partitioning should follow observed volume and access patterns, with a plan for rebalancing. It is not a substitute for a query plan, caching, or workload limits.
Senior followups
Ask how the partition key distributes both current and projected traffic, including the largest tenant and burstiest key. What fraction of queries is single-partition, and how much fan-out is acceptable at p99? Can identifiers be unique only within a partition, or must uniqueness be global? How are cross-partition constraints and transactions handled? What is the rebalancing time and temporary resource cost for moving a partition? Can operators detect skew before a hot key causes an incident? Is the key stable if product ownership or data residency changes? Consider whether a partition can split without changing client-visible identity. Senior design includes a test dataset with realistic skew and a documented procedure for adding capacity, moving ownership, and rolling back a partial move. A partition plan without an operational balancing strategy is only a static placement diagram.
Operational practice
Expose per-partition request rate, latency, storage, replication lag, and error rates, plus a distribution view such as highest-to-median load. Set alert thresholds on imbalance and growth, not just total cluster usage. Test queries with and without partition-key filters to verify pruning or targeted routing. Keep migrations resumable and track copied versus verified records. During repartitioning, ensure one authoritative writer and use checksums or counts before routing fully. Retention jobs should detach or archive the intended periods and confirm that backups retain required history. Avoid dashboards that show only fleet-wide averages, since a single overloaded partition can be invisible in them. Run a capacity exercise that simulates a large key, node loss, and rebalancing load. Document what the system does when an unrecognized partition key arrives.
Terms in plain language
- Partition
- A subdivision of data identified by a range, hash, list, or other routing rule.
- Partition key
- A value used to decide which partition holds or serves a record.
- Hot partition
- A partition receiving a disproportionate share of requests or writes.
- Fan-out
- A query or operation sent to multiple partitions and combined into one result.
References and boundaries
Primary documentation supports the mechanisms described. It does not certify these hypothetical architectures, prices or sizing assumptions. Review platform-specific behavior before implementation.
Primary database documentation for declarative range, list, and hash partitioning.
Primary vendor guidance on partition-key distribution and hot partitions.