The interview problem

Practice prompt

Keep an analytical copy of a transactional database fresh within one minute. Bootstrap two terabytes of existing data while writes continue, recover from a six-hour outage, and propagate updates and deletes without silently losing records.

Original practice question, not a verified company interview. Reviewed September 26, 2026. Workload and performance figures are illustrative assumptions.

1. Define the copy's consistency contract

Ask whether the target is a current-state replica, a historical event archive or both. Assume keyed tables, an analytical current-state copy and a durable replay stream. Freshness is measured from committed source changes to queryable target state. Initially permit temporary cross-table inconsistency; a dashboard requiring atomic visibility across tables needs an additional publication protocol.

Spend 5 interview minutes on semantics, 10 on bootstrap, 10 on replay correctness, 10 on recovery and 10 on schema and operations. Database changes are not necessarily business events: one purchase may alter several rows, while an administrative correction can look like an ordinary update.

2. Separate capture, replay and materialization

Logical flow: source transaction log → capture connector → durable partitioned stream → target materializer → analytical tables. A control record stores source identity, stream generation, snapshot manifest, capture position and target progress. Events carry table identity, key, operation, schema version, transaction identity and an unambiguous source ordering token. Do not assume a timestamp alone orders concurrent changes.

Partition by stable row identity to preserve per-key order. The materializer atomically commits the row value (or deletion marker) together with its source version, applying only a newer version, and records stream progress after durable application. A crash between applying a row and checkpointing causes replay, so writes must be idempotent. Keep deletion versions long enough to prevent an older replayed upsert from resurrecting a deleted row.

For aggregated targets, blindly replaying “add ten” twice is unsafe even if overwriting a row would be safe. Either atomically deduplicate event IDs with aggregate updates or derive aggregates from an idempotently maintained base table. Consumer delivery guarantees do not automatically extend through an external database write.

3. Connect a consistent snapshot to the log

Use a database-supported snapshot/log-position handshake, not an arbitrary table scan followed by reading the latest log position. Establish a consistent read view associated with a recoverable log boundary and retain subsequent changes while scanning. Finish the snapshot manifest, then apply the corresponding log stream without a gap. The exact handshake depends on the database and connector version.

Consider a row scanned as balance 20 while a concurrent transaction changes it to 30. If capture begins after that transaction but the scan read the old row, the target can remain at 20 forever. Conversely, overlapping snapshot and streaming may duplicate state. A correct design proves coverage and controls overlap instead of guessing which event arrived first.

Load into a staging generation until the snapshot is complete. When parallel snapshot chunks are used, their progress and change reconciliation must follow a valid watermark protocol; independent current reads are not automatically one consistent snapshot. Do not let a slow snapshot row overwrite a later streamed update. Expose the analytical copy only after a declared readiness boundary.

4. Size bootstrap and outage recovery

At a sustainable scan/export rate of 100 MB/s, two decimal terabytes take at least 20,000 seconds, or 5 hours 33 minutes, before target indexing and contention. If the source generates 10 MB/s of retained log during that scan, at least 200 GB accumulates. Event payload size and source log size need separate measurement; indexes and unrelated tables can increase the latter.

Assume 20,000 captured events/second at 500 bytes each: 10 MB/s, or 864 GB/day of raw stream payload. Three replicas require 2.592 TB/day before compression and metadata. A six-hour consumer outage creates 432 million events. If the recovered target applies 60,000 events/second while new events arrive at 20,000, net backlog drain is 40,000/second: recovery takes 10,800 seconds, or three hours.

The one-minute freshness objective is therefore violated during recovery. Define a separate recovery objective and communicate stale-data status. Retention must exceed outage plus catch-up time with margin. Increasing consumers helps only if source partitions, target writes and key skew permit additional throughput.

5. Recover without silently changing history

If the connector loses its connection, resume from its durable position and expect possible replay. If the needed log has expired, stop and mark a gap; a fresh snapshot can restore current state but cannot reconstruct every intermediate historical event. Keep those two recovery outcomes distinct.

A stalled replication slot can retain log until source storage is exhausted. Monitor retained bytes, disk headroom and capture lag, not only consumer lag. Protect the source with an explicit incident policy: restoring capture, adding approved capacity or abandoning continuity and planning a resnapshot. Never silently discard a slot and declare the pipeline healthy.

After source failover, verify that the new primary's replication state and log lineage support continuation. A numeric offset from a different generation is not proof of continuity. Fence obsolete capture processes and reconcile source/target boundaries before resuming. For a poison event, quarantine details and block or explicitly mark the affected scope incomplete; skipping it invisibly breaks the copy's contract.

6. Handle schema and transaction boundaries

Version event schemas and test compatible additions before rollout. PostgreSQL logical decoding does not provide a general DDL event stream, so schema migration discovery needs an explicit control path; do not assume every ALTER TABLE arrives as a normal row event. Ensure captured tables expose the key/replica identity needed to identify updates and deletes. Renames, type narrowing and key changes need an explicit mapping or backfill plan. A source column deletion is not automatically a permission to purge historical copies, nor is a new schema necessarily understood by old consumers. Coordinate migration order and preserve raw events under the agreed retention policy.

If a source transaction changes an order and its items on different stream partitions, readers may see a temporary mismatch. For atomic analytical publication, stage transaction changes and publish only after a trustworthy completion marker confirms all expected events are present. Large transactions increase buffer requirements; a missing partition must not be mistaken for completion.

Reconcile sampled keys, row counts and partitioned checksums against comparable source/target watermarks. Equal counts alone miss wrong values and offsetting insert/delete errors. Track freshness, retries, rejected schemas, reconciliation mismatches and source storage pressure separately.

7. Defend the trade-off

Log capture reduces polling load and observes deletes, but depends on retention, privileges and database-specific behavior. Polling can be simpler for low-volume tables with reliable change markers, yet a timestamp field may miss deletes or concurrent updates. Periodic full exports are operationally simple when freshness requirements are loose.

Foundation: explain the snapshot gap. Senior: recover after target commit but before checkpoint. Staff: choose between protecting source availability and preserving historical continuity during a prolonged outage. Score 0–2 each for bootstrap correctness, replay semantics, capacity arithmetic, schema evolution and recovery honesty. Full credit needs mechanisms and limitations. Continue with message queues and feature pipelines.

Sources and next steps

The target protocol, scenario, calculations and self-review rubric are original educational material; implementation details must be checked against deployed database and connector versions.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.