PDF/A validation on serverless and edge runtimes
Validation needs to be fast to be practical for every request. If the validator has to do setup work before it can check the file, you pay that cost every time the function runs. If the function has to start from scratch for each request, any setup the validator does gets repeated instead of being reused.
Where it fits
| Runtime | Fit | Why |
|---|---|---|
| Long-running service | Best | Import the library and validate in-process. No subprocess, no serialisation, typed errors. |
| Container / batch job | Best | A small static binary in a scratch image, verifying the whole corpus in one process. |
| Serverless function | Good | Nothing to warm up, so a cold start is dominated by the platform rather than by the validator. |
| Browser / WebAssembly | Situational | Nothing is uploaded, which is the point. The bundle a new visitor downloads first is real bandwidth. |
| Edge worker (V8 isolate) | Constrained | Isolate runtimes cap bundle size and memory well below what a full PDF engine needs. Validate in a function behind the edge instead. |
The measurements behind that table, and the methodology they were taken under, are on the benchmarks page.
Validating in the browser
Compiled with GOOS=js GOARCH=wasm, the same gopdfrab engine runs in a Web Worker. That changes the privacy story completely: the document is read into memory in the visitor's browser and handed to the WebAssembly module, and there is no endpoint that could receive it. The validator on this site works exactly that way.
Bounding memory
A function with a memory cap and untrusted input is exactly the situation the resource limits exist for. A single stream decodes to at most 256 MB by default.
// A single stream decodes to at most 256 MB by default, guarding against
// decompression bombs. Raise it for legitimately large PDFs, or lower it to
// harden against hostile input.
gopdfrab.SetLimits(gopdfrab.Limits{
MaxDecodedStreamBytes: 512 << 20, // 512 MB
MaxResidentBytes: 32 << 20, // caches one open document keeps (default 64 MB)
})
gopdfrab.CurrentLimits() // the effective caps
gopdfrab.DefaultLimits() // the built-in capsCancellation
The verifier uses deadlines, so a problematic document is abandoned rather than running until the platform terminates the invocation. See options and cancellation.
Frequently asked
Can I validate PDF/A in an AWS Lambda?
Yes, there is no provisioning time and nothing needs to be warmed up before the first byte is read.
Can PDF/A validation run in the browser?
Yes. gopdfrab compiles to WebAssembly with GOOS=js GOARCH=wasm, and the validator on this site is that build running in a Web Worker. The document never leaves the browser.
How big is the WebAssembly bundle?
About 16 MB, downloaded once and then cached.
How much memory does validation need?
Peak memory stays flat across the conformance corpus. Per-document use depends on the document.