16 / 25 · Data and consistency
Data partitioning
Partitioning splits a dataset into manageable parts using rules such as date ranges or key hashes. Table partitions can remain inside one database; partitioning does not automatically mean physical sharding across servers.
What you will practise
- Explain pruning
- separate partitions and shards
- plan retention
Before you start: Table, predicate and query plan.
About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.
Download MP4CaptionsListen without the video
Download audioChapters and full transcript
Let us understand data partitioning. You organize school papers into folders by month. Finding November work becomes easier if you open only the November folder. Putting every folder on the same desk does not create more desks. Likewise, smaller table parts can improve maintenance or pruning without adding another database machine. Partitioning splits a dataset into manageable parts using rules such as date ranges or key hashes. Table partitions can remain inside one database; partitioning does not automatically mean physical sharding across servers.
Follow the normal path. History rows are grouped by date. This organization can exist inside one database and should not be confused with distributing ownership across independent shards. Each month has a defined range with explicit boundaries. Future data needs a matching partition or a deliberately configured default behavior. SeatSpot stores an increasing audit/history table. Date partitions can make retention and time-bounded queries easier while keeping current reservation transactions on an appropriate authoritative path.
Now change one condition. A date-bounded query reaches the planner. The engine can eliminate irrelevant ranges if its rules and the query expression permit partition pruning. A common misunderstanding is this: Table partitioning automatically scales across machines. Partitions can remain inside the same database on the same machine. Think about this. A monthly partitioned table is queried without a date predicate. Must it read only one month? Pause the video and make your prediction. No. Without a usable condition the database may inspect many partitions. Check the query plan instead of assuming pruning.
Let us reason with a concrete example. History contains one million rows per month over two years. A query requests one month. With useful pruning it may inspect a relevant partition rather than all 24 million rows, but actual I/O depends on predicates, indexes and plans. Use EXPLAIN in a test environment. Confirm pruning and retention behavior instead of assuming a partitioned table is always faster. These figures are teaching examples, not production guarantees.
Turn the idea into a design decision. The November partition supplies the requested history. An appropriate index and query plan can still be necessary inside that partition. Retention can operate on old partitions, but removal is a data-policy decision. Verify dependencies, recovery requirements and correct boundaries before destructive maintenance. When you try the practice task, look for this result. Partitioning can aid pruning and lifecycle management without adding another database server.
Check your understanding. A query without the partition key may still inspect many parts. More partitions do not automatically add machines, guarantee speed or fix one hot-row lock. Here is a challenge. A table is partitioned by date, but a query filters only customer email. Must it be fast? Pause before the answer. No. The engine may inspect many partitions without a useful date restriction. Examine the actual plan and indexing/access pattern rather than assuming partitioning alone helps. For an interview, discuss partition keys, pruning, indexes and retention. Say what you would measure, not only which tool you would buy.
Start with an everyday picture
You organize school papers into folders by month. Finding November work becomes easier if you open only the November folder. Putting every folder on the same desk does not create more desks. Likewise, smaller table parts can improve maintenance or pruning without adding another database machine.
Why SeatSpot needs this
SeatSpot stores an increasing audit/history table. Date partitions can make retention and time-bounded queries easier while keeping current reservation transactions on an appropriate authoritative path.
Trace one step at a time
Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.
Define a partition rule
History rows are grouped by date. This organization can exist inside one database and should not be confused with distributing ownership across independent shards.
Read all six mechanism steps
Define a partition rule
History rows are grouped by date. This organization can exist inside one database and should not be confused with distributing ownership across independent shards.
Create ranges
Each month has a defined range with explicit boundaries. Future data needs a matching partition or a deliberately configured default behavior.
Ask for November
A date-bounded query reaches the planner. The engine can eliminate irrelevant ranges if its rules and the query expression permit partition pruning.
Read the useful part
The November partition supplies the requested history. An appropriate index and query plan can still be necessary inside that partition.
Maintain the lifecycle
Retention can operate on old partitions, but removal is a data-policy decision. Verify dependencies, recovery requirements and correct boundaries before destructive maintenance.
Know the boundary
A query without the partition key may still inspect many parts. More partitions do not automatically add machines, guarantee speed or fix one hot-row lock.
Pause and make a prediction
A monthly partitioned table is queried without a date predicate. Must it read only one month?
Correct a common misunderstanding
Claim to question: Table partitioning automatically scales across machines.
Better explanation: Partitions can remain inside the same database on the same machine.
Work a monthly history query
- Draw 24 monthly partitions with one million rows each.
- Write a predicate for one month and identify removable partitions.
- Remove the predicate and compare the possible work.
Check what you can explain
This is your self-check, not an automated grade. Try again without the diagram tomorrow.
0 of 3 goals checked. Choose one remaining idea to practise next.
Teach it back
Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.
Engineering model and trade-offs
Match the partition key to queries and lifecycle operations. Partition pruning avoids irrelevant parts when predicates and the database plan permit it. A query with no usable partition condition may still scan many partitions.
Range, list and hash partitions have different properties. Plan creation of future partitions, default/error behavior for unmatched rows, indexes and retention. Too many tiny partitions can add planning and management overhead.
Check uniqueness and foreign-key capabilities in the specific database. Partitioning may constrain global uniqueness or maintenance operations. It does not remove the need for indexing or automatically solve write contention on one hot record.
Work through an example
History contains one million rows per month over two years. A query requests one month.
Reason with the numbers
With useful pruning it may inspect a relevant partition rather than all 24 million rows, but actual I/O depends on predicates, indexes and plans.
Make a decision
Use EXPLAIN in a test environment. Confirm pruning and retention behavior instead of assuming a partitioned table is always faster.
Implementation sketch
CREATE TABLE booking_history (
id bigint NOT NULL, created_at date NOT NULL
) PARTITION BY RANGE (created_at);
CREATE TABLE booking_history_2026_11
PARTITION OF booking_history
FOR VALUES FROM ('2026-11-01') TO ('2026-12-01');PostgreSQL teaching example. The lower bound is inclusive and upper bound exclusive. Insertions outside defined partitions need another matching/default partition; indexes and constraints are not complete here.
Where this is used
- Time-based history retention and maintenance.
- Queries that can select a limited set of data partitions.
Common mistakes
- Calling all partitioning sharding.
- Missing future partition creation.
- Ignoring query plans and global constraint behavior.
Practise a reasoned answer
Answer aloud or write notes before opening the reference. These prompts teach reasoning and trade-offs; they are not claimed questions from a particular company.
Partitioning versus sharding?
Choose a practice depth
- Foundation
- Explain folders within a table.
- Practical
- Discuss partition keys, pruning, indexes and retention.
- Advanced
- Defend uniqueness constraints, planning overhead and partition lifecycle automation.
Self-check rubric
- State the required user outcome and the relevant invariant.
- Explain the normal path and one failure path.
- Name a cost or consistency/latency trade-off.
- Say what you would measure or test before trusting it.
For deeper practice, connect this topic to the previous lesson and identify a shared bottleneck. A longer answer is not automatically a better answer.
Try it before viewing the solution
A table is partitioned by date, but a query filters only customer email. Must it be fast?
Check one key idea
Your explanation and interview notes
Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.
Loading your local notes…
Official references and next reading
The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.