Diagrammatic

Build an Intelligent Document Processing Pipeline — System Design Interview Practice

Design a document processing system that extracts text from PDFs and images, classifies documents, extracts structured data, and validates accuracy. Work through the requirements, architecture trade-offs, and an interactive design review.

Concepts and architecture decisions to consider

  • gcpConcept to explore
  • document aiConcept to explore
  • ocrConcept to explore
  • cloud functionsConcept to explore
  • mlConcept to explore

Interview prompt

Design an intelligent document-processing pipeline that ingests PDFs and images, performs OCR and classification, extracts structured fields, and returns confidence-aware results at scale.

  • Keep the original document immutable and version every OCR, classification, extraction, correction, and validation result.
  • Use asynchronous page-level work with bounded concurrency, confidence thresholds, human review, and idempotent retries.
  • Preserve coordinates and provenance so each extracted field can be traced back to the source page and model version.
  • Explain encrypted storage, tenant isolation, PII handling, malformed documents, model fallback, and auditability.

Requirements and scale assumptions

  • Upload documents, detect type and pages, extract OCR text, classify the document, and map fields to a declared schema.
  • Expose per-document and per-page status, confidence, validation errors, human-review tasks, and versioned results.
  • Support redaction, deletion, reprocessing with a new model, correction, export, and audit history.
  • Target p95 processing completion below 10 seconds for ordinary documents and return an accepted job immediately.
  • Scale by document and page while isolating large PDFs, expensive vision models, and noisy tenants.
  • Never lose the original or a committed result; make page tasks, callbacks, and model retries idempotent.
  • Degrade to OCR-only or human review when extraction models or enrichment services are unavailable.
  • Process 1 million documents per day, averaging 8 pages, with occasional 500-page batch uploads.
  • Partition work by tenant, document, and page; isolate oversized files and model-specific queues.
  • Retain originals, manifests, page outputs, model versions, confidence scores, and review decisions under policy.
  • Document volume: 1M docs/day — Page count and model cost drive queue capacity and tenant quotas.
  • Processing target: p95 <=10s/doc — The API acknowledges an asynchronous job before all pages finish.
  • Durable boundary: Committed before async — The source of truth is the immutable document and a versioned processing manifest.
  • Async boundary: At-least-once workers — Keep OCR, extraction, validation, enrichment, and review off the upload request path.

Key entities

  • SourcePartitionsourceId, partitionId, cursor, schemaVersion, watermark, status

    Replayable intelligent document processing pipeline source evidence and ingestion cursor.

  • SchemaVersiondatasetId, version, compatibility, owner, effectiveAt, status

    Governed intelligent document processing pipeline contract used to validate producers and consumers.

  • ProcessingRunrunId, inputWatermark, checkpoint, qualityStatus, codeVersion, status

    Checkpointed intelligent document processing pipeline processing attempt with quality and lineage metadata.

  • AnalyticalDatasetdatasetId, partition, watermark, schemaVersion, qualityStatus, location

    Curated intelligent document processing pipeline serving partition with freshness and quality state.

Data flow

  1. 1. Register sources and contractsThe intelligent document processing pipeline catalog records owners, schemas, compatibility rules, retention, lineage, and partitioning before data is accepted.
  2. 2. Ingest with backpressureConnectors checkpoint intelligent document processing pipeline source cursors, validate schema and deduplication keys, and slow producers when downstream capacity is exhausted.
  3. 3. Process event time with checkpointsStream or batch engines compute intelligent document processing pipeline transformations using watermarks, late-data policy, state checkpoints, and deterministic code versions.
  4. 4. Publish quality-gated datasetsOnly intelligent document processing pipeline outputs that pass completeness, freshness, validity, and privacy checks become visible to analytical consumers.
  5. 5. Serve, replay, and reconcileConsumers read bounded partitions with freshness metadata while operators replay failed intelligent document processing pipeline ranges and compare output checksums.

Deep dives and trade-offs

  • Schema evolution and data qualityVersion intelligent document processing pipeline contracts and make compatibility rules explicit for every producer and consumer. Quarantine malformed partitions instead of poisoning the whole dataset. Track row counts, null rates, duplicates, distribution changes, and policy violations by partition.
  • Watermarks, late data, and exactly-once effectsUse source cursors and event-time watermarks for intelligent document processing pipeline progress, not wall-clock assumptions. Make checkpoints, output keys, and sink commits retry-safe under at-least-once delivery. Document how late events revise windows, aggregates, or snapshots.
  • Replay, lineage, and costKeep immutable intelligent document processing pipeline raw evidence and code or schema versions so failed outputs can be reproduced. Separate hot serving storage from cold retention and cap replay concurrency. Measure freshness, backlog, compute cost, storage growth, and quality-gate failure rate.
  • Streaming versus batchUse streaming for freshness-critical intelligent document processing pipeline paths and batch for backfills, compaction, and expensive recomputation. Forcing every workload into streaming makes state, replay, and cost harder to operate.
  • Raw retention versus curated-only storageRetain enough immutable raw evidence for replay, audit, and correction, then tier or expire it according to policy. Without raw evidence, a bad transformation can require an unreproducible emergency fix.
  • Central warehouse versus domain-owned datasetsCentralize governance and discovery while letting domain owners own contracts and quality signals. A single team owning every transformation becomes a delivery bottleneck and hides data ownership.
Diagrammatic — system design practice and architecture review.