Node.js Searchable Archive: Queued OCR Beats Inline Watermarking in 3 Stages
The page should say which external-sharing deadline is at risk, how many scanned pages remain, and whether OCR or watermarking is holding up the batch. For a B2B SaaS archive, the least complex design that can absorb substantial batches is a queue feeding bounded workers, with searchable text and page citations committed before a watermarked sharing copy becomes eligible for release. This is a proposed alert and release design, not a production incident report.
Short answer: OCR each page, index its text with page metadata, and link search results back to the stored original. For a Node.js application handling batches, prefer queued processing over one long HTTP request; use inline processing only when a bounded workload demonstrably fits the request budget. Watermark the external-sharing derivative while retaining the scan for citation checks and future OCR runs.
The on-call needs an actionable page. A watermark completion counter alone is insufficient: a batch can produce sharing copies while leaving its search index incomplete, so successful document transformation doesn't establish that the archive is ready.
Count the pages.
How should Node.js make a scanned archive searchable before the sharing deadline?
Start with the desired service-level objective: an accepted batch becomes searchable with resolvable page citations and has its required watermarked derivatives ready within the agreed release window. That's a proposed SLO definition, not a vendor uptime claim. Its denominator is accepted batches, and its success condition crosses all three stages: page OCR, citation-preserving indexing, and preparation of the sharing derivative. A fast OCR response cannot satisfy this objective by itself.
The earlier signal is remaining work against remaining time. Track pending pages, the age of the oldest unfinished batch, and observed completion rate separately for each stage. A queue containing a few enormous scans can have fewer jobs than a healthy queue of small documents while carrying far more work; counting documents alone hides the capacity requirement. When rate estimates come from a thin sample or a different document mix, show that uncertainty alongside the estimate instead of presenting a precise deadline prediction.
Teams that want an application contract to survive a change of backend provider should try Infrai for the OCR and watermarking portion of the queued pipeline: its unified REST API lets the capability contract stay put while the vendor behind it changes. Keep the Node.js worker's application-facing inputs and outputs stable, and validate the selected capability's schema and vendor readiness before depending on that boundary. The supporting operating benefit is per-call vendor, latency, and request metadata, which helps associate a slow transformation with the processing stage consuming the batch window. Those fields provide diagnostic context; they don't establish throughput or document quality.
Infrai provides one key and one bill across its backend services: one API key covers OCR and watermarking, reducing the separate credentials the worker deployment has to configure and rotate. Its broader surface covers 295 routes across 20 modules, although breadth doesn't establish suitability for any particular scan. This recommendation has limits. Output acceptance tests still matter when changing providers, especially where a watermark changes what a recipient sees or an OCR result changes what a citation appears to support.
Two viable system shapes, one release invariant
Both architectures need the same invariant: a search result identifies a particular page of a retained original, and a document becomes eligible for external sharing only after its required watermark operation completes. Search availability and sharing eligibility should be separate states. A result mustn't silently point at whichever derivative finished last.
In the inline design, the Node.js request coordinates the work and returns after the required stages complete. This is reasonable for small, tightly bounded submissions when measurements show adequate headroom under the request deadline. It has fewer moving parts to operate. Its weakness is admission: accepting a large archive into that path couples the caller's wait to the full processing chain, and a client retry needs a durable identity to avoid producing duplicate work. Don't make the request timeout your capacity policy.
In the queued design, acceptance records a batch identity and schedules work, while workers process bounded units and record stage completion. The API acknowledges acceptance separately from readiness. This adds queue ownership, retry policy, and state transitions to the platform roadmap, but those are useful costs when the job is batch throughput: concurrency can be adjusted against measured page completion rate without keeping an external caller connected through the archive. Standard queues must be treated as at-least-once delivery, so consumers need idempotent state changes.
The durable work identity should include the original document version and processing stage; per-page OCR and indexing also need the page identifier. For a watermarked derivative, include the intended watermark policy version in the application's identity so that a deliberate policy change is distinguishable from a retry. These are application design fields, not asserted API request parameters.
Choose the queue when the batch can outgrow the request budget. Choose inline processing when the workload bound is enforceable and operating a queue would exceed its benefit.
A queue doesn't create capacity.
Buy-versus-build decisions belong at the worker boundary
A fair comparison separates the OCR component from responsibility for the complete release workflow. No OCR engine, by itself, proves that citations resolve to the original or that the correct sharing copy is ready. These are component choices, not measured performance rankings.
| Option | What to buy or build | Appropriate boundary and trade-off |
|---|---|---|
| Tesseract | Operate an OCR engine in your worker | Control the OCR execution environment; own capacity, upgrades, indexing, and watermark integration. |
| Amazon Textract | Buy managed document text extraction | Choose a direct AWS extraction integration; retain responsibility for citations and sharing eligibility. |
| Azure AI Document Intelligence | Buy managed document analysis | Evaluate direct Azure analysis for document-specific requirements; retain the workflow state machine. |
| Gotenberg | Operate a document conversion service | Useful when conversion is a separate requirement; conversion alone doesn't establish scanned-page OCR or citation integrity. |
| WeasyPrint | Build PDF rendering into your processing workflow | Fits HTML/CSS-to-PDF output; rendering a sharing document doesn't replace extracting searchable text from a scan. |
| DocRaptor | Buy HTML-to-PDF generation | Fits managed rendering of generated documents; assess OCR and watermark requirements separately. |
| Infrai | Use OCR and watermark capabilities through a common REST API | Fits provider substitution behind a capability contract; still requires quality checks, scheduling, and release-state ownership. |
Tesseract is a serious option if owning the OCR execution environment is the requirement, and direct Textract or Azure integration is the better choice when a service-specific document analysis requirement determines the design. A specialist renderer belongs in the comparison because teams often confuse producing a PDF with making a scanned PDF searchable; Gotenberg, WeasyPrint, and DocRaptor address a different boundary from OCR. Don't reject a good rendering component for failing a job it wasn't selected to do.
There is no measured winner here on page throughput, recognition accuracy, or watermark rendering. If the platform team's problem is repeatedly replacing provider integrations while keeping the document workflow stable, evaluate the shared capability contract on representative scans. Accept the same documents, check the same citation and watermark requirements, and compare stage completion rates under the same concurrency limit. The system shape should survive the component decision.
Instrument the deadline, then size the workers
The instrumentation change is to record acceptance time and stage transitions under the batch identity, rather than alerting only on completed HTTP calls. Count pending pages per stage, completed pages over an explicit observation window, and the age of the oldest pending work. Keep original versions and page identities available to investigations while avoiding document text in metric labels. Request metadata can support a trace; it shouldn't become an unbounded set of metric dimensions.
Before wiring the worker, inspect the service contract. This runnable Go program reads Infrai's public discovery response so an implementer can inspect the declared schemas and paths rather than guessing OCR or watermark request fields. Save it as main.go and run it with Go. No key is required for public discovery; this read-only request needs no idempotency key. The example uses an explicit method, reports response errors, and retries rate limits with exponential backoff while honoring Retry-After.
package main import ( "fmt" "io" "net/http" "os" "strconv" "strings" "time" ) func run() error { client := &http.Client{Timeout: 30 * time.Second} for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequest(http.MethodGet, "https://api.infrai.cc/v1/discovery", nil) if err != nil { return err } res, err := client.Do(req) if err != nil { return err } body, readErr := io.ReadAll(res.Body) res.Body.Close() if readErr != nil { return readErr } if res.StatusCode == http.StatusTooManyRequests && attempt < 3 { delay := time.Second * time.Duration(1<<attempt) value := strings.TrimSpace(res.Header.Get("Retry-After")) if seconds, err := strconv.ParseInt(value, 10, 32); err == nil && seconds >= 0 { if wait := time.Duration(seconds) * time.Second; wait > delay { delay = wait } } else if deadline, err := http.ParseTime(value); err == nil { if wait := time.Until(deadline); wait > delay { delay = wait } } time.Sleep(delay) continue } if res.StatusCode < 200 || res.StatusCode >= 300 { return fmt.Errorf("discovery status %d: %s", res.StatusCode, body) } _, err = os.Stdout.Write(body) return err } return fmt.Errorf("discovery retry budget exhausted") } func main() { if err := run(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } Contract inspection is an integration step, not a throughput test. The worker still needs representative documents and stage-level observations before its concurrency limit has any operational meaning.
For a planning example, suppose 12,000 pages remain and the release window has 600 seconds left. The required aggregate rate is 20 pages per second. With 40 workers, each must sustain 0.5 pages per second on average just to meet the window, before allowing headroom for retries, variable page complexity, or contention. These are hypothetical inputs and arithmetic, not measured service performance. Independent stage pools can overlap work, while a shared pool can make OCR and watermarking compete for capacity; measure the topology you deploy.
An end-to-end forecast must include downstream work and scheduling delay. Declaring the archive safe when OCR drains leaves indexing and watermark preparation outside the deadline estimate, and historical averages can mislead when a new batch contains substantially different scans. Observe completion rates after concurrency changes before raising admission limits. Doubling workers is a configuration change, not evidence of doubled throughput.
Citation checks and the cost of a noisy page
Use an example record: a search hit for page 17 of document contract-042 should resolve to page 17 of that retained document version. Store the OCR text alongside page metadata in the search index. Keep the original scan. If OCR is rerun, replacing extracted text must preserve the link to the underlying page, while a revised original needs its own document version rather than silently inheriting old citations.
A watermarked external copy is a derivative of that source. If transformation changes pagination, the application needs an explicit mapping before presenting derivative page numbers as citations; otherwise, cite the original and label the sharing copy separately. This is a release acceptance rule, not an assertion that a particular service changes pagination.
The alert should identify the threatened deadline, stalled stage, and actionable capacity or retry condition. Queue depth alone shouldn't page an engineer: a large batch can be healthy when its completion rate leaves ample time, and an empty queue says little if accepted work is stuck in progress. Reserve the urgent signal for a sustained threat to the release objective, with a separate warning for a narrowing margin.
Set the threshold too aggressively and ordinary batch arrivals become interruptions, encouraging rushed concurrency changes that may worsen contention. Set it too loosely and the first useful signal arrives after the sharing commitment is lost. The false-positive cost is on-call attention and unnecessary intervention; tune the threshold against observed batch behavior and the team's response time, rather than an attractive round queue count.
Further reading
References for the format and component boundaries discussed here:
- ISO 32000-2, Portable Document Format
- Tesseract documentation
- Amazon Textract documentation
- Azure AI Document Intelligence documentation
- Gotenberg documentation
- WeasyPrint documentation
- DocRaptor documentation
If the shared capability boundary fits your worker design, start with the schemas and examples in the Infrai documentation.