PDF-to-Markdown Inference API
Design synchronous and asynchronous PDF conversion across CPU parsing, GPU OCR, and memory-intensive Markdown assembly.
Problem statement
For this exercise, assume customers upload PDFs and request faithful Markdown. A CPU stage splits and rasterizes pages, a GPU OCR stage extracts text and layout, and a memory-intensive stage converts and assembles Markdown.
The synchronous path must optimize one document of up to about 1,000 pages over a single request or streamed interaction, with an explicit bounded connection lifetime and continuation outcome if the ceiling is reached. The asynchronous path handles many concurrent jobs for later retrieval.
Both modes share page-level work, preserve original page order, spill large intermediates outside worker memory, and retry without duplicating output. Exclude OCR model training and document-editor collaboration.
What to build
- Pipeline and micro-batch one PDF of up to about 1,000 pages, returning an ordered body or ordered stream within the connection contract.
- Accept many concurrent conversions asynchronously and expose durable progress, cancellation, and later result retrieval.
- Publish one ordered, versioned Markdown artifact with page-level provenance and explicit failure details.
- Return a stable job identity and continuation contract when a synchronous interaction cannot finish before its hard ceiling.
At scale
- Support documents from one page to a few thousand pages, including about 1,000 pages on the synchronous or streamed path, without holding every rasterized page in one process.
- Keep the CPU splitter, GPU OCR, and memory-heavy Markdown stages busy concurrently while GPU micro-batch size remains an explicit latency-versus-utilization choice.
- A synchronous interaction has a hard connection ceiling measured in minutes; if it cannot finish, the client receives the same durable job identity and an explicit continuation path rather than losing completed work.
- A completed artifact or streamed prefix must contain each successful page exactly once and in original page order.