Design a Distributed File Ingestion and Threat Analysis Platform
System DesignModel answerLast updated
Design an async, high-throughput system that ingests large files, fans out to multiple scan engines in isolation, and delivers a consolidated threat report.
Distributed File Ingestion and Threat Analysis Platform
Your task is to design a backend platform that lets authenticated users submit files for automated threat analysis. Uploaded files are passed concurrently through several independent scanning engines. The platform then consolidates the results into a single report and alerts the user when the process is complete.
Functional Requirements
- Authenticated users can upload files as large as 500 MB.
- Every uploaded file is scanned simultaneously by multiple analysis engines (internal or third-party).
- Users can check the current status of a submission and retrieve the final report at any time.
- Any file flagged as a threat by at least one engine must be isolated from general access immediately.
Non-Functional Requirements
- Uploaded files must be durable and the ingestion path highly available.
- The system must scale horizontally to absorb traffic spikes without dropping jobs.
- Scan engine health, latency, and queue depth must be observable in real time.
- The design must be security-first: scanning runs in an isolated environment, and untrusted files never reach end-users before a clean verdict.
What Your Answer Should Cover
- API Design — the key endpoints for submitting a file, polling status, and retrieving a report.
- Data Model — the schema for file metadata, scan jobs, and per-engine results.
- Architecture — a high-level diagram of the async workflow, including how events move from upload to verdict.
- Error Handling — how the system deals with engine failures, partial results, timed-out jobs, and malformed uploads.
Spend the first few minutes asking clarifying questions and stating your scale assumptions out loud before jumping into the design.
Hints
Hint 1
Large files should never stream through your application servers. Think about how object storage presigned URLs let the client write bytes directly to the bucket, keeping your API tier stateless and cheap.
Hint 2
Each scan engine should have its own queue or topic. This prevents a slow or failing vendor from blocking progress on the other engines, and lets you scale and rate-limit each one independently.
Hint 3
Think through what 'partial results' means when a deadline is hit or an engine errors out. You need an explicit policy — and an explicit state in your schema — for every terminal condition, not just the happy path.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify Requirements and Nail Down Scale
Start here before drawing anything. State your assumptions out loud so the interviewer can correct them.
Scale assumptions:
- 1 M uploads per day → ~12/s average, bursts to ~170/s.
- Average file: 10 MB. Maximum: 500 MB. Raw ingest ~10 TB/day; dedup on SHA-256 cuts stored volume significantly because threat samples repeat heavily.
- 5 engines per file, each taking 10–60 s. That is 5 M engine jobs/day (~58/s). At 30 s average, steady-state concurrency is ~1,750 engine slots. Queues absorb bursts; you do not provision for peak.
- Latency target: report available within minutes. The upload response must never block on scanning.
- Retention: clean files for 30 days; quarantined files under indefinite legal hold.
Key clarifying question: must a file be fully cleared before users can access or share it? Assume yes — every file is untrusted until a clean verdict is issued ("quarantine by default").
2. API Design
POST /v1/uploads
body: { filename, size_bytes, sha256 }
resp: { upload_id, presigned_put_urls[], expires_at }
POST /v1/uploads/{upload_id}/complete
resp: { scan_id, status: "QUEUED" }
GET /v1/scans/{scan_id}
resp: { status, verdict, engines: [{ name, status, verdict }] }
GET /v1/scans/{scan_id}/report
resp: full per-engine findings including signature names
POST /v1/webhooks
body: { url, events: ["scan.completed"] }
resp: { id, signing_secret }
How the upload works: the client declares the hash and size up front, then writes bytes directly to object storage via multipart presigned PUT URLs. This keeps 500 MB streams entirely off the application servers. All endpoints are authenticated at the gateway (OAuth 2 / JWT) and scoped to the requesting user or tenant.
3. Data Model
files — one row per unique content hash:
sha256 (PK), size_bytes, mime_magic, storage_key, state (STAGED | CLEAN | QUARANTINED), first_seen_at
scans — one row per user submission:
scan_id (PK), user_id, sha256 (FK), status (QUEUED | SCANNING | COMPLETE | PARTIAL | FAILED), verdict (CLEAN | MALICIOUS | SUSPICIOUS | INCONCLUSIVE), deadline_at, created_at, completed_at
engine_results — one row per (scan, engine) pair:
(scan_id, engine) (PK), engine_version, status (PENDING | DONE | TIMEOUT | ERROR), verdict, signature_name, attempts, latency_ms, raw_report_key
outbox — transactional outbox for reliable event emission:
event_id, type, payload, published_at
Storage choices: Postgres for relational state, object storage for raw engine output, Redis for the (sha256, engine_version) dedup cache.
4. High-Level Architecture
Client
→ API Gateway (authn, rate limiting)
→ Upload Service → presigned multipart URLs
Client ==bytes==> Staging Bucket (private, SSE-KMS, no public read)
Upload complete / bucket event
→ Orchestrator:
1. Validate hash, size, magic bytes
2. Check dedup cache
3. Write scan + engine_results(PENDING) + outbox entry (one transaction)
4. Fan out: one message per engine onto per-engine queues
Engine Workers (sandboxed microVMs)
→ Fetch file via short-lived single-object GET URL
→ Scan → upsert engine_result → emit result event
Aggregator
→ All engines terminal, or deadline reached → compute verdict
→ CLEAN: promote to clean bucket
→ MALICIOUS: move to quarantine bucket (separate KMS key)
→ Render report → publish scan.completed → Notification Service
Key architectural decisions:
- Per-engine queues prevent a slow vendor from head-of-line blocking the others; each scales and is rate-limited independently.
- Transactional outbox ensures DB state and emitted events never diverge — write them in the same transaction.
- Default-deny storage means files in staging are inaccessible to end-users. Only the aggregator can promote a file after a clean verdict.
5. Deep Dives
Sandboxed execution. Each engine job runs in an ephemeral microVM (Firecracker) or gVisor container with a read-only root filesystem, no outbound network except to the vendor endpoint if cloud-based, and hard CPU/memory/disk and wall-clock caps. Workers receive a single-object, short-lived GET URL — they never hold broad bucket credentials. The quarantine bucket uses a separate KMS key accessible only to the security-analysis role.
Verdict policy:
- Any engine returning high-confidence MALICIOUS short-circuits the scan: quarantine immediately, report updates as remaining engines finish.
- If the deadline passes with fewer than a quorum of engines complete (e.g., 3 of 5), the status is PARTIAL and the verdict is INCONCLUSIVE. The file stays in staging.
- Every engine's status is reported explicitly. Never silently drop a result.
Failure modes and mitigations:
| Failure | Mitigation |
|---|---|
| Engine timeout or error | Exponential backoff with jitter, N retries, then mark TIMEOUT/ERROR and route to DLQ |
| Duplicate delivery | (scan_id, engine) upsert is idempotent |
| Worker crash | Queue visibility timeout redelivers the job |
| Stuck scan | Sweeper process finalizes any scan past deadline_at |
| Hash mismatch on complete | Reject upload, delete object |
| Zip bombs / malformed archives | Decompression-ratio and size caps enforced inside the sandbox; result is UNSCANNABLE, treated as suspicious |
Dedup. Reuse a cached result for the same (sha256, engine_version). Invalidate when engine signatures update — a file clean yesterday may be detected today.
6. Trade-offs Worth Stating
- SQS vs. Kafka: SQS gives per-message visibility timeouts and native DLQs, which maps cleanly to job retry semantics. Kafka offers replay and higher throughput but makes per-message retry awkward. Prefer SQS here unless replay is a hard requirement.
- Wait for all engines vs. early verdict: waiting is more accurate. Returning a verdict as soon as one engine hits MALICIOUS reduces latency for the worst-case file but means the report is incomplete at notification time.
- Dedup reuse: saves cost and latency but risks stale verdicts if the cache key does not include engine version.
- MicroVM vs. container isolation: microVMs are stronger but cold-start is higher. Warm pools of pre-booted VMs cut this to under 100 ms.
Common Mistakes to Avoid
- Streaming large files through the app tier instead of using presigned URLs.
- A single shared queue for all engines — one slow vendor starves the rest.
- No explicit schema state for PARTIAL results, making it impossible to distinguish "still scanning" from "gave up with incomplete data."
- Granting workers broad bucket read credentials instead of single-object, time-limited URLs.
- Forgetting the sweeper: without it, a crashed aggregator leaves scans stuck in SCANNING forever.