Try
↑ ↓ move↵ openesc close

Interview prep / B-trees

Mid · B-trees · System design interview question

Why does a B-tree write far more bytes than the application asked it to?

Sketch your own answer first, then compare it with the one below.

A strong answer

The unit of writing is a page. Changing one 100 byte record dirties a whole page of several kilobytes, so the engine writes the whole page for a small change. That is write amplification.

The log adds a second write of every change. Splits add more, because a split writes two leaves and a parent. Some engines also write a full copy of a page the first time it changes after a checkpoint, to survive a torn write.

You reduce it with larger checkpoint intervals, so a page that changes many times is written once, and with sequential keys, so each insert dirties the same few pages. A good answer names the page size as the multiplier.

Sources

Learn it by running it

The b-trees and page writes lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms