Loading...
A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
The prompt: a user drops a 200-page PDF into a chat and expects to ask questions about it soon after. Before that can happen, the file has to be stored, scanned, parsed, split into chunks, embedded, indexed, and reported as ready. Design that.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one upload end to end through your diagram, from the user's laptop to the first cited answer. Argue the tradeoff, not "industry standard."
Read this before you go in. These are the decisions, and why they matter.
Through your API. The obvious first draft: the client streams the file to an upload service. It works for one user. At a bulk-import peak it means your API fleet proxies gigabits of file data for no benefit, and a dropped connection at 90% starts over.
Straight to object storage. The API validates type and size, then hands back pre-signed URLs, one per part of a multipart upload. The client sends parts directly to the Blob Store and retries only a failed part. The API never touches file bytes. This is the default.
Xu's Google Drive design sends bytes through block servers that chunk, compress and encrypt. That is right for a sync client doing delta sync. A chat upload has no delta sync, so direct upload is simpler. Knowing why the two differ is a good answer.
The contract is: never lose an acknowledged upload, and never make the request wait for processing.
So acknowledge only after the multipart upload is complete in storage and the file row is committed as uploaded. Then return 202 and let processing run on its own. Storage events are delivered at least once and can arrive late or twice, so do not bet the promise on one event: write an outbox row in the same transaction, and run a sweep that finds files stuck in uploaded.
One job per file. Parse, OCR, chunk, embed and index in one worker. If embedding fails at chunk 580 of 600, the retry re-parses and re-OCRs everything. The user sees the bar jump back from 97%. Interviewers call this out by name.
A stage per step. Each stage (scan, parse/OCR, chunk, embed, index) gets its own queue, worker pool, retry policy and checkpoint. Each writes a durable output for the next: parsed text to the Blob Store, chunks to a table, vectors to the index. A crash repeats one stage.
Then classify failures. They are not all "retry 3 times":
Queues and storage events deliver at least once. Every stage runs at least once. So every stage must be safe to repeat.
(file_id, chunk_seq). Writes are upserts.Replay any stage and you converge on the same 600 chunks, not 1,200.
Dedup. Hash the file during upload. Ten teammates uploading the same handbook get one processed copy and ten references. When someone uploads a revised version, re-embed only the chunks whose text changed (key reuse by the chunk's text hash, since an insertion shifts every later sequence number).
Keep dedup inside a tenant. If a different company's upload comes back "ready" instantly, you have told them someone else already has that exact file.
"Processing..." is not progress. Job metadata already knows pages parsed and chunks embedded; expose that per stage, by polling or push.
Can a user ask about page 12 while page 400 is still in OCR? Chunks are searchable the moment they are indexed, so you can allow it. If you do, retrieval returns only indexed chunks, the answer must say coverage is partial, and the ready event clears that. The danger is the confident absence: "the contract does not mention arbitration," said while half the contract is unread. Either answer (allow it, or wait for ready) is fine if you state the retrieval contract.
Fairness. One company imports 50,000 files. Another user uploads one memo. With one FIFO queue, the memo waits hours. Use per-tenant queues with weighted round-robin, per-tenant concurrency caps, and ideally an interactive lane separate from bulk imports.
Isolation. Every chunk carries tenant_id, file_id and ACL tags. The retriever takes the tenant from the authenticated identity, never from the request or the model's tool call, and checks the user's current permissions at query time (sharing changes after upload). Filter inside the search, or partition the index by tenant: filtering after an approximate nearest-neighbour search can return almost nothing for a small tenant.
A file becomes an original, parsed text, hundreds of chunks, hundreds of vectors, keyword index entries, and maybe cached answers. Deleting the metadata row leaves all of that behind.
Hide first: mark it deleted and have the retriever skip it within seconds. Then purge each artifact type with its own idempotent, retried task. With dedup, only purge shared content when the last reference goes. A periodic sweep looks for orphans and alerts on any.
Vectors from two models live in different spaces. Mixing them quietly ruins retrieval. Keep a versioned index, re-embed into v2 from the stored chunk text (never re-parse a year of files), dual-write new uploads, and switch each tenant once its backfill is done. Queries must embed with the model that matches the tenant's version.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
Rough numbers are fine; the method is what gets graded.
How the graph works: the API is a thin control plane. Bytes go from the client to the Blob Store. A storage event starts a chain of queued stages, each writing a durable output and a checkpoint. The chat's retriever only ever reads the index, always filtered by tenant.
Web Client, Mobile Client
→ Load Balancer → Upload Service (pre-signed URLs, status) ── Postgres (files, stage jobs, chunks)
→ Blob Store (direct multipart PUT; originals + parsed text)
→ Pub/Sub Topic (upload-complete event)
→ SQS stage queues (one per stage, per-tenant weighted)
→ Worker pools (mark distributed): Scan → Parse/OCR → Chunk → Embed (ML Model on GPUs) → Index
→ Elasticsearch (vectors + BM25, tagged tenant_id / file_id / acl)
→ Queue (dead-letter)
Chat Service (agent) → Retrieval Service → Elasticsearch (filter by tenant + current ACLs)
Cron: reconciliation sweep (stuck uploads) + orphan sweep (deletions)
Components:
uploaded; orphan sweep that verifies deletions.uploading and returns pre-signed part URLs.uploaded plus an outbox row, and returns 202. That is the acknowledgement.(file_id, 0..599) to Postgres. Embed workers batch them to the GPU model, skipping any chunk that already has a vector.ready and pushes a status update.Sam uploads the same file: the hash matches a ready file in the same tenant. Sam gets a reference and ready immediately; nothing is uploaded or embedded.
Embedding hits a 429 at chunk 580: only the embed stage retries, with backoff. Parsed text and chunks are already durable; the 580 existing vectors are skipped.
Priya deletes it: hidden from retrieval within seconds, then per-artifact purges. Sam still references the content, so shared chunks and vectors stay until his reference goes too.
File(file_id, tenant_id, owner_id, name, size, content_hash, blob_key, status, deleted_at)
StageJob(file_id, stage, status, attempt, checkpoint, error_code, updated_at)
Chunk(file_id, seq, tenant_id, page, text, text_hash)
FileRef(tenant_id, user_id, file_id)
DeletionTask(file_id, artifact, status, verified_at)
VectorEntry(chunk_id, index_version, vector, tenant_id, file_id, acl_tags) -- in the index
(file_id, seq) makes replays upserts; text_hash enables reuse on revisionstenant_id; partition the index by tenant (large tenants get their own shard)Kafka or RabbitMQ instead of SQS. A workflow engine driving stages instead of each worker enqueueing the next. pgvector, OpenSearch or a managed vector DB instead of Elasticsearch. Polling instead of push for status. All-or-nothing ready instead of partial availability. What matters is that you can argue the tradeoff.