The interview problem

Practice prompt

Design a service that exports up to 2 TB of a customer's records while the application continues accepting writes. Exports must represent one consistent data view, survive worker retries and support resumable downloads. Explain what happens if the source snapshot disappears or the requesting user's access is revoked.

Original system-design practice, not a reported company interview. Sizes and throughput are hypothetical. PostgreSQL primary documentation retrieved September 27, 2026; publication date not established. Interview date: not applicable.

1. Name the view being exported

Define the export as records visible in a specified consistent database snapshot, with a fixed schema, tenant scope and selection predicate. Completion time is not the data's freshness time. Return the snapshot's logical identifier and descriptive capture time, without implying that a wall-clock timestamp alone can recreate its visibility rules.

For example, account A has balance 100 and B has zero. A transfer atomically makes them 70 and 30. An export that reads A before the transfer and B afterward reports 130 total, even though no committed database state had that total. Reading each partition correctly at a different time does not create a consistent full export.

Decide how attachments and external stores participate. A relational snapshot does not freeze a mutable object URL. Export immutable object versions referenced by that snapshot or document a weaker cross-store contract. This baseline requires referenced attachment versions to remain available. A missing required version fails the generation; it is not silently omitted. A metadata-only export is a separately requested format.

2. Separate generation from publication

authorized export request → durable job + snapshot lease
                                  ↓
                        fixed partition manifest
                                  ↓
                  bounded workers → immutable part objects
                                  ↓
                      validation + final manifest commit
                                  ↓
                  authenticated download / resume gateway

A job contains tenant, request owner, selection parameters, schema version, snapshot identity, generation, state and idempotency key. Retrying the same request returns the same job only when parameters match. Acquire the source snapshot when generation is admitted, not while the job waits indefinitely in the queue. Report that capture boundary to the customer; an export promised as of request time instead needs a durable historical view covering the queue delay. Keep customer quotas and source-read limits separate from worker concurrency; an export must not monopolize the production database.

Partition by disjoint stable key ranges or another complete partitioning of the snapshot. Each worker reads its assigned range in the same view, using deterministic keyset pagination. Offsets over changing live data can skip or duplicate records. For composite keys, persist the entire ordering key and use a strict continuation predicate.

Part metadata includes range, snapshot generation, row count, byte count, format version and checksum. Objects are private and immutable. A final manifest lists exactly the accepted parts. The job becomes READY only when that manifest is committed after completeness validation; a partially uploaded prefix is not an export.

3. Make snapshot lifetime part of recovery

PostgreSQL supports exporting a snapshot for other transactions to import while the exporting transaction remains open. The identifier is not a permanent checkpoint that can be imported after its owner ends. Keep the exporting transaction alive for workers and replacement workers that still need to import the view; account for the operational cost of retaining an old view.

For short bounded jobs, coordinated read transactions may suffice. For multi-hour exports, consider an isolated immutable database copy or a durable versioned analytical snapshot with enough retention for retries. Validate that it contains a consistent source boundary and required attachment versions. A replica that continues changing is not automatically an immutable export source.

If the required snapshot can no longer be read, mark the generation invalid and restart against a new snapshot. Do not reuse old parts with new parts from the new view merely because their key ranges do not overlap. Customers receive an explicit restart and new snapshot identity. Preserving a few completed files is less important than preserving the promised consistency.

4. Retry parts without publishing duplicates

Workers use attempt-specific temporary object names. After upload and checksum validation, a conditional metadata transition chooses the accepted attempt for that partition and generation. A worker that lost ownership may finish uploading, but cannot change the accepted manifest. Unreferenced attempt objects are collected later.

Persist progress only at a boundary that is recoverable. One simple approach makes each part atomic: if its upload or encoding is incomplete, repeat that part from its start. A row cursor advanced ahead of durable output can lose records. A cursor behind durable output can duplicate them unless the output and continuation protocol accounts for the overlap.

Validate that expected ranges appear once, accepted parts belong to one snapshot and schema, and each range query follows its assigned boundaries. Checksums detect corruption, not semantic completeness: a perfectly hashed file can still omit rows. For high-value exports, compare independently computed snapshot counts or aggregates where their cost is acceptable.

5. Calculate export and recovery cost

Use decimal units here: 2 TB is 2,000,000 MB. At an effective source-read rate of 200 MB/s, scanning takes 10,000 seconds, or 2 hours 46 minutes 40 seconds. If compression reduces output to 1 TB and upload capacity is 100 MB/s, upload also takes 10,000 seconds. With full streaming overlap, the throughput lower bound is the slower stage, about 2 hours 46 minutes 40 seconds, not their sum. Encoding, snapshot setup, skew and validation add time.

Splitting the 1 TB output into nominal 1 GB parts yields 1,000 parts. Ten failed parts require about 10 GB of replacement output, assuming each failed part is repeated once. Retrying one monolithic archive could require the entire terabyte. Individual compression frames or independently compressed parts support restart boundaries better than an arbitrary byte cut through a single compressed stream.

Ten workers at 30 MB/s each do not yield 300 MB/s when the shared source is capped at 200 MB/s. Similarly, a slow large partition determines the tail even when average utilization looks low. Split oversized ranges using snapshot-safe boundaries and update the partition plan atomically so parent and child ranges cannot both appear in the final manifest.

6. Make resume and revocation compatible

A client resumes a specific immutable part at a byte offset and verifies its checksum after completion. Bind continuation to export generation and object version; a changed object must not silently reuse an old offset. The client can download remaining parts from the manifest rather than reconstructing worker state.

Recheck tenant membership and export permission at download authorization. For stronger revocation, serve through a gateway that checks access on each range request, with bounded transfer chunks and an explicit policy for active streams. Already delivered bytes cannot be recalled. Short-lived signed URLs reduce exposure time but are bearer capabilities and may remain usable until expiry under the storage service's contract.

Keep export retention separate from source retention. Expired jobs stop issuing downloads, while lifecycle cleanup removes their objects after the defined grace period. A canceled job cannot be published by a late worker: manifest commitment checks current job state and generation. Logs contain job metadata rather than exported customer records or bearer URLs.

7. Failure analysis and follow-ups

Test source updates during scanning, snapshot-owner loss, worker crashes after upload, duplicate attempts, canceled jobs with late completion, revoked users and missing attachment versions. Monitor queue age, source load, bytes processed, slowest partition, orphan storage, generation restarts and authorization failures.

Follow-ups: Can a checksum prove all records are present? No. Can a new snapshot complete an old manifest? Not under this contract. Does job acceptance promise immediate generation? Quotas may queue it. Can a long-lived download link guarantee immediate revocation? No. Should exports always be one ZIP file? A manifest of independently verifiable parts may better fit scale and recovery.

Score 0–2 each for snapshot semantics, partition completeness, retry publication, capacity math and access/retention handling. A strong answer explains why resuming work requires preserving the data view as well as the cursor.

Sources and next steps

The architecture, transfer example and sizing calculations are original. Compare database backup and restore for recovery rather than customer-scoped exports.

Continue your preparation

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