Partitioning & file layout
Partition by query pattern (usually date), avoid high-cardinality partitions, target ~128MB-1GB files. The small-files problem quietly kills both S3 listings and Spark planning.
The mental model
Partitioning is **the index of a book that you build into the shelving itself**. A data lake has no B-tree index — it is a pile of files on object storage. So instead of searching inside files, you arrange the *directories* so that the folder path itself answers "which files could possibly match". WHERE event_date = '2026-07-01' becomes "open the event_date=2026-07-01/ folder and ignore every other folder" — a filesystem operation, not a data scan. That skip is called partition pruning, and it is the single biggest performance lever in a lake before you tune anything else.
The analogy that sticks: a warehouse aisle scheme. If you shelve inventory by received-date aisle, an auditor asking "what came in last Tuesday" walks to one aisle. If you shelve by product ID and someone asks about a date, they walk every aisle. The partition key is the question you optimise for — and, just as importantly, the question you pessimise every other query for. There is no free partitioning; you are trading one query pattern's speed for all the others'.
Two forces pull in opposite directions and the whole craft is balancing them:
- **Partition granularity** — finer partitions (by hour instead of day) prune more precisely but multiply the number of directories and files. Push too far — partition by
user_id, or by a full timestamp — and you get millions of directories with a handful of rows each. Now listing the partitions costs more than scanning the data. - File size within a partition — too-large files kill parallelism (one task must read a 10 GB file); too-small files kill everything else. The sweet spot is ~128 MB–1 GB per file, and staying in it under continuous writes is the recurring operational chore of running a lake.
The one idea that explains most lake performance pain: the small-files problem. Streaming and frequent micro-batches naturally emit many tiny files. Every tiny file is a separate storage listing entry, a separate footer read, a separate task, and a separate metadata row. At a few thousand files nothing is wrong; at a few million, listing the table takes minutes, Spark spends more time planning than computing, and the metastore groans — all while the data is small. Small files are how a lake dies slowly.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision