Quick revision
The short answer
POST /exports returns 202 Accepted with an operation resource, and the export runs as a background job with states QUEUED, RUNNING, SUCCEEDED, FAILED and CANCELLED, cancellable by the client. Workers write results to object storage in compressed chunks of about 1 GB, and the finished operation lists presigned download URLs with an expiry, so data never passes through API pods. Work is queued per tenant and scheduled fairly with round robin and per-tenant concurrency caps, exports are resumable by tracking completed chunks and read from a replica or snapshot, and quotas, retention, completion webhooks and per-tenant usage records complete the design.
What to remember
In this answer, we designed an export API where POST /exports returns 202 with an operation resource that moves through QUEUED, RUNNING, SUCCEEDED, FAILED and CANCELLED. Workers write compressed 1 GB chunks to object storage and clients download them through presigned URLs, never through API pods. Per-tenant queues with round robin and concurrency caps share capacity fairly, chunk tracking and leases make exports resumable, replicas or snapshots protect production and give consistency, and quotas, retention, webhooks and usage records complete the product.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
POST /exports returns 202 Accepted with an operation resource, and the export runs as a background job with states QUEUED, RUNNING, SUCCEEDED, FAILED and CANCELLED, cancellable by the client. Workers write results to object storage in compressed chunks of about 1 GB, and the finished operation lists presigned download URLs with an expiry, so data never passes through API pods. Work is queued per tenant and scheduled fairly with round robin and per-tenant concurrency caps, exports are resumable by tracking completed chunks and read from a replica or snapshot, and quotas, retention, completion webhooks and per-tenant usage records complete the design.
Why this question is asked
Exports of up to 200 GB cannot live inside an HTTP request: no load balancer, client or pod is happy holding a connection open for hours, and a single failure would mean starting over. The scenario adds a second problem, one tenant taking all the capacity, which is a fairness question as much as a technical one. Interviewers ask this to see whether we can design the API contract, the execution engine and the capacity model together. In this answer, we will size the work, design the operation API, follow an export from request to download, design fair scheduling across tenants, make exports resumable and safe for production, and close with quotas, notifications and billing.
1Requirements and Rough Numbers
A 200 GB export read at a sustained 100 MB per second takes about 35 minutes of pure reading, and with transformation and compression realistically one to two hours. Compressed with gzip or zstd, text-based formats such as CSV or JSON Lines often shrink by a factor of 5 to 10, so the output might be 20 to 40 GB. Clients need to download that reliably, so it should come in pieces they can fetch in parallel and retry individually. If the platform has, say, 40 export workers, one tenant submitting 40 large exports could occupy all of them for hours, which is exactly today's problem. These numbers drive three decisions: background execution, chunked output in object storage, and per-tenant scheduling.
2The Operation API
POST /exports takes the data set, filters and format, validates them, checks quotas, and returns 202 Accepted with an operation resource and its URL. The operation has explicit states: QUEUED while waiting for a worker, RUNNING with progress, SUCCEEDED with its results, FAILED with a structured error, and CANCELLED. The client can cancel with DELETE /exports/{id} or POST /exports/{id}:cancel; workers check a cancel flag between chunks and stop promptly. GET /exports/{id} returns the state, and Retry-After keeps polling sensible; a webhook notifies on completion for clients that prefer not to poll.
Notice that the files are links to object storage, not data in the response, and each has a size and checksum so the client can verify its download.
3From Request to Download
A worker that picks up the export reads the data in ranges, by primary key or time, streams the rows through a serialiser and a compressor, and uploads the output to object storage such as S3 as a sequence of chunks of about 1 GB each, using multipart upload for each file. After each chunk, it records the chunk in the operation's metadata. When all chunks are written, the operation becomes SUCCEEDED.
For download, the API generates presigned URLs, links signed with a short expiry such as one hour that let the client download one object directly from storage without our credentials. The data never passes through API pods, which keeps them small and fast, and object storage serves parallel downloads at high throughput. Each GET of the operation produces fresh URLs, so expiry is not a problem for slow clients.
11 messages in order. Play them, or step through them one at a time.
4Sharing Capacity Fairly Between Tenants
A single global FIFO queue is what lets one tenant take everything: its 40 jobs are ahead of everyone else's one job. Instead, each tenant has its own queue, and the scheduler picks the next job by going round robin across tenants that have queued work. Combined with a per-tenant concurrency cap, for example at most 3 running exports per tenant, or a cap proportional to the tenant's plan, no tenant can hold more than its share of workers, and a small tenant's single export starts within minutes even while a large tenant has 40 waiting.
Weighted fair sharing extends this: tenants on higher plans get a larger weight, so they receive proportionally more worker time when the system is busy, but they still cannot starve others. If capacity is idle, a tenant may temporarily exceed its share, since unused workers help nobody. The scheduler can be a small service over a jobs table with SKIP LOCKED queries, or a queue system with per-tenant partitions.
- Next tenant in round robin order
- Tenant has queued exports?YesCheck its running countNoMove to next tenant
- Running below tenant cap?YesStart its oldest export on a free workerNoSkip tenant this round
- Free workers left?YesContinue the roundNoWait for a worker to finish
4 steps in order. Play them, or step through them one at a time.
5Resumable Exports That Do Not Hurt Production
A two-hour job will meet deployments and pod failures. Because the worker records each completed chunk, together with the key range it covered, a restarted job skips finished chunks and continues with the next range instead of starting over. Workers use leases and heartbeats so a dead worker's export is reclaimed, and chunk writes are idempotent: rewriting part-0008 to the same key gives the same result.
Reading 200 GB from the primary database would compete with production traffic for hours. Exports read from a read replica dedicated to analytics, or from a snapshot such as a database snapshot or the data lake copy, with a throttle on read rate. Reading from a snapshot also gives the export a consistent point in time, recorded as snapshot_at in the operation.
6Quotas, Retention, Notifications and Billing
Each tenant has quotas on concurrent exports, total bytes per day and maximum export size, checked at POST time so a request beyond them is refused immediately with a clear error rather than queued forever. Results are retained for a fixed period, for example 7 days, after which a storage lifecycle rule deletes them and the operation reports EXPIRED. A webhook on completion or failure saves clients from polling. Finally, every export records usage per tenant, rows, bytes read, bytes written, worker minutes, so we can bill or at least show heavy users what they consume, and see when capacity needs to grow.
7Follow-up questions
How do you keep the export consistent if data changes while it runs?
Read from a consistent point in time. The cleanest option is a snapshot: a database or storage snapshot, or a data lake table version, taken when the export starts, so every chunk reads the same state. On PostgreSQL, a long REPEATABLE READ transaction on a replica would also give a consistent view, but holding it for hours can conflict with replication and vacuum, so snapshots are usually safer. If neither is possible, we export by an immutable or monotonic key range and document that the export reflects data as of each range's read time; recording snapshot_at in the result tells the client which point in time they have, and they can use a change feed from there.
Why chunks of about 1 GB?
Large enough to keep the number of files manageable (200 to 400 for the largest export), small enough that a failed download or a restarted chunk costs little to redo, and convenient for clients that process files in parallel.
8Conclusion
In this answer, we designed an export API where POST /exports returns 202 with an operation resource that moves through QUEUED, RUNNING, SUCCEEDED, FAILED and CANCELLED. Workers write compressed 1 GB chunks to object storage and clients download them through presigned URLs, never through API pods. Per-tenant queues with round robin and concurrency caps share capacity fairly, chunk tracking and leases make exports resumable, replicas or snapshots protect production and give consistency, and quotas, retention, webhooks and usage records complete the product.
Open with
I would turn exports into long-running operations. POST /exports validates the request, checks quotas and returns 202 with an operation resource. The operation moves through QUEUED, RUNNING, SUCCEEDED, FAILED and CANCELLED, the client can cancel it, and it gets Retry-After for polling and a webhook on completion.
Then, if they want more
Workers read the data in key or time ranges, from a read replica or a snapshot so production is not affected and the result is consistent, and they write compressed chunks of about a gigabyte to object storage.
The finished operation lists the files with sizes, checksums and presigned URLs that expire, so 200 gigabytes never pass through our API pods and clients can download parts in parallel. For fairness, I would not use one global queue.
Each tenant has its own queue, the scheduler goes round robin across tenants, and each tenant has a concurrency cap, maybe weighted by plan, so one tenant cannot hold every worker and a small tenant's export starts quickly.
Exports are resumable: the worker records each completed chunk, uses a lease with heartbeats, and a restarted job continues from the next chunk instead of starting over. Finally, quotas on size and concurrency, results kept for something like seven days, notifications, and usage recorded per tenant for billing and capacity planning.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the export API and backend, including how results are delivered and how capacity...": https://scrivio-interview-library.netlify.app/architecture/api-design-at-scale/abb191f10e/