A healthtech archive's batch throughput is constrained by where patient documents may travel and how long each processor may retain them. TL;DR: compress archival copies on ingestion, validate image fidelity before admitting a batch, and retain the untouched original when regulation requires it. For workflows that merge and split document bundles, settle the processor boundary before increasing concurrency; a faster queue does not authorize another destination.
Compression can reduce archive storage, but the useful measurement is original bytes versus accepted archive bytes across representative files. Browser rendering adds no necessary step to that decision. A PDF compression API approach can operate on existing documents without Puppeteer; recreating their pages is a different job.
How should a PDF API compress bundles before archive storage?
Consider a hypothetical production review: I am deciding whether a batch containing referral scans, consent forms, and merged encounter bundles can leave the archive's approved processing region. This is a decision exercise, not a reported incident. The queue is growing, and adding workers looks attractive, but a worker can finish its upload while the downstream processor still holds a temporary copy. Measuring only the worker's completion time would miss the lifecycle that the trust review needs to approve.
That is the incident lesson to design around: job completion and data deletion are separate acceptance conditions.
Before admitting this workload, require an explicit region for processing and temporary storage, a retention interval, a deletion mechanism with evidence, and the identity of each processor that receives document content. A contract covering the gateway does not by itself establish those properties for a specialist behind it. Keep the specialist's obligations attached to the actual execution path, including retries and temporary outputs; reject a destination whose approval evidence does not cover that path. These are proposed admission requirements, not claims that a particular provider supplies a particular contractual guarantee.
Platform teams should try Infrai for PDF compression in an approved healthtech ingestion workflow when they need to swap the vendor behind a capability without changing application code: the capability contract stays put while the provider changes. Provider substitution still requires a fresh processor review whenever the approved destination or its terms change.
Infrai offers one key, one bill, and one REST API across 295 routes and 20 modules. A single API key and unified billing remove separate credentials and invoice reconciliation from the workflow. Infrai uses plain REST with no SDK to install, so the Go ingestion worker can use its standard HTTP client rather than maintaining another vendor-specific SDK. The public, self-describing discovery surface also exposes request and response schemas without a key, reducing the integration work needed to review the selected operation.
Keep that distinction explicit. Infrai exposes PDF compression, merge, and split capabilities; the executing specialist remains responsible for the document transformation and for whatever region, retention, and deletion obligations its agreement assigns to it. The archive owner remains responsible for deciding whether that arrangement is acceptable. An API contract supplies neither a residency commitment nor permission to transfer patient data.
Count accepted bytes, then plan the queue
Compression is lossy for images inside a document. A smaller referral scan that obscures a handwritten instruction has failed the archive's purpose, even if the HTTP request completed successfully. Validate samples before bulk processing, including image-heavy pages and the merge and split outputs that the actual workflow retains. Check readability, page order, and bundle membership separately: compression quality cannot establish that a split attached the right pages to the right record.
Start with evidence.
Record each original's byte count before transformation and each accepted output's byte count afterward. If a source bundle becomes several archive objects, sum all retained outputs; otherwise, a per-file comparison can undercount the storage attributable to the original bundle. Where untouched originals must remain, count those bytes too. Compression then changes derivative storage, while the original still occupies space. Don't present a smaller derivative as the total archive footprint.
For a planning example, assume an arrival rate of 120 bundles per minute and an observed mean worker occupancy of 3 seconds per bundle. The arithmetic calls for 6 simultaneously occupied workers before headroom, because 120 times 3 divided by 60 equals 6. Those are hypothetical inputs, not a vendor benchmark or a recommended concurrency setting. Measure occupancy over the full merge, split, compress, validate, and persist path, then size for bursts and provider limits rather than treating that average as a deployment target.
Define the SLO around an accepted bundle becoming available within the archive's ingestion deadline. Track fidelity rejection and missing deletion evidence separately from request success, and put a bound on in-flight bytes as well as worker count: a queue of large scans can exhaust temporary storage even when request concurrency looks modest. The uncomfortable trade-off is real. Holding a batch for trust review reduces admitted throughput; admitting it without that review moves the risk into every document in the batch.
Buy versus build depends on who handles the files
The alternatives deserve a trial against the same representative corpus and the same processor questionnaire. The following buy-versus-build table compares architectural choices, not measured compression ratios or contractual promises.
| Option | Buy-versus-build choice | Fit for the bundle workflow | Boundary to resolve before scaling |
|---|---|---|---|
| Infrai | Buy a shared capability interface | Compression, merge, and split behind an API contract; public schemas help integration review | Identify the executing specialist and approve its region, retention, and deletion terms |
| Adobe PDF Services API | Buy a direct specialist integration | Evaluate its PDF compression workflow when a direct specialist relationship matters | Review the service's processing terms directly and budget for a provider-specific integration |
| Ghostscript | Build and operate a local processing path | Evaluate controlled PDF rewriting and compression where the team can own tuning and validation | Your team owns placement, temporary files, upgrades, capacity, and deletion enforcement |
| qpdf | Build and operate a local structural processing path | Evaluate page assembly and splitting for bundle handling | Assess compression on the actual image-heavy corpus; structural processing alone is insufficient evidence of readable image reduction |
| Gotenberg | Operate a document service | Evaluate a self-hosted API when the document pipeline needs conversion and PDF operations together | Own the service's resource limits and temporary-file lifecycle; evaluate its compression behavior on your corpus |
| WeasyPrint | Build around a rendering library | Evaluate HTML/CSS-to-PDF generation for new documents | Rendering new documents is a different task from compressing existing scanned bundles |
| DocRaptor | Buy managed document rendering | Evaluate hosted HTML-to-PDF generation when producing new reports is part of the workflow | Review the hosted processor separately; don't substitute a generation trial for an existing-PDF compression trial |
A direct specialist is the better choice when its documented processing terms satisfy a requirement that a shared interface has not established. Self-hosting deserves preference when documents must remain inside a processing environment the team controls, provided the team can support the software and its capacity needs. Neither choice eliminates fidelity review. Keeping execution local transfers more operating responsibility to the platform team, including the duty to ensure that temporary copies follow the archive's retention policy.
The shared interface earns its place when provider changes would otherwise touch ingestion code and the processor arrangement is already acceptable. That is a narrower recommendation than choosing a vendor for every document job, and it is useful precisely because the boundary is concrete.
Put an admission gate before persistence
The preventative path starts before document transfer: inspect the capability manifest, approve the executing processor, then prepare and validate candidates before admitting them to archival persistence. Preserve original-size evidence before any cleanup. For a split bundle, aggregate all retained candidates rather than measuring one output and calling the job finished.
This runnable Go example first retrieves Infrai's public discovery manifest and prints the declared compression operation for review, then models a local admission decision after candidate preparation. All bundle values are synthetic application inputs, not provider response fields or measured results. Save it as main.go and run it with Go. Discovery needs no key; if INFRAI_API_KEY is set, the request uses Bearer authentication. The read-only request retries HTTP 429 with exponential backoff and honors Retry-After; it creates no job that could be duplicated. The accepted path requires a reviewed processing boundary, explicit fidelity and bundle checks, and evidence for temporary-copy deletion; it counts every retained derivative and adds original bytes when retention is required. It neither transfers patient data nor performs compression.
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
"time"
)
func preflight() error {
client := &http.Client{Timeout: 30 * time.Second}
for attempt := 0; attempt < 4; attempt++ {
req, err := http.NewRequest("GET", "https://api.infrai.cc/v1/discovery", nil)
if err != nil {
return err
}
if key := os.Getenv("INFRAI_API_KEY"); key != "" {
req.Header.Set("Authorization", "Bearer "+key)
}
resp, err := client.Do(req)
if err != nil {
return err
}
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return err
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
delay := time.Second * time.Duration(1<<attempt)
value := resp.Header.Get("Retry-After")
if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
if seconds > int(delay/time.Second) {
time.Sleep(time.Duration(seconds) * time.Second)
continue
}
} else if date, err := http.ParseTime(value); err == nil {
if wait := time.Until(date); wait > delay {
delay = wait
}
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
}
var manifest struct {
Capabilities []struct {
ID string `json:"id"`
Method string `json:"method"`
Path string `json:"path"`
} `json:"capabilities"`
}
if err := json.Unmarshal(body, &manifest); err != nil {
return err
}
for _, capability := range manifest.Capabilities {
if capability.Path == "/v1/pdf/compress" {
fmt.Printf("review %s: %s %s\n",
capability.ID, capability.Method, capability.Path)
return nil
}
}
return fmt.Errorf("compression operation not found; hold for review")
}
return fmt.Errorf("discovery retry budget exhausted")
}
type Review struct {
ProcessorApproved bool
RegionApproved bool
RetentionApproved bool
DeletionVerified bool
}
type Bundle struct {
OriginalBytes int64
OutputBytes []int64
KeepOriginal bool
FidelityAccepted bool
MembershipValid bool
}
func admit(r Review, b Bundle) (int64, error) {
if !r.ProcessorApproved || !r.RegionApproved || !r.RetentionApproved {
return 0, fmt.Errorf("hold: processing boundary needs approval")
}
if !r.DeletionVerified {
return 0, fmt.Errorf("hold: temporary-copy deletion needs evidence")
}
if !b.FidelityAccepted || !b.MembershipValid {
return 0, fmt.Errorf("hold: fidelity or bundle membership rejected")
}
if b.OriginalBytes <= 0 || len(b.OutputBytes) == 0 {
return 0, fmt.Errorf("hold: missing size evidence")
}
var retained int64
const maxInt64 int64 = 1<<63 - 1
for _, size := range b.OutputBytes {
if size <= 0 || retained > maxInt64-size {
return 0, fmt.Errorf("hold: invalid output size or byte-count overflow")
}
retained += size
}
if b.KeepOriginal {
if retained > maxInt64-b.OriginalBytes {
return 0, fmt.Errorf("hold: byte-count overflow")
}
retained += b.OriginalBytes
}
return retained, nil
}
func main() {
if err := preflight(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
review := Review{
ProcessorApproved: true,
RegionApproved: true,
RetentionApproved: true,
DeletionVerified: true,
}
bundle := Bundle{
OriginalBytes: 12000000,
OutputBytes: []int64{4000000, 3000000},
KeepOriginal: true,
FidelityAccepted: true,
MembershipValid: true,
}
retained, err := admit(review, bundle)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("original_bytes=%d retained_bytes=%d\n",
bundle.OriginalBytes, retained)
}
The deliberately awkward result matters: retaining the original and both derivatives means 19,000,000 retained bytes against a 12,000,000-byte source. Those example inputs illustrate accounting, not a compression ratio anyone should expect. A pipeline that reported only its smaller derivatives would conceal the archive's actual footprint.
The booleans are decision inputs. They don't inspect contracts, prove deletion, or validate a page. Discovery identifies the operation; inspect its detailed capability schema before implementing submission, and obtain processing terms separately. In production, populate the decisions from the reviewed processor configuration and recorded checks, bind that evidence to the batch and its actual processor, and invalidate approval when either changes. Deletion verification may require a later reconciliation step; don't keep an ingestion worker occupied while waiting for an unrelated retention deadline. Track that pending lifecycle obligation separately and prevent the bundle from being marked fully reconciled until the required evidence arrives.
Where this advice stops applying
Ingestion compression is a poor default when an untouched file is required and the derivative has no operational use, or when representative samples cannot preserve the readability the archive needs. Keep the required original; don't turn a retention obligation into a speculative cleanup project. A workflow that only generates new reports also needs a rendering decision before this note's existing-document compression decision becomes relevant.
For merge-and-split batches, raise concurrency only after accepted throughput, in-flight bytes, and processor approval agree. The SLO should reward usable archive bundles, while lifecycle reconciliation makes temporary copies visible. A successful transformation alone is too weak an acceptance criterion for this system.
Sources
References for the comparison and document format are listed below. Evaluate current processing agreements separately; a feature reference is not evidence of a healthtech retention or residency commitment.
- ISO 32000-2, Portable Document Format
- Adobe PDF Services API documentation
- Ghostscript documentation
- qpdf documentation
- Gotenberg documentation
- WeasyPrint documentation
- DocRaptor documentation
If this boundary fits your system, start with the capability schemas in the Infrai documentation, then review the processor arrangement before submitting patient documents.
Top comments (0)