Try
↑ ↓ move↵ openesc close

Interview prep / B-trees

Senior · B-trees · System design interview question

What does a checkpoint do, and how do you choose how often to take one?

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

A strong answer

A checkpoint writes the dirty pages in memory to the data file and records a point in the log. Recovery then only needs to replay the log from that point, and older log can be recycled.

Checkpoint rarely and you write fewer pages, because a hot page that changed a hundred times is written once. The cost is a long replay after a crash and a large log. Checkpoint often and recovery is quick, but you write pages more often and may produce bursts of I/O that hurt query latency.

A good answer mentions spreading the writes out over the interval so they do not arrive in a spike, and sizing the interval from the recovery time the service can tolerate.

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