An app sends about 500 GB of events a day to S3, stored as Parquet and queried with Spark and Trino. Almost every query filters on a date range of a few days; some also filter on country (about 200 values, a few of them hold most of the traffic), and the support team looks up single users by user_id (about 50 million users). A teammate proposes Hive-style directory partitioning with paths dt=…/country=…/user_id=…/, so that each of these filters prunes directories. Lay out the prefixes for this table, name a sensible size for its files, and explain what goes wrong with partitioning by user_id.
Partition only by dt= (maybe hour=): nearly every query filters on it and its cardinality is bounded, so engines prune folders. user_id gives a folder per user, KB files, millions of partitions. Write files of hundreds of MB sorted by country, user_id.
- Partitioning by a high-cardinality column such as
user_idto speed up point lookups - Adding partition levels until every filter prunes, multiplying folders and shrinking files
- Expecting min/max statistics to replace directory pruning for the column almost every query filters on
- When would adding
hour=underdt=be worth it for this table? - How would a table format such as Iceberg change this layout with hidden partitioning?
Layout. A Hive-style partition is a column=value prefix in the path. The engine matches the filter against those values and never lists or opens the other prefixes. So the partition key is the column almost every query filters on, with a bounded number of values:
s3://lake/events/dt=2026-11-07/part-00000.parquet
s3://lake/events/dt=2026-11-07/part-00001.parquet
...500 GB a day at files of about 512 MB is on the order of a thousand files per dt partition. Add hour= only if queries really cut by hour and an hour still yields files of hundreds of megabytes.
Why not user_id. 50 million users means 50 million directories a day and as many partition entries in the metastore. Each directory holds a file of a few kilobytes: every file costs its own storage request and footer read, and compression barely works on tiny files. The layout does nothing for a date filter either: it still has to open every user's directory for the day.
country and user_id go into the order inside files. country, with its skewed traffic, would give a few huge partitions and a hundred tiny ones. Instead, the rows within a day are sorted by country, user_id: Parquet's row-group min/max statistics then let a reader skip most of a file, even for a single-user lookup.