Full answer
The goal
Analytics queries scan huge tables: "revenue by course for last week". The fastest data is data you do not read. Layout decides how much can be skipped.
Partitioning
A table stored as events/date=2026-12-03/, events/date=2026-12-04/ lets a query with WHERE date >= '2026-11-27' read only seven folders. That is partition pruning.
Good partition keys:
- Appear in most query filters (date or hour for event data).
- Have moderate cardinality: days, maybe days plus region. Not user_id: millions of partitions mean millions of tiny files and huge metadata.
Skew matters too: if one partition holds 80% of data, parallel jobs wait on it.
Columnar formats
Parquet and ORC store each column separately, compressed, in row groups with min and max statistics. A query that needs 3 of 80 columns reads only those 3. Similar values compress very well (dictionary and run-length encoding).
Clustering and sorting
Within a partition, sort data by a second common filter (for example course_id). Then each file and row group covers a narrow range of course_id, and the engine skips files whose min and max cannot match. Z-ordering mixes several columns when queries filter on different ones. Warehouses call this clustering keys (Snowflake, BigQuery) or sort keys (Redshift).
File sizes
Streaming ingestion writes many small files. Each file costs an open, metadata reads and scheduling overhead. Compact them into files of roughly 128 MB to 1 GB. Table formats such as Iceberg, Delta Lake and Hudi track files in metadata, support compaction and allow changing the partition scheme later without rewriting queries.
Example
A learning platform stores 2B video events per day. Layout: partition by event_date, cluster by course_id, Parquet files of about 512 MB. A query for one course over 7 days reads 7 partitions and only the files whose course_id range includes it, perhaps 1% of the week's data.
Trade-offs
- More partitions mean better pruning only up to a point; past it, metadata and small files dominate.
- Sorting on ingest costs compute; periodic background clustering spreads the cost.
- Partitioning for one query pattern can hurt another; pick the dominant pattern and use clustering for the rest.
- OLTP-style partitioning (by user for load spread) is different from analytics partitioning (by time for pruning).
By level
Fresher: Explain that data is split into folders by date so queries only open the days they need. A fresher should know that columnar files read only the needed columns.
Mid: Discuss partition key choice, columnar statistics, clustering within partitions and compaction of small files. Give an example layout.
Senior: Cover Z-ordering, table formats, partition evolution, skew, and choosing between conflicting query patterns. Expect cost-aware reasoning about scanned bytes.
Key points
- Partition by the most common filter, usually date
- Partition pruning skips whole folders
- Columnar formats read only needed columns and skip by min-max statistics
- Cluster or sort within partitions on secondary filters
- Avoid small files and high-cardinality partitions
Common mistakes
- Partitioning by user ID or another high-cardinality column
- Ignoring small files from streaming ingestion
- Storing analytics data in row formats like CSV or JSON long term
- Assuming more partitions always mean faster queries
Follow-ups
- How does Z-ordering work?
- How would you change the partition scheme of a 500 TB table?
- How do Iceberg or Delta Lake help with compaction?
Tips
- Use a date-filter example to explain pruning
- Mention column pruning and statistics
- Warn about small files with numbers
Evaluation rubric
- Correct partitioning guidance
- Columnar and statistics-based skipping explained
- Clustering and file size handled
- Trade-offs between query patterns