skip to content

How would you plan the initial CDC snapshot of a 4 TB production database that cannot absorb extra load?

level: principalimportance: should knowfreq 34%

answer

  1. duration is the variable every cost tracks
  2. retention must exceed duration with headroom
  3. the cheapest snapshot is the one you skip
  4. a replica moves I/O but not position portability
  5. make failure cost one chunk, not one week

basics

~20 s

Decide four things before touching the source: where the baseline comes from, where it is read, how it is paced, and whether the pinned log position survives the elapsed time. Duration against log retention is the constraint that governs all of them.

solid answer

~50 s

Start from the binding constraint: **projected snapshot duration must sit comfortably inside the source's log retention window**, because exceeding it destroys the baseline. Then work four decisions. *Where the baseline comes from* — a source scan, or an existing warehouse extract reconciled by primary key, or schema-only capture if nobody needs history. *Where it is read* — primary, or a replica, which moves the I/O but requires a log position that is meaningful on the primary, so a global transaction identifier rather than replica-local coordinates. *How it is paced* — chunked and throttled, ideally the watermark-based incremental form so streaming runs throughout and nothing is retained. *What the sink must guarantee* — idempotent, per-key-ordered upserts, so overlap at the seam and mid-backfill restarts are free. Then measure a representative table, extrapolate, and put alerting on retained log bytes and oldest-transaction age before you start.

code

text · 17 lines
text
1  Does anyone need history?
     no  -> schema-only capture, start at current log position. STOP.
2  Does history already exist as an extract?
     yes -> pin a position at/before its cut, stream forward,
            reconcile by primary key. STOP.
3  Can the capture set be trimmed?
     blobs, cold partitions, soft-deleted rows
4  Where does the scan read?
     replica -> require a portable log position (GTID, not file+offset)
     primary -> throttle against a source-latency SLO
5  How is it paced?
     watermark incremental (streams throughout)  <- default
     else chunked + checkpointed + parallel per table
6  Guardrails before starting
     projected duration  <<  log retention
     alerts: retained log bytes, oldest txn age, source p99
     explicit abort criterion

go deeper

for a junior

Understand the shape of the problem: reading four terabytes takes a long time, the database has to keep log data for the whole of it, and the pipeline needs a plan for both.

for a middle

Be able to name the levers — chunking, throttling, trimming the capture set, reading from a replica — and explain that each one is ultimately about shortening or de-risking elapsed time.

for a senior

Show a pilot-and-extrapolate method, the metrics you instrument before starting, and the correctness trap in replica-side snapshots where the pinned log position must be portable to the primary.

for a principal

Own the tradeoff explicitly: source impact against convergence time under a hard ceiling set by log retention, including whether the baseline should come from the source at all, and what downstream consumers are told about partial coverage.

## Frame the constraint before the plan Every cost in a large snapshot scales with elapsed time: log segments retained since the pinned position, superseded row versions the read view prevents reclaiming, read I/O stolen from the workload, and the exposure window in which a failure wastes everything done so far. So the first number to establish is **duration**, and the first invariant is that duration must sit well inside the source's log retention window with room for a stall. Get the number empirically. Scan one representative table with production-like pacing, measure rows per second and the effect on source latency, and extrapolate to 4 TB. Guessing here is what produces the hour-eleven failure. ## Decision one: does a source scan need to happen at all? The cheapest snapshot is one you do not run. - **Nobody needs history.** Cache invalidation, search indexing, audit streams and event-driven integrations often care only about the future. Capture schema only, start at the current log position, done. - **History already exists.** If a nightly full extract already lands in a warehouse, take the log position at or before that extract's cut, stream forward, and reconcile the extract by primary key. This is frequently the correct answer at 4 TB and is under-proposed in interviews. - **History is needed and lives only in the source.** Now you scan — but perhaps not all of it. Excluding blob columns, cold partitions and soft-deleted rows routinely removes most of the volume. ## Decision two: where the scan reads Reading from a **replica** removes the scan's I/O from the primary, which is often the whole point when the primary has no headroom. Two things must be checked: - **Log-position portability.** The position you pin must be interpretable against the stream you will consume. A global transaction identifier is a portable identity; raw file-and-offset coordinates are replica-local and mean something different on the primary. Getting this wrong anchors the handover to the wrong point and loses data silently. - **Engine support and replica health.** Some engines only allow logical decoding on a standby from recent versions, and a long scan puts the same version-retention pressure on the replica that it would have put on the primary — including the risk that the replica falls behind or has to cancel the query to keep applying changes. Reading from the **primary** with aggressive throttling is the simpler, less surprising option when the replica route is not clean. ## Decision three: how the scan is paced **Watermark-based incremental snapshot** is the strongest default at this size: chunked, resumable per chunk, no long read view, and — decisively — the log is consumed throughout, so nothing is retained and there is no catch-up cliff at the end. The prerequisite is a writable signalling table in the source, which is a political question as often as a technical one. If that is unavailable, use a chunked classic snapshot with checkpointing so a restart resumes at a chunk boundary, and parallelise across tables — or across key ranges of the largest table — up to the source's I/O tolerance. Parallelism converts directly into reduced duration, and duration is the thing every risk here is proportional to. Past a point it becomes the load you promised not to add, so pace it against a source-latency SLO and be willing to run over days. ## Decision four: what the sink must guarantee None of this is safe unless the sink applies changes **idempotently and in per-key order**. That single property makes seam overlap harmless, makes mid-backfill restarts free, and makes a targeted re-seed of one table a routine operation rather than an incident. If the sink cannot promise it, fix the sink before planning the snapshot — otherwise every strategy above degrades into a one-shot operation you must get right the first time. ## Sequencing and guardrails Order the work: prove the sink's idempotency, raise log retention and disk headroom, instrument retained log bytes, slot lag, oldest-transaction age and source latency, run a pilot on one large table, extrapolate, then start with an explicit abort criterion. Publish what consumers see during the backfill — a sink that is complete for some key ranges and empty for others is a correct intermediate state, but only if downstream knows. ## The tradeoff to own out loud You are trading **source impact against convergence time**, under a hard ceiling set by log retention. Going fast risks the OLTP workload; going slow risks the retention window and leaves consumers on partial data for longer. The lead's job is to name which of those the business can absorb, size the headroom explicitly, and choose the strategy that keeps a failure costing one chunk rather than one week.

  • Why is a global transaction identifier preferable to file-and-offset coordinates when snapshotting from a replica?
    A global identifier names a transaction in a way every node agrees on, so a position pinned on the replica means the same thing when you stream from the primary. File-and-offset coordinates describe a position in that node's own log file, and the same file and offset on another node points at unrelated data. Pinning the latter anchors the handover to the wrong place and loses changes with no error.
  • How do you decide between finishing the backfill fast and protecting the source?
    By naming the ceiling first: log retention bounds total duration, so the range of acceptable pacing is fixed before the debate starts. Within it, throttle against a source-latency objective rather than a throughput target, and be explicit with consumers that partial coverage is the intermediate state. If the only pacing that protects the source exceeds retention, the answer is not to go faster — it is to stop scanning the source and take the baseline from an existing extract.
  • What makes a targeted re-seed of a single table routine rather than an incident?
    Idempotent, per-key-ordered application at the sink plus a chunked backfill that reconciles against the live stream. Together they mean re-reading one table cannot corrupt anything, cannot disturb the other tables, and can be paused. Without them, re-seeding requires stopping the pipeline and re-snapshotting everything, which is why teams avoid it and let sink drift persist.
  • What would you tell downstream consumers before starting a multi-day backfill?
    That the sink is correct for the key ranges already covered and empty for the rest, that coverage advances in chunk order, and roughly when full coverage lands. Give them a way to see the boundary. Consumers that cannot tolerate partial coverage should read from a swap target that is published only on completion, rather than have the backfill slowed to protect them.

It is a stocktake of a warehouse that cannot close: you decide whether last month's count will do, whether to count from the security footage instead of the floor, and how many aisles a night you can walk without blocking the forklifts.

saying these in an interview costs you the question

  • Plans the snapshot without checking it against log retention
  • Assumes reading from a replica is free of correctness concerns
  • Never considers skipping the scan in favour of an existing extract
  • Maximises parallelism without a source-latency objective
  • Starts a multi-day backfill with no abort criterion or alerting

context