# Design the AI document classification system.

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/7422/design-ai-document-classification-system
Source observed: 2026-11-04T21:22:55.331Z
Last checked: 2026-11-04T21:22:55.331+00:00
Indexed: 2026-11-05T00:11:43.086+00:00

---

# Design the AI document classification system.

We publish this as an Artificial Intelligence, Machine Learning, and System Design interview question for **Machine Learning Engineer** candidates. The page reports **1 interview**, associated with **LinkedIn**, and an interview experience shared **a month ago**.

## Interview experience

[LinkedIn senior machine-learning-engineer interview experience](https://www.aced.io/experiences/linkedin-senior-machine-learning-engineer-interview-b8803d)

The shared experience says the coding round was tricky because the problem is unpredictable; ML fundamentals and ML design were easier with preparation for regular ML system designs; AI coding should use models that run quickly rather than cutting-edge models; and behavioral questions were standard. The role was **Machine Learning Engineer · Senior / L5**.

## Community answer: AI Document Classification System: Design

### 1. Assumptions

The proposed design assumes:

- A multi-tenant SaaS product in which each tenant has its own taxonomy, such as invoice, contract, KYC, or claim form.
- PDFs, scans, images, Office files, and emails.
- Approximately **1M documents/day at peak**, with synchronous API and bulk batch traffic.
- A target of **p95 under 3s** for a synchronous single-page document.
- At least **95% accuracy** on automatically routed documents.
- A human-review path for the rest.
- PII and regulated data, requiring audit trails and tenant isolation.

### 2. High-level architecture

```text
Clients/Connectors (API, S3/SharePoint, Email)
        │
API Gateway (authN/Z, tenant context, rate limits)
        │
Ingestion Service ──► Object Store (raw, encrypted, per-tenant prefix)
        │
Message Bus (Kafka / SQS) ── doc.received
        │
Preprocessing: type detection → text extraction → OCR (scans)
                 → layout parsing → page splitting → PII masking
        │
                 doc.normalized
        │
Classification Cascade
  L0 Rules/fingerprints/metadata (cheap, exact)
  L1 Embeddings + lightweight classifier (fast)
  L2 LLM / multimodal model with taxonomy (hard)
        │
Confidence Router
  high ──► Result Store + doc.classified event
  low  ──► Human Review UI ──► labels ──► Feedback Store ──► Retraining
```

### 3. Key components

#### Ingestion

- Make uploads idempotent by using the content hash as a deduplication key.
- Perform virus scans and size and type validation.
- Store raw files in object storage.
- Send only metadata and pointers through the message bus; do not send large payloads.

#### Preprocessing

- Extract native text directly from text PDFs.
- Use OCR for scans and images, such as Textract, Azure Document Intelligence, or Tesseract when cost matters.
- Preserve layout features—headers, tables, and logos—as structured output rather than flattening them into text.
- Split multi-document bundles, such as a 40-page scan containing five documents, with a page-boundary model and classify each segment.
- Optionally redact PII before sending content to external model APIs.

#### Classification cascade

The cascade is the principal cost-versus-accuracy trade-off:

- **L0:** Deterministic rules using known form IDs, barcodes, sender or subject patterns, and template fingerprints. It handles **20–40%** of traffic at near-zero cost.
- **L1:** Embed text, optionally with layout and vision features, then classify with logistic regression, gradient boosting, or a small fine-tuned transformer. Use per-tenant heads on a shared base encoder so a new tenant can start with few-shot examples.
- **L2:** Use an LLM with the tenant taxonomy, label descriptions, and **3–5 retrieved examples** through kNN. Require structured JSON containing the label, confidence, and evidence span. Invoke L2 only when L1 confidence is below threshold, keeping LLM usage around **10–15%**.
- Return multi-label output with calibrated confidence. Use temperature scaling or isotonic calibration so thresholds are meaningful, and set thresholds per class according to the cost of error.

#### Routing and human review

- **Auto-accept:** confidence `≥ T_high`.
- **Review queue:** confidence between the thresholds.
- **Unknown/other:** confidence `≤ T_low`.
- The review UI shows the document, top-three predictions, and highlighted evidence.
- Reviewer corrections go into the feedback store.
- Active learning prioritizes low-confidence and high-disagreement samples, including L1-versus-L2 mismatches.

#### Taxonomy service

- Version labels, descriptions, examples, and thresholds for every tenant.
- Record `taxonomy_version` and `model_version` with every result so documents can be reprocessed when either changes.

### 4. Core data model

```text
documents(id, tenant_id, hash, source, status, storage_uri, created_at)
document_segments(id, doc_id, page_range)
classifications(id, segment_id, label, confidence, stage[L0|L1|L2|human], model_ver, taxonomy_ver, evidence, created_at)
feedback(id, classification_id, corrected_label, reviewer, ts)
taxonomies(tenant_id, version, labels_json, thresholds_json)
```

Metadata lives in Postgres; embeddings use pgvector, OpenSearch, or Pinecone; files use S3 or Blob storage; and events use Kafka.

### 5. API surface

```http
POST /v1/documents
POST /v1/documents?mode=sync
GET /v1/documents/{id}/classification
POST /v1/documents/{id}/feedback
PUT /v1/taxonomies
```

- `POST /v1/documents` is asynchronous and returns `doc_id`; `?mode=sync` is for small documents.
- Webhooks or events notify consumers with `doc.classified` and `doc.needs_review`.
- `PUT /v1/taxonomies` manages labels.

### 6. Non-functional design

#### Scalability

- Autoscale stateless workers on queue depth.
- Use a GPU pool for OCR/vision and batched L1 inference.
- Send L2 through a rate-limited model gateway with retries and fallback providers.
- Separate synchronous and bulk queues so batch jobs cannot starve interactive requests.
- Use priority lanes and per-tenant quotas.

#### Reliability

- Use at-least-once processing with idempotent handlers.
- Provide a dead-letter queue with replay.
- Use a saga or workflow engine such as Temporal or Step Functions for long, multi-stage documents.
- If the LLM is unavailable, route the document to human review rather than failing.

#### Security and compliance

- Use per-tenant encryption keys.
- Enforce tenant IDs at every data-access layer with row-level security.
- Use PII-aware logging.
- Support data residency by regional deployment, configurable retention, and a complete audit trail showing who classified what and how.
- Use zero-retention LLM endpoints or self-hosted models for sensitive tenants.

#### Observability

Track:

- Stage latency.
- L0/L1/L2 cascade hit rates.
- Review rate.
- OCR failure rate.
- Cost per document.
- Per-class precision and recall on a continuously refreshed golden set.
- Reviewer-override rate as a live accuracy proxy.
- Embedding distribution and confidence histograms.
- Spikes in `unknown` classifications as drift alerts.

### 7. MLOps loop

1. Accumulate feedback and reviewed labels in a versioned dataset.
2. Retrain L1 heads on a schedule, per tenant when enough data exists and otherwise on shared data.
3. Evaluate offline against the golden set, then use shadow deployment and canary rollout. Roll back automatically if accuracy or latency regresses.
4. Optionally distill L2 decisions into L1 over time to reduce LLM usage.

### 8. Trade-offs and risks

| Decision | Trade-off |
|---|---|
| Cascade vs. LLM-only | The cascade is cheaper and faster but adds complexity and calibration work. |
| Per-tenant models vs. shared | Per-tenant models may be more accurate but cost more to operate; use a shared base with lightweight heads. |
| Strict thresholds | Higher precision creates a larger review queue and staffing cost. |
| Third-party OCR/LLM | Faster to build but introduces data-privacy and vendor-dependency concerns. |
| Bundle splitting | A major accuracy improvement on scans, but introduces its own error source. |

Common failure modes and mitigations:

- **Poor scan quality:** Add image enhancement and a quality score.
- **New document types:** Add an `unknown` class and clustering to suggest new labels.
- **Prompt injection inside documents:** Treat document text strictly as data and validate model output against the schema.
- **Label ambiguity:** Resolve it with taxonomy descriptions and reviewer guidelines.

### 9. Phased rollout

1. **MVP:** Ingestion, OCR, L0 rules, LLM classification, and review UI.
2. **Optimize:** Add an L1 classifier trained on labels collected during the MVP and cascade routing to reduce cost and latency.
3. **Scale:** Add multi-tenant taxonomies, bundle splitting, active learning, and drift monitoring.
4. **Mature:** Add automatic retraining, label suggestion, and extraction—the natural next step after classification.

## Related questions

- [Design a notification system.](https://www.aced.io/questions/4720/system-design-notification-system)
- [Build a data classification system for AI governance.](https://www.aced.io/questions/6506/design-data-classification-ai-governance)
- [Design the Jira system.](https://www.aced.io/questions/7287/design-jira-project-management-system)

## Related courses

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

Prepare for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other companies with mock interviews, frameworks, and advice from senior candidates. Topics include ML system design, core concepts, coding, and behavioral interviews.

### [Behavioral Interviews: A Practical Guide for Engineers](https://www.aced.io/courses/eng-behavioral)

![Behavioral Interviews: A Practical Guide for Engineers](https://images.ctfassets.net/x78yjrjc11pq/47qcoHjzFZXE37GoacedkB/9d8e3f4910d8b06b21e76745cd9cbff3/AdobeStock_1142146335.jpeg?w=800&h=800&fm=webp&q=75)

Prepare for senior-plus behavioral interviews at FAANG and Tier-1 companies with material made with staff and principal engineers from Meta, Netflix, Google, and more.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F7422%2Fdesign-ai-document-classification-system&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F7422%2Fdesign-ai-document-classification-system). Opening a form does not execute a tool.