KatInterview

Secure Multi-Tenant Pipeline for Big Ledger File Processing

System DesignModel answer
MediumModel answerSystem Designsystem-designmultipart-uploadidempotency

Last updated

Design a service where enterprise tenants upload files up to 5 GB, which are processed asynchronously into versioned reconciliation reports, with resumable uploads, idempotent jobs, and strict isolation.

Problem

A payments platform lets enterprise customers submit very large batch files (transaction ledgers, bank statements, payment batches) in CSV, XML, or JSON, up to 5 GB each. After submission, the platform must validate and parse the records and produce reconciliation and compliance reports.

Design an authenticated service that accepts these uploads, analyzes them asynchronously, and publishes versioned reports, while keeping each tenant's data strictly separate.

Functional requirements

  • Resumable uploads: files up to 5 GB must survive flaky connections, using chunked or multipart transfer.
  • Asynchronous analysis: once an upload is assembled and verified, start a background validation and processing pipeline.
  • Idempotency and dedup: the same file, or a repeated trigger or webhook, must not be processed twice.
  • Versioned reports: produce reports (JSON and/or PDF summaries of anomalies and reconciled balances) that authorized users of the tenant can fetch, with each new run creating a new version.
  • Tenant isolation: no cross-tenant access in storage, in transit, or in compute.

Non-functional requirements

  • Reliability: an interrupted upload resumes without restarting from byte 0. A crashed worker never leaves a job stuck.
  • Scale: 10,000 uploads per day, with bursts of 50 concurrent large-file jobs.
  • Security: short-lived presigned access, encryption at rest and in transit, strict RBAC.
  • Latency: upload-init and upload-complete API calls respond within 200 ms. A 5 GB file is analyzed within 10 minutes.

What your answer should cover

  1. API design: endpoints to start an upload, track or register parts, finish the upload, and query job and report status.
  2. Storage: object layout, how parts are assembled, lifecycle rules.
  3. Processing pipeline: queues, worker pools, streaming and parallel parsing, job state management.
  4. Idempotency and recovery: network drops, duplicate requests, workers dying mid-task, and poisoned (malformed) records.
  5. Multi-tenancy: isolation in the data tier and fair sharing in the compute tier (rate limits, quotas).

Hints

Hint 1

Do the back-of-envelope math first: 10,000 uploads/day is a tiny request rate, so the real constraints are the 10-minute SLA for 5 GB (about 8.5 MB/s sustained) and fairness during bursts. That suggests splitting each file into shards.

Hint 2

Keep file bytes off your API servers: clients upload parts directly to object storage through presigned URLs, and the 'complete' call should only record intent and return quickly, with a background worker doing the actual assembly.

Hint 3

Make every stage safe to retry: use a unique dedupe key on jobs, deterministic output paths per shard, leases with heartbeats for workers, and a retry limit that diverts bad records or shards to a dead-letter/quarantine path.

Hint 4

For tenant isolation, think in layers: tenant ID taken from the auth token (never the body), per-tenant prefixes and encryption keys, row-level security in the database, and per-tenant concurrency quotas in the scheduler.