Merge-on-read moves cost to compaction, which is fine if you schedule it

source: Apache Iceberg docs — Spark write modes

Iceberg gives you two ways to apply an update or delete. Copy-on-write rewrites every data file that contains an affected row, so writes are expensive and reads are clean. Merge-on-read writes small delete files and leaves the data files alone, so writes are cheap and every read has to apply the deletes.

For SCD Type-2 master data, where a load touches a few rows in a great many files, merge-on-read was the only sane choice. A copy-on-write merge of a nightly incremental load would have rewritten most of the table every night.

The cost does not disappear. It moves to two places:

  • Reads, which get slower in proportion to how many delete files have accumulated since the last rewrite.
  • Compaction, the rewrite_data_files and rewrite_position_delete_files maintenance jobs that fold deletes back into clean data files.

What made it fine for us was treating compaction as part of the pipeline schedule rather than as housekeeping. The loads run, then compaction runs on the tables the loads touched, then snapshot expiry. Reads during the day hit compacted files. Nobody has to remember to run anything.

The rule I took from it: pick merge-on-read when writes are sparse and reads happen later, and put the compaction job in the same DAG as the write. If compaction is "someone's job", it will not run, and the table will slowly get slower until it becomes an incident.