Design 5: Document processing system
Practice this questionOverview
An asynchronous pipeline turns uploads into validated extracted data and search indexes. It is primarily a workflow with AI stages.
Why this matters
Large documents take longer than interactive requests and can fail at several stages.
An everyday example
A mailroom receives, checks, sorts, and processes paperwork.
A technical example
POST /documents → 202/jobId; staff poll processing status.
How it works
- Validate/store
- Enqueue
- Parse/OCR
- Extract/chunk
- Validate
- Review/publish.
Architecture and flow
Upload → object storage → queue → sandboxed workers → reviewed records/index.
The insurance assistant example
Process repair invoices and policy documents.
When to use it
Repeated document intake and indexing.
When to avoid it
Avoid open-ended agents for a known processing sequence.
Interview answer
“I design durable jobs, stage-specific errors, idempotent processing, and reviewed publication.”
Benefits, trade-offs, and production considerations
Size worker pools by CPU/GPU/memory and provider quotas. Quarantine failures, cap retries, and measure extraction accuracy and queue age.