
Build, deploy, and scale a production-grade OCR pipeline using Rust, vLLM, Redis, KEDA, and Kubernet
Build, deploy, and scale a production-grade OCR pipeline using Rust, vLLM, Redis, KEDA, and Kubernet
Most OCR tutorials stop at "call an API and get some text back." This isn't that.
Instead, we're building a production-grade, self-scaling Visual Document Understanding pipeline, deployed for real on Kubernetes (AKS or GKE), that goes far beyond flat text extraction: it reasons about charts, tables, and layout the way a human reader would — powered by a Small Language Model (Qwen 3.5) instead of a bloated frontier model.
By the end of this course, you'll have your own event-driven OCR system capable of:
/dev/shm-based document handoff between the layout encoder and the inference engineExcited? Let's get started!
This course is for ML/AI Engineers and Platform Engineers who already know how to call an OCR API and want to know what it takes to run one in production: GPU node pools, autoscaling economics, network security, and the systems-design tradeoffs behind serving a generative model at throughput.
We run this as a 6-week hands-on engineering cohort. The entire repository is open-source from day one — every week combines a deep-dive systems article with a step-by-step codebase walkthrough.
| Week | Focus | Hands-on |
|---|---|---|
| ⛵ 1. Kubernetes for AI Systems | Pods, Services, Node Pools, resource scheduling | Cluster setup on AKS/GKE, T4 & A100 node pools, GPU drivers/operators with proper security profiles and taints |
| 2. SOTA OCR Approaches & VDU | Single-stage end-to-end models vs. our two-stage layout-first pipeline | Evaluating GLM-OCR SDK's layout detection and measuring performance trade-offs |
| ⚡ 3. Deploying the vLLM Inference Engine | Continuous batching, PagedAttention, scheduling optimizations | Deploying Qwen 3.5 4B on vLLM, tuning MAX_NUM_BATCHED_TOKENS, chunked prefills, Multi-Token Prediction (MTP) — standalone deployment walkthrough |
| 4. Rust Ingest Gateway | High-concurrency gateways for heavy payloads; ownership, borrowing, async Rust | Building the Axum gateway (client_rt_producer), 10MB limits, atomic HSET writes to Redis — standalone deployment walkthrough |
| 5. Async Architectures & Zero-Copy Ingestion | Queue buffers, dynamic batching collectors, RAM-disk transfer | Building the Python worker (client_rt_consumer), 100ms collection window, /dev/shm handoff, scale-to-zero with KEDA — standalone deployment walkthrough |
| ️ 6. Enterprise Gateways & Claude Code MCP | Security boundaries, JWT verification, rate limiting, agentic workflows | Configuring Azure APIM / GCP API Gateway policies and wrapping the pipeline in an MCP server for Claude Code — standalone deployment walkthrough |
Start with account setup, then GPU quota, then the full deployment guide for your cloud of choice:
Modern OCR has evolved from simple character recognition to Visual Document Understanding (VDU). By leveraging Small Language Models (SLMs) like Qwen 3.5 (4B), this pipeline moves beyond "flat" text extraction to provide:
/dev/shm (Shared Memory), allowing the layout engine and the inference engine to share high-resolution buffers without costly disk I/O.The architecture leverages the GLM-OCR SDK as a high-concurrency orchestration layer to bridge the gap between deterministic layout analysis and generative SLM recognition.
By deploying models via vLLM, we leverage continuous batching and PagedAttention to maximize the A100's utility.
Batch N, the Orchestrator/Layout pod is already pre-processing Batch N+1 using the PP-DocLayoutV3 detector.To maximize the ROI of the A100 nodes, the system is tuned to balance the asymmetric load between CPU-bound preprocessing and GPU-bound inference.
| Parameter | Optimized Value | Technical Rationale |
|---|---|---|
max_workers |
512 | Matches the MAX_NUM_SEQS of the vLLM server. Ensures that the worker can saturate the continuous batching engine with concurrent region-recognition requests. |
layout/batch_size |
4 | For multi-page PDFs, this allows the PP-DocLayoutV3 model to process multiple pages in a single GPU forward pass, reducing kernel launch overhead. |
layout/workers |
4 | Utilizes multi-core CPUs for parallel image decoding, resizing, and normalization, preventing the GPU from idling while waiting for input tensors. |
connection_pool |
1024 | Prevents HTTP connection exhaustion when handling high-concurrency bursts across the 512 workers. |
To fully utilize the massive 80GB VRAM of the A100 node for models like Qwen3.5-4B, we aggressively tune the internal parameters of the vLLM engine:
MAX_NUM_SEQS=512: Increased from default to allow the vLLM continuous batching scheduler to process up to 512 concurrent image crops or text completions in parallel.MAX_NUM_BATCHED_TOKENS=262144: Massively increased to eliminate the "prefill bottleneck". Because each layout crop contains ~6K tokens, a standard batch size limits prefilling to only ~5 crops at a time. By pushing this to 262K, the engine can prefill ~42 images simultaneously in a single forward pass.MAX_MODEL_LEN=16384: Explicitly reduced from 32K. Setting this to 16K perfectly covers the worst-case scenario (6K image + 8K generation) while preventing overly pessimistic reservations. This frees up gigabytes of VRAM to physically accommodate the 512 sequences.--enable-chunked-prefill): Prevents large prefill tasks from blocking decoding steps of currently running requests. By chunking prefills and co-scheduling them with decoding tokens, the engine guarantees lower latency spikes under heavy concurrent workloads.--enforce-eager): Critical for Multi-Token Prediction (MTP). We allow vLLM to compile CUDA graphs during cold-start. This eliminates the massive CPU bottleneck caused by dispatching thousands of micro-kernels per generation step.Colocating the SDK worker and vLLM across T4 (Layout) and A100 (OCR) node pools allows for optimized resource utilization. The system uses a Sequential Dynamic Batching strategy to saturate the GPU without causing kernel contention.
| Component | Hardware Target | Workload Profile | Batching Strategy |
|---|---|---|---|
| Worker (SDK) | T4 GPU | Layout Bound: Uses PP-DocLayoutV3 to identify regions. | Dynamic Collector: Batches up to 4 tasks in 100ms windows to reduce kernel overhead. |
| vLLM (SLM) | A100 GPU | Compute Bound: High-speed generative OCR/Reasoning using MTP. | Continuous Batching: Sa |
No open issues yet, or sync has not completed.