skip to content

How would you choose a checkpoint interval or recovery-time target for a production database, and what are you trading off in each direction?

level: principalimportance: should knowfreq 38%

answer

  1. RTO first, then price the steady state
  2. interval bounds log to replay; replay slower than logging
  3. shorter -> more page writes AND more full-page images
  4. oldest dirty page, not the interval, sets the real start point
  5. standby failover changes the whole calculus

basics

~20 s

Start from the recovery-time objective, since the interval bounds how much log replay a crash costs, then check the steady-state price: shorter intervals mean more repeated page writes and more full-page-image log volume. Choose the longest interval that still meets the recovery target.

solid answer

~60 s

Work from the requirement backwards. The dominant term in crash recovery is replaying the log written since the recovery start point, so the checkpoint interval effectively bounds recovery time. If the business tolerates 60 seconds of unplanned downtime, and you measure replay throughput of roughly X MB/s of log, you can compute how much log you may leave outstanding and set the interval accordingly - with margin, because replay is slower than logging and the buffer pool starts cold. Then price the other direction. Shorter intervals cost: - **write amplification** - a hot page flushed more often coalesces fewer updates; - **more log**, where the first modification of a page after each checkpoint writes a full page image; - **more frequent flush activity** competing with the workload. So the rule is: the longest interval that still meets the recovery objective. Then verify by actually crashing a copy and timing recovery, and remember the interval is only an upper bound - a long-dirty page can hold the recovery start point back.

go deeper

for a junior

Know the direction of the tradeoff: more frequent checkpoints mean faster recovery but more write work.

for a middle

Quantify it - interval bounds the log to replay, and shortening it costs page write amplification plus full-page-image log volume.

for a senior

Derive the interval from a measured recovery objective, validate with a real drill, and interpret volume-triggered checkpoints and dirty-page age as signals.

for a principal

Position it inside the availability architecture: with fast failover the RTO pressure moves off the primary, and the tuning goal shifts to steady-state cost, replication traffic, and archive volume.

## Frame it as a requirement, not a knob The wrong version of this answer is a number ('five minutes'). The right one starts from what the system owes its users, because the checkpoint interval is the main lever converting *steady-state cost* into *recovery time*, and only the business can say which side matters more. Two requirements bound it: - **Recovery time objective (RTO)** for an unplanned restart: how long may the database take to come back after a crash? - **Cost budget**: how much extra write I/O and log volume the storage can absorb without hurting the latency the application actually sees. Note what is *not* on the list: durability and data loss. Committed data survives because the log is flushed at commit; the checkpoint interval does not change the recovery point objective at all. Candidates who conflate the two are making a serious error. ## Deriving the interval from the RTO Recovery time is dominated by scanning and replaying the log from the recovery start point to the end, plus undoing uncommitted transactions, plus the time for the system to become useful again with a cold cache. A usable method: 1. Measure the log generation rate under peak write load (MB/s). 2. Measure replay throughput empirically - restore a backup, kill the process under load, and time the restart. Replay is typically *slower* than logging, because it is random page reads against a cold buffer pool rather than sequential appends. 3. Compute the outstanding log an interval implies, divide by replay throughput, add undo time and warm-up. 4. Leave real margin - crashes happen at the worst moment, which is peak load, and a cold cache after restart means the first minutes of service are slow even after recovery formally completes. The conclusion is usually 'much shorter than intuition suggests' for write-heavy systems and 'the default is fine' for read-heavy ones. ## Pricing the shorter interval Three costs rise as the interval shrinks: **Write amplification of data pages.** The deferred-write design lets a page absorb many updates between flushes. Halve the interval and a hot page is flushed about twice as often, coalescing half as many updates each time. On a workload with a small, extremely hot working set this factor is large. **Log volume from full-page images.** Where torn-page protection works by logging a complete page image on the first modification of that page after each checkpoint, every checkpoint resets each page to 'first touch'. Halving the interval can therefore nearly double the full-image traffic. This surprises people, because it means *more frequent checkpoints can make the log bigger*, not smaller - and a bigger log means more replication traffic, bigger archives, and longer replay per unit time. **Continuous flush pressure.** More frequent flushing competes with the foreground workload for I/O; paced properly it is a hum rather than a spike, but the capacity is still consumed. ## Pricing the longer interval - Recovery grows toward minutes or tens of minutes, and the system is *down* for all of it. - More dirty data accumulates, so each checkpoint has a larger burst to deliver, worsening latency percentiles unless pacing is well configured. - Log space and archive lag grow, and any stalled reclaim point becomes an incident faster. ## Things that break the simple model - **The interval is only an upper bound on the recovery start point.** Replay begins at the oldest change among pages still dirty, so a page that has stayed dirty for a long time drags the start point backwards regardless of the interval. Engines flush long-dirty pages preferentially for exactly this reason, and it is why measured recovery time can exceed the arithmetic. - **Volume triggers.** Most engines also start a checkpoint when a threshold of log has been produced. Under peak write load this fires before the timer, so the *effective* interval is shorter than configured - and it is a signal the sizing assumptions no longer hold. - **Replicas change the calculus.** With a fast automatic failover to a standby, unplanned downtime is a failover, not a recovery, so the RTO pressure on the primary's checkpoint interval largely disappears and you can optimize for steady-state cost. This is the architectural answer a principal is expected to reach: HA topology dominates checkpoint tuning. - **Planned restarts are not crashes.** A clean shutdown ends with a full checkpoint, so maintenance restarts are fast regardless of the interval; only crashes pay. ## Validating and revisiting Make the choice testable: run a real crash-and-recover drill on production-scale data at production write rates, measure it, and keep measuring after workload growth. Watch how much log was replayed, how long undo took, and how long p99 latency stayed degraded after startup while the cache re-warmed. If recovery time is dominated by the cold cache rather than by replay, the checkpoint interval is no longer the lever and warm-up or failover is. ## The answer in one line Set the longest interval that meets a measured recovery objective, price the shortening in write amplification and full-page-image log volume, and recognize that with a good failover story the whole tradeoff shifts toward steady-state cost.

  • Does lengthening the checkpoint interval increase the risk of losing committed data?
    No. Committed data is durable because the write-ahead log is flushed at commit; the recovery point objective is unaffected by checkpoint frequency. A longer interval only means more log to replay after a crash, so it costs recovery *time*, not data. Conflating the two is a common and serious mistake.
  • You configure a five-minute interval but measured recovery still replays far more than five minutes of log. What explains it?
    Replay starts at the oldest change among pages still dirty in the buffer pool, not at the last checkpoint record. A page dirtied long ago and never yet flushed drags that start point back, so the outstanding log exceeds one interval. Engines mitigate it by preferentially flushing long-dirty pages, and the fix is to look at dirty-page age and background-writer behaviour rather than only at the interval.
  • How does having a hot standby with automatic failover change how you set this?
    It largely decouples user-visible downtime from crash recovery on the primary, because the service fails over instead of waiting for replay. That frees you to lengthen the interval and optimize for steady-state write amplification and log volume. The caveat is that the standby must itself be caught up and able to take over, so replication lag and failover reliability become the numbers to watch instead.

saying these in an interview costs you the question

  • Quoting a fixed interval with no reference to a recovery objective or measurement
  • Claiming a longer interval risks losing committed transactions
  • Assuming more frequent checkpoints always reduce log size
  • Ignoring that a long-dirty page can push the recovery start point earlier than the last checkpoint
  • Never validating the choice with an actual crash-and-recover drill

context