Data lake storage: formats and layout
A data lake is just files in cheap cloud storage, but which file format and folder layout you choose decides how fast every later query is. This lesson compares CSV, JSON, Avro, ORC and Parquet, explains compression, and shows how to lay out folders.
Step 3 · Data lake & lakehouse · Bronze · Lake foundations, lesson 2 of 3
On this page
Read first: Lake, warehouse, lakehouse (skip if you know it)
In plain words first
A warehouse full of boxes can be a mess or a joy, depending on the labels and the shelving. Same boxes, same goods: what changes is how quickly anyone finds what they need.
File formats are the boxes (some are see-through, some must be unpacked to read), and the folder layout is the shelving.
What a data lake is
A data lake stores data as files in cheap object storage (Amazon S3, Azure Data Lake Storage, Google Cloud Storage) and lets many engines read it: Spark, Trino, Flink, DuckDB, warehouses. Storage is separated from compute, so you pay for compute only while queries run. The price is that the lake has no database to enforce anything: formats, layout and conventions do that job, and table formatstable format: A metadata layer (Delta Lake, Iceberg, Hudi) that turns a folder of data files into a table with commits, versions and a schema. Learn more → like Delta and Iceberg add transactions on top.
The formats compared
| Format | Layout | Schema | Splittable | Best for |
|---|---|---|---|---|
| CSV | Row, text | None (all strings) | Yes, if uncompressed or with a splittable codec | Exchange with humans and legacy systems |
| JSON (Lines) | Row, text | Self-describing per record | Yes for JSON Lines | APIs, logs, nested data on landing |
| Avro | Row, binary | Embedded, with evolution rules | Yes | Kafka messages, write-heavy pipelines, schema evolutionschema evolution: Changing a table's columns on purpose, such as adding one, without rewriting the data. Learn more → |
| ORC | Columnar, binary | Embedded | Yes | Analytics in Hive-era stacks |
| ParquetParquet: A columnar file format: values of each column are stored together, so queries read only the columns they need. Learn more → | Columnar, binary | Embedded | Yes | Analytics; the default under Delta, Iceberg and Hudi |
Why columnar wins for analytics
Input
| Row layout (CSV, Avro) |
|---|
| 1, Pune, 250 |
| 2, Delhi, 900 |
| 3, Pune, 120 |
Output
| Columnar layout (Parquet, ORC) |
|---|
| id: 1, 2, 3 |
| city: Pune, Delhi, Pune |
| amount: 250, 900, 120 |
The same three rows, two layouts
- Column pruningcolumn pruning: Reading only the columns a query uses, which columnar files like Parquet make possible. Learn more →:
SELECT sum(amount)reads one column out of fifty, not all of them. - Better compression: similar values sit together, so dictionary and run-length encoding shrink them a lot (a city column with 100 distinct values compresses to almost nothing).
- Skipping: each row grouprow group: A block of rows inside a Parquet file. Its min and max statistics let readers skip blocks that cannot match a filter. Learn more → stores min/max statistics per column, so
WHERE amount > 1000skips row groups whose max is lower. - The cost: writing is heavier, and reading one whole record touches every column chunk. That is why landing and streaming often use row formats.
Compression codecs
| Codec | Size | Speed | Typical use |
|---|---|---|---|
| Snappy | Good | Very fast | Spark's Parquet default |
| ZSTD | Better | Fast | Increasingly the default for Parquet and Iceberg; a good general choice |
| GZIP | Better | Slow | Archives; avoid on CSV, because a .gz file cannot be split, so one tasktask: The work for one partition in one stage, run on one CPU core. Learn more → reads it all |
| LZ4 | Good | Fastest | Hot data, shuffleshuffle: Moving rows between machines so that all rows with the same key end up together. Needed by joins, groupBy and sorting, and usually the most expensive step of a job. Learn more → files |
Inside Parquet, compression applies per column chunk, so every codec is splittable there. Outside Parquet, a single 10 GB .csv.gz file is read by one task, which is a common reason a job has one task running for an hour.
Zones: raw to curated
-
Raw / landing
Exactly as received: CSV, JSON, Avro. Append-only, never edited, kept for replay and audit.
-
Cleaned / bronze-silver
Parsed, typed, de-duplicated, in Parquet or a table format.
-
Curated / gold
Modelled for consumers: facts, dimensions, aggregates.
This is the same idea as the medallion architecture. Keeping the raw zone means any bug downstream can be fixed by reprocessing from the original files.
Folder layout
A typical layout
s3://acme-lake/ raw/orders/ingest_date=2025-03-01/part-0000.json.gz silver/orders/order_date=2025-03-01/part-00000.zstd.parquet gold/daily_revenue/...
- Hive-style folders (
column=value) let engines prune partitions from the path. - Partition by a low-cardinalitycardinality: How many distinct values a column has. User ids are high cardinality; country codes are low. Learn more → column that queries filter on, usually a date. Partitions should hold at least about 1 GB.
- Aim for files of 128 MB to 1 GB.
- Separate buckets or prefixes per zone make access control simple: few people can write to raw, many can read gold.
- Never rely on listing folders to know what a table contains: concurrent writers make that unsafe. That is the problem table formats solve with a transaction logtransaction log: The ordered list of commits that defines which files make up a Delta table at each version. Learn more →.
Try it yourself
Each example says what it shows, then the output from a real run and what to notice in it, so you can follow without running anything. To try one yourself, paste it into a local Spark session with Delta Lake, with spark already created: each builds its own data.
Goal: Save incoming raw data so each day's load can be found, and redone, on its own.
import glob from pyspark.sql import functions as F raw = spark.createDataFrame( [("o-1", "IN", "120.5"), ("o-2", "US", "80"), ("o-3", "DE", "45.25")], ["order_id", "country", "amount"]) (raw.withColumn("_ingested_at", F.current_timestamp()) # the load date, not the event date .withColumn("ingest_date", F.lit("2025-03-01")) .write.mode("append") .option("compression", "zstd") # smaller files than snappy .partitionBy("ingest_date") .parquet("lab/landing/orders")) print("files written under lab/landing/orders:") for f in sorted(glob.glob("lab/landing/orders/**/*.parquet", recursive=True)): print(" ", f.removeprefix("lab/landing/orders/")) spark.read.parquet("lab/landing/orders").drop("_ingested_at").orderBy("order_id").show()
Output from a real run
files written under lab/landing/orders: ingest_date=2025-03-01/part-00001-f3daeade-cf34-4c6c-9f44-881615e48f84.c000.zstd.parquet ingest_date=2025-03-01/part-00002-f3daeade-cf34-4c6c-9f44-881615e48f84.c000.zstd.parquet ingest_date=2025-03-01/part-00003-f3daeade-cf34-4c6c-9f44-881615e48f84.c000.zstd.parquet +--------+-------+------+-----------+ |order_id|country|amount|ingest_date| +--------+-------+------+-----------+ | o-1| IN| 120.5| 2025-03-01| | o-2| US| 80| 2025-03-01| | o-3| DE| 45.25| 2025-03-01| +--------+-------+------+-----------+
What to notice:
- The folder name
ingest_date=2025-03-01is the date column: Spark put the value in the folder name, not inside the files. - 3 files for 3 rows: the data was split across tasks, and each task wrote its own file.
- Each file name ends in
.zstd.parquet: that shows the compression used. - If one day's load is bad, you delete or rewrite that one folder.
Goal: See how much disk space the same 500,000 rows take in each file format.
import glob, os from pyspark.sql import functions as F df = (spark.range(0, 500_000) .withColumn("country", F.expr("element_at(array('IN', 'US', 'DE', 'BR'), " "CAST(id % 4 + 1 AS INT))")) .withColumn("amount", F.round(F.rand(seed=1) * 1000, 2)) .withColumn("status", F.expr("IF(id % 10 = 0, 'REFUNDED', 'PAID')"))) def size_mb(path): files = [f for f in glob.glob(f"{path}/*") if not os.path.basename(f).startswith((".", "_"))] # skip _SUCCESS return sum(os.path.getsize(f) for f in files) / 2**20 formats = [("csv", {"header": "true"}), ("csv-gzip", {"header": "true", "compression": "gzip"}), ("json", {}), ("orc", {}), ("parquet", {})] for name, options in formats: fmt = name.split("-")[0] target = f"lab/formats/{name}" df.coalesce(1).write.mode("overwrite").options(**options).format(fmt).save(target) print(f"{name}: {size_mb(f'lab/formats/{name}'):.1f} MB")
Output from a real run
csv: 10.5 MB csv-gzip: 2.9 MB json: 29.1 MB orc: 1.6 MB parquet: 4.2 MB
What to notice:
- JSON is biggest (29 MB): it repeats every column name on every row.
- ORC (1.6 MB) and Parquet (4.2 MB) are smallest. They store each column's values together, so similar values compress well.
- gzip shrinks the CSV from 10.5 to 2.9 MB, but a gzipped file cannot be split: one task has to read all of it.
Common mistakes
- Analytics on CSV or JSON — Every query reads every column as text. Convert to Parquet once.
- Large gzip CSV files — Not splittable: one task per file.
- Partitioning by a high-cardinality column — Millions of tiny folders and files.
- No raw zone — A parsing bug cannot be fixed by reprocessing because the original data is gone.
Key takeaways
- Row formats suit landing and exchange; columnar formats suit analytics.
- Parquet gives column pruning, compression and row-group skipping.
- Avoid big gzip text files: they cannot be split.
- Use zones, date partitions and large files; add a table format for transactions.
Interview prep
THE QUESTION
"Parquet vs Avro: when would you use each?"
Avoid: "Parquet is always better". Avro wins for row-at-a-time writes, streaming messages and schema evolution in transit.
Follow-ups · answer out loud, then open
Follow-up"Why is gzip-compressed CSV a problem for Spark, but Snappy Parquet is not?"
Scenario"Design the folder layout for raw files landing from 30 source systems."
raw/<source>/<dataset>/ingest_date=YYYY-MM-DD/. Keep files immutable, record ingestion metadata, and convert to a table format in the next layer. Ingestion date (not event date) makes reprocessing and late data simple.Trap"Snappy compresses better than gzip, which is why Parquet uses it."
Check yourself
3 questionsA query sums one column of a 50-column table. Which format reads the least data?
Show the answer
Parquet. Columnar formats read only the needed column.
Why is a 10 GB .csv.gz file slow to read in Spark?
Show the answer
gzip is not splittable, so one task reads the whole file. Without split points, one task must decompress from the start.
What is the raw zone for?
Show the answer
Keeping data exactly as received so it can be reprocessed. It is the replayable source of truth.
Practise this
Problems that use this, graded on hidden tests
- Inventory a Partitioned FolderData Lake Medium
- Find Files Spark Cannot SplitData Lake Medium
- Late Data in the Raw ZoneData Lake Medium
Keep going
Up next · Lake foundations · lesson 3 of 3 · 7 min readParquet and columnar storage
Row groups, column chunks and statistics: why columnar files let engines skip most of the data.
Related lessons
Partitioning done rightData lake & lakehouse · 6 min read
The medallion architecture
Previous: Lake, warehouse, lakehouse
Primary sources: Apache Parquet · Apache Avro · Spark data sources