AlgoViz

Write-back

medium 22 min

With write-back, also called write-behind, a save is answered as soon as it is in the cache, and a worker writes it to the database later in batches.

Where it shows up

The same pattern appears across everyday software.

  • Linux file writes

    A program writes to a file and the kernel keeps the pages in memory as dirty. Flusher threads wake up regularly and write old dirty data to disk. Programs that need safety ask for a sync.

  • PostgreSQL pages

    Changed pages stay dirty in memory until a checkpoint writes them. The change itself is safe earlier, because it is in the write-ahead log. This is write-back with the loss window closed.

  • Processor caches

    Many processor caches write changed lines back to main memory only when they have to, which saves traffic.

  • Game leaderboard

    Scores are kept in a sorted set in memory and written to the database every few seconds. After a crash a few recent scores may be missing.

  • View counters

    Views are added up in the cache. A worker writes one new total per video instead of one write per view.

  • Ehcache write-behind

    The Java cache can write to the system of record in the background, with batching and coalescing. Its documentation says failed writes are not retried at that level, so your writer has to do it.