Delta, Iceberg, or Hudi

Concepts covered: Cost Optimization

All 3 formats give the previous sections' guarantees: atomic commits over immutable Parquet files, snapshot reads, time travel and schema evolution. They differ in how the metadata is laid out, which decides 3 properties: how planning scales with file count, how row updates get written, and how many engines can share a table.

3 ways to lay out metadata

AspectDeltaIcebergHudi
MetadataOrdered JSON commits plus Parquet checkpointsA tree: metadata file, manifest list, manifestsA timeline of instants in a .hoodie folder
A version isAn integer commit numberA snapshot IDAn instant, keyed by commit time
A commit isCreating the next numbered fileSwapping the catalog's pointer to a new metadata fileCompleting an instant on the timeline
Row updatesFile rewrites, or deletion vectors that mark rows removedFile rewrites, or delete files (format v2)Copy-on-write or merge-on-read, set per table
Built forSpark-centric batch and merge workHuge tables shared by several enginesKeyed upserts and pulling only changed rows

Iceberg's tree and why it scales

Iceberg's metadata is a tree, so it has no log to replay. The catalog holds a pointer to the current metadata file, which names the current snapshot's manifest list. The manifest list names manifests and records the range of partition values each covers, and each manifest lists data files with their column stats. Planning walks down the tree and skips whole manifests whose range misses the filter, so its work follows the files a query might need, while a log replay starts from an entry for every live file.

A query on 2024-03-14 follows the pointer down, skips Manifest A, and plans only Data files B.
  • Catalog (custom, current pointer)
  • Metadata file (storage, schema, snapshots)
  • Manifest list (storage, snapshot 3)
  • Manifest A (storage, 2024-03-01 to 03-07)
  • Manifest B (storage, 2024-03-08 to 03-15)
  • Data files A (storage, Parquet)
  • Data files B (storage, Parquet)
  • Catalog -> Metadata file
  • Metadata file -> Manifest list
  • Manifest list -> Manifest A
  • Manifest list -> Manifest B
  • Manifest A -> Data files A
  • Manifest B -> Data files B

The tree also allows partition evolution. Iceberg partitions by transforms of a column, such as days(order_ts), and each manifest records the spec its files were written with. Switch from daily to hourly and new files use the new spec while old files keep theirs; a filter on order_ts prunes both, and nothing is rewritten. Queries filter on order_ts itself and never name a partition column, which Iceberg calls hidden partitioning.

Copy-on-write versus merge-on-read

Formats also split on how a row update is written. Copy-on-write rewrites every file holding an updated row: writes pay, and reads stay plain Parquet scans. Merge-on-read writes only the change, as delete markers or small log files beside the base files, and every read merges them in until a compaction folds them back. Either way, finding the files to touch is a job of its own. Delta's MERGE starts with an inner join of the updates against the table that collects the names of the files holding a match:

from pyspark.sql import functions as F

touched = (target
    .join(F.broadcast(updates), "order_id")
    .select("file")
    .distinct())

touched.collect()
target
order_idamountfile
10140f1.parquet
10215.5f1.parquet
10322f1.parquet
1049f2.parquet
10560f2.parquet
10631f2.parquet
10712f3.parquet
10875f3.parquet
10918f3.parquet
11044f4.parquet
11127f4.parquet
11250f4.parquet
updates
order_idamount
10217.5
10558
10633
11129

The join broadcasts updates, so the only shuffle is the distinct on file. The 4 changed rows hit 3 of the 4 files, and copy-on-write rewrites all 9 rows in them. Scaled up, 1,000 updated keys scattered over 200 files of 128MB each is 25.6GB rewritten for a few kilobytes of change, on every run.

Hudi was built around that trade. A record-level index maps each key to the file group holding it, a merge-on-read table appends updates to that group's log files, and compaction later merges them into a new base file. Commit times on the timeline also let a downstream job read only rows changed since the last commit it processed.

Choosing and defending it

If the platform...Lean towardBecause
Runs nearly all reads and writes on Spark, with appends and periodic mergesDeltaSimplest log, and checkpoints keep replay short
Shares tables across several query engines, or holds millions of filesIcebergEngine-neutral spec, manifests that prune at planning
Changes its partitioning as data growsIcebergPartition evolution with no rewrite of old files
Upserts keyed rows every few minutes and feeds jobs that want only changesHudiRecord index, merge-on-read, incremental reads by commit time

A defence names the workload, the cost the choice avoids, and the cost it accepts. For instance: 'Hudi merge-on-read, because 40 source databases upsert every 5 minutes and copy-on-write would rewrite most files each run; we accept that reads merge log files, and we run compaction hourly to keep that merge small.' Each part of it can be checked against the job's metrics.

A team runs 3 engines on the same tables: Spark writes them hourly, a SQL engine serves dashboards, and a separate service reads features for model training. The largest table holds 4 million files, rows are appended and rarely updated, and the team plans to move from daily to hourly partitions. Which format fits best?

About this lesson

This section is part of the Storage Formats: Advanced lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.