Multi-Region File Distribution with Tenant Isolation
System DesignModel answerLast updated
Design a scalable pipeline that replicates large immutable files from a central location to multiple per-tenant destinations with guaranteed delivery and strict isolation.
You're designing a distributed system for a multi-tenant platform. The system must replicate large immutable files—such as recorded customer calls—from a central production location to multiple storage endpoints specific to each tenant. Every tenant configures their own set of target locations, and files belonging to one tenant must never be accessible to another.
The business requires strong guarantees: no file may be lost, and for audit and compliance purposes, the system must report whether each file has successfully reached all of its intended destinations.
Approach this design incrementally. Begin with a minimal working design for a single source and destination, then layer in asynchronous distribution to multiple endpoints, robust failure handling, and finally tenant isolation and fairness under load.
Assumptions and Open Questions
- File size distribution and daily throughput are undefined—make parametric estimates and ask for concrete numbers.
- Files do not change after creation.
- Each tenant's destination list is stored as configuration and may evolve over time.
- Whether the source retains or deletes files post-transfer is a business decision to clarify.
Questions to Ask
- What are typical and maximum file sizes? What is the daily file creation rate at peak?
- What is the acceptable replication latency from file creation to availability at all destinations?
- Should the source preserve files after successful replication, or delete them to save space?
- Are destinations platform-managed storage in other regions, or customer-controlled endpoints? What protocols are supported?
- Should a destination file become visible only after the entire transfer is verified?
- Are there data residency or sovereignty constraints that restrict where a tenant's data may transit or temporarily reside?
Part 1 — Minimal Working Design
Describe a straightforward design for replicating a single file to one destination per tenant. Identify the core components, data flow, and the limitations that make this approach insufficient.
Expected coverage:
- End-to-end component flow with clear responsibilities
- Metadata tracking for files and their transfer state
- Why a synchronous approach fails for large files and many tenants
Part 2 — Asynchronous Multi-Destination Replication
Extend the design to handle fan-out: each file is replicated to all destinations configured for its owning tenant. Use message queues and worker pools. Explain how replication work is created, distributed, and tracked, and how large files are transferred efficiently without blocking.
Expected coverage:
- Mechanism for generating per-destination transfer tasks from file events without loss
- Chunked, resumable transfers with checksum verification
- Decoupling destination availability from overall system health
- Data model and APIs for monitoring replication progress
Part 3 — Handling Failures and Ensuring Consistency
Workers crash, destinations become unreachable, events are processed multiple times, and data corruption occurs in transit. Show how the design guarantees eventual delivery of every file to every destination, intact and without duplication, and ensures partial transfers are never exposed.
Expected coverage:
- Retry policies, task leases, and dead-letter queues for failed tasks
- Idempotent operations and atomic commit at destinations
- Checksum validation and periodic reconciliation to detect missed work
- Graceful degradation during prolonged destination outages
Part 4 — Tenant Isolation and Fairness at Scale
Demonstrate how the design enforces strict tenant boundaries so files cannot reach unintended destinations, and how it maintains performance and fairness when tenant workloads vary widely or the tenant count grows.
Expected coverage:
- Credential and encryption-key scoping per tenant
- Fair queuing or scheduling to prevent one tenant from monopolizing resources
- Horizontal scaling strategy and identifying the true bottleneck (cross-region bandwidth)
Hints
Hint 1
Start by clarifying file size and throughput—these drive storage, network, and worker capacity decisions.
Hint 2
Use message queues to decouple file production from replication, and partition work by destination to isolate failures.
Hint 3
Idempotency and atomic visibility (write-then-rename or upload-then-commit) prevent partial files from being read.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
A strong candidate walks through the design in stages, justifying each layer of complexity with concrete failure modes or scale requirements, and grounds decisions in parametric estimates.
Clarifying Questions and Estimates
Before diving in, ask:
- File size and volume: Are files typically 10 MB, 500 MB, or multi-GB? How many files per day at peak—hundreds, thousands, or millions?
- Latency: Must files reach destinations in seconds, minutes, or hours?
- Source retention: Do we keep the source copy indefinitely, or delete once all destinations confirm?
- Destination ownership: Are these cloud storage buckets we control, or customer-provided SFTP/S3 endpoints?
- Visibility: Should files appear atomically at destinations, or can they be readable while uploading?
- Residency: Are there geographic restrictions on where data may be stored or routed?
Parametric estimate:
Assume 100,000 files/day, average 200 MB, peak 1 GB. Average 3 destinations per tenant, 1,000 tenants. That's ~20 TB/day source, ~60 TB/day egress. Peak concurrency: ~1,000 files in flight. Replication SLA: files available within 15 minutes.
Part 1 — Minimal Working Design
Components:
- File Producer: The recording service writes completed files to object storage (S3) in the source region and publishes an event to a message broker (Kafka, SQS) with file ID, tenant ID, size, and checksum.
- Replication Service: A worker process consumes events, looks up the tenant's destination, streams the file from source to destination, verifies the checksum, and marks the transfer complete in a tracking database (Postgres or DynamoDB).
- Tracking Database: Stores rows like
(file_id, tenant_id, destination_id, status, checksum, timestamp).
Flow:
- File finishes → event published.
- Worker pulls event, fetches file, uploads to destination, verifies checksum.
- Worker writes
status=completedto tracking DB.
Limitations:
- Synchronous bottleneck: If a destination is slow or unavailable, the worker blocks, reducing throughput.
- No fan-out: With multiple destinations per tenant, a single event must trigger multiple transfers—hard to scale and retry independently.
- Large file inefficiency: Streaming a 1 GB file in one shot is fragile; network hiccups force full retries.
Part 2 — Asynchronous Multi-Destination Fan-Out
Architecture:
- Event Publisher: When a file completes, publish one event per (file, destination) pair to a work queue. A small service reads tenant configuration, fans out events, and ensures each destination gets exactly one task.
- Transfer Queue: Use SQS or Kafka partitioned by destination. Each message contains
{file_id, tenant_id, destination_id, source_url, checksum}. - Worker Pool: Horizontally scaled workers consume tasks, perform chunked multipart uploads (e.g., S3 multipart, resumable HTTP), verify checksums, and mark completion.
- Chunked Transfer: Split large files into 10–50 MB chunks. Upload each chunk, retrying failed chunks independently. Once all chunks succeed, commit the file atomically (S3 CompleteMultipartUpload or write a
.completemarker). - Tracking Database: Schema includes
(file_id, destination_id, status, chunk_progress, checksum, retry_count, last_attempt).
Data Flow:
- File completion event → fan-out service looks up tenant destinations → enqueues N tasks.
- Worker picks task, starts multipart upload, uploads chunks with retries, completes upload.
- Worker verifies checksum, updates tracking DB to
status=verified. - API exposes replication status per file: "2/3 destinations complete."
Isolation of Failures:
If destination B is down, only tasks for B retry and backlog; destinations A and C proceed normally.
API Example:
GET /files/{file_id}/replication
→ {file_id, tenant_id, destinations: [{id, status, completed_at, retries}]}
Part 3 — Failures, Retries, and Consistency
Failure Scenarios:
- Worker crashes mid-transfer: Incomplete multipart upload left on destination.
- Destination unreachable for hours: Tasks pile up in queue.
- Event delivered twice: Duplicate tasks for the same (file, destination).
- Data corruption in transit: Bytes arrive but checksum doesn't match.
Solutions:
-
Task Leases: Workers take a visibility timeout lease (e.g., 10 minutes) on queue messages. If the worker crashes, the lease expires and another worker retries.
-
Idempotent Writes: Before starting a new multipart upload, check if the file already exists at the destination with the correct checksum. If so, skip and mark complete. Use unique upload IDs tied to file_id + destination to avoid duplicates.
-
Retry Policy: Exponential backoff with jitter. After N failures (e.g., 10), move task to a dead-letter queue for manual review.
-
Checksum Verification: After upload completes, compute checksum of the destination file and compare to source. Mismatch → delete and retry.
-
Atomic Visibility: Use two-phase commit pattern:
- Upload to a temporary path or staging area.
- Verify checksum.
- Atomically rename or move to the final path (S3 copy-then-delete, or filesystem rename).
- Only then mark
status=complete.
Clients reading from the destination never see partial files.
-
Reconciliation: Daily batch job scans source files from the last 7 days and compares with tracking DB. For any file missing a
completedentry for a configured destination, re-enqueue a task. This catches lost events or DB update failures.
Long Outage Behavior:
Tasks for the unavailable destination accumulate in the queue. Set a max queue depth alarm. Once the destination recovers, workers drain the backlog. DLQ ensures truly stuck tasks don't block others.
Part 4 — Tenant Isolation and Fairness
Tenant Isolation Mechanisms:
- Credential Scoping: Each tenant has dedicated IAM roles or access keys scoped to only their destination buckets. Workers assume the tenant's role before uploading. Misrouting a file to the wrong destination fails at the authentication layer.
- Encryption: Encrypt files at rest and in transit using tenant-specific encryption keys (KMS per tenant). Even if a file is written to the wrong bucket, it's unreadable without the correct key.
- Path Namespacing: Destination paths include tenant_id:
s3://dest-bucket/{tenant_id}/{file_id}. Workers validate tenant_id in the task matches the destination config. - Network Segmentation: If destinations are customer VPCs, use private links or VPN tunnels per tenant, preventing cross-tenant traffic.
Fairness and Scale:
- Fair Queuing: Partition the transfer queue by tenant. Workers round-robin across tenant partitions, ensuring one tenant's 100k-file backlog doesn't starve another tenant's 10 files. Alternatively, use weighted fair queuing based on tenant tier.
- Rate Limiting: Apply per-tenant egress quotas to prevent a single tenant from saturating cross-region bandwidth links.
- Horizontal Scaling: Add workers as file volume grows. Workers are stateless, pulling from queues, so scaling is straightforward.
- Bottleneck: The true limit is cross-data-center bandwidth. If aggregate egress is 10 Gbps and we need 60 TB/day, that's ~5.5 Gbps sustained—still within limits. For higher throughput, negotiate dedicated links or use CDN-style edge replication.
Monitoring:
- Per-Tenant Dashboards: Replication lag (time from file creation to completion), failure rate, queue depth.
- Reconciliation Alerts: Daily reconciliation mismatches trigger alerts.
- DLQ Monitoring: Tasks stuck in DLQ require ops review.
Summary of Key Decisions
| Aspect | Choice | Rationale |
|---|---|---|
| Event fan-out | One task per (file, destination) | Independent retries, isolated failures |
| Transfer method | Chunked multipart upload | Resumable, efficient for large files |
| Idempotency | Check-then-upload with checksum | Duplicate events don't cause re-upload |
| Atomic visibility | Write-to-temp, verify, rename | Clients never see partial files |
| Retry strategy | Exponential backoff + DLQ | Handles transient and permanent failures |
| Tenant isolation | Scoped credentials + per-tenant keys | Enforced at infrastructure layer |
| Fairness | Partitioned queues by tenant | Prevents starvation under load |
This design achieves effectively-once delivery (at-least-once messaging + idempotent writes), strict tenant isolation, and horizontal scalability, while exposing clear replication status for compliance and auditing.