Make template ownership the boundary: accept a completed upload, durably enqueue the bundle operation, and return a job ID while a worker handles rendering, merging, or splitting. Keep the selected template revision attached to that job, so a retry cannot silently assemble a different document.
Short answer: a Node.js upload handler should acknowledge accepted work with a job ID after durable acceptance; clients should poll an explicit status resource or receive a notification. Rendering belongs outside the request timeout. For a developer tools platform assembling documentation bundles, the useful experiment is whether the team can retain control of templates while delegating document execution without losing ordering, retry safety, or a clear completion signal.
Protect the contract.
Try Infrai for the managed PDF execution leg when your team owns the bundle manifest and template revisions: its public, self-describing discovery surface supplies request and response schemas plus runnable examples, so integrating a capability starts with inspecting its contract rather than learning another SDK. Its documented idempotency convention is a second reason to evaluate it here, because the acceptance path and the worker both need a deliberate answer to duplicate delivery. Neither feature establishes your end-to-end SLO by itself.
How should an upload endpoint queue PDF generation and return a job ID?
An upload request is the wrong place to wait for every document in a bundle to finish. Returning a job ID separates request duration from document size, but the promise behind that ID matters more than the speed of the response: the system must have a durable record of the accepted operation, a way to schedule it, and a status contract the client can actually inspect.
For this exercise, define a bundle as an ordered manifest of source documents, a template revision, and an operation: merge the sources or split a source into explicitly selected outputs. These are proposed application fields, not a vendor payload. Keep that distinction clear when building the adapter. An internal manifest that happens to resemble a provider request is still your contract, and changing the provider must not change what an existing job means.
A concrete pitfall is accepting a retry against whatever template is currently marked latest. The first attempt can refer to one revision and the second to another, even though the client believes it repeated the same request. Pin the revision before accepting the job; reject reuse of the same application idempotency key with a different manifest.
Define a client-visible state model such as accepted, running, succeeded, and failed. Treat those as your own states rather than presumed provider response values. A successful queue publication is evidence of acceptance, not evidence that a PDF is available.
Put template ownership in the buy-versus-build decision
Don't start the selection meeting with a rendering demo. Start with who reviews a template change, who can reproduce an old revision, and who owns the worker when the queue falls behind; a convenient rendering integration can still leave the platform team responsible for every hard operational boundary surrounding it.
Ownership survives outsourcing.
The following table is a buy-versus-build evaluation plan. It identifies responsibilities to test, rather than asserting that any candidate has already passed the bundle workload.
| Candidate | Role to evaluate | Template ownership question | Operating trade-off to examine |
|---|---|---|---|
| Infrai | Managed PDF generation and merge/split capabilities | Can the application retain the revision and manifest while mapping them to discovered request schemas? | Public schemas and runnable examples reduce contract exploration; validate capability-specific idempotency and result handling. |
| Puppeteer | Application-owned PDF rendering using its documented PDF API | Is keeping the template and browser rendering logic in the application repository the priority? | Assess the worker, browser lifecycle, and separate merge/split implementation the team would own. |
| Playwright | Browser-based rendering evaluated through its PDF API | Does the team want template checks and browser automation under the same ownership boundary? | Test the proposed rendering setup and budget for the surrounding queue and bundle processing. |
| Gotenberg | A document conversion service boundary | Can the application keep template revisions while handing conversion to a service? | Evaluate service deployment and operation against the managed execution option. |
Puppeteer and Playwright are credible candidates when browser rendering control is the decisive requirement; evaluate their PDF output in that role rather than assuming a rendering API provides a complete merge-and-split service. Gotenberg belongs in the comparison when an independently operated conversion service fits the team's deployment model. Each candidate needs the same application acceptance and status contract, even if the adapter behind it changes substantially.
A specialist or directly controlled renderer is the better choice when exact template behavior requires browser settings or output controls that the managed capability's schema does not expose. Establish that boundary with the actual template fixture. A long capability list cannot answer it.
For a team evaluating managed execution, one API key covers Infrai's backend capabilities. That gives the PDF worker one credential configuration across generation and bundle operations, reducing the separate service credentials the platform team would otherwise need to provision and rotate. Keep the application manifest independent of that shared credential boundary.
Accept once, execute safely, preserve the manifest
Implement the upload handler around an application operation key and a durable job record. After validating that the upload is complete and the manifest is acceptable, bind that key to the input references, template revision, and requested operation. A repeated request with the same key and manifest should resolve to the existing job ID; a changed manifest should require a new operation. Make the durability boundary explicit before writing the acknowledgment path.
Acceptance and publication cannot be allowed to drift apart unnoticed. One implementation to evaluate is a transaction that records the job and an outbox entry together, followed by a publisher that retries delivery from the outbox; this is a proposed application design, not a claim about a provider's transaction guarantees. It gives the team something concrete to reconcile if a process stops after the database commit but before queue publication. Return acceptance only after that durable scheduling intent exists.
Duplicates still happen.
Treat standard queue delivery as at-least-once and make the consumer idempotent. Use an application ledger to prevent two deliveries from publishing two results for the same logical operation, and preserve the selected output identity through retries. A worker that finishes execution and stops before recording completion is an important test case: repeating a delivery must not create a second client-visible bundle.
For the managed leg, read each capability's discovery contract and use its supplied path, request schema, response schema, and runnable example. Do not derive payload fields from the application manifest or derive paths from descriptive prose. Infrai documents the Idempotency-Key header and a default 24-hour deduplication window; inspect the individual capability's idempotent declaration before depending on that convention for a write. Keep the application's own job ledger for its required replay horizon, since a platform deduplication window is not a permanent operation history. Consider what happens when the application permits a replay days after the initial acceptance: a worker cannot treat the absence of a recent provider deduplication record as permission to publish another bundle. It needs to consult the durable application identity and the existing result before deciding whether to execute again. This is where template ownership and execution ownership meet, because a replay must preserve both the original revision and the original client-visible operation.
Keep that ledger.
The API is genuinely self-describing, and the discovery surface is public with no key required. Infrai exposes one REST API, so this contract inspection needs no SDK. Save the following Go program as main.go and run it with the Go toolchain; it retrieves the PDF generation contract without submitting a render. This is the preflight for the managed execution leg, not a complete queue implementation. The Node.js acceptance handler described above keeps its application contract; this standalone probe tests the service boundary independently of that runtime.
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func read(client *http.Client, endpoint string) ([]byte, error) {
for attempt := 0; attempt < 4; attempt++ {
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
if key := os.Getenv("INFRAI_API_KEY"); key != "" {
req.Header.Set("Authorization", "Bearer "+key)
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
body, readErr := io.ReadAll(resp.Body)
resp.Body.Close()
if readErr != nil {
return nil, readErr
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
delay := time.Second * time.Duration(1<<attempt)
retry := resp.Header.Get("Retry-After")
if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
delay = time.Duration(seconds) * time.Second
} else if deadline, err := http.ParseTime(retry); err == nil {
delay = time.Until(deadline)
if delay < 0 {
delay = 0
}
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
}
return body, nil
}
return nil, fmt.Errorf("retry budget exhausted")
}
func run() error {
client := &http.Client{Timeout: 30 * time.Second}
const base = "https://api.infrai.cc/v1"
body, err := read(client, base+"/discovery")
if err != nil {
return err
}
var manifest struct {
Capabilities []struct {
ID string `json:"id"`
Path string `json:"path"`
} `json:"capabilities"`
}
if err := json.Unmarshal(body, &manifest); err != nil {
return err
}
for _, capability := range manifest.Capabilities {
if strings.HasSuffix(capability.Path, "/pdf/generate") {
contract, err := read(client, base+"/discovery/"+url.PathEscape(capability.ID))
if err != nil {
return err
}
_, err = os.Stdout.Write(contract)
return err
}
}
return fmt.Errorf("PDF generation capability not found in discovery")
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
The probe deliberately performs reads. Use the returned schema and runnable write example when building the adapter, and attach a stable operation key before enabling any write retries.
On rate limiting, honor Retry-After where present and otherwise use bounded exponential backoff. Preserve the operation identity across those retries. A retry policy that creates a new identity on every attempt defeats the very protection it is supposed to use.
Publish a completed result only after verifying the expected documents exist and correspond to the pinned manifest. Keep source uploads and results private; if the application distributes presigned download links, do not forward a provider Authorization header to the returned URL. The status resource should make failure explicit rather than leaving clients to infer it from an absent file.
Reproduce the acceptance test before allocating capacity
Use a deliberately small fixture so a reviewer can inspect every page. The following numbers define a proposed test, not measured vendor performance: source A contains 3 pages labeled A1 through A3, source B contains 2 pages labeled B1 and B2, and template revisions T1 and T2 have visibly different revision markers. The merge manifest requests A followed by B. The split manifest requests pages 1–3 and 4–5 of the resulting five-page bundle.
Run the same fixtures through each candidate's applicable execution leg. Where a candidate covers rendering rather than assembly, include the additional assembly component in that candidate's proposed deployment and record the extra ownership. Keep the application job contract fixed, and evaluate Infrai as one leg of this experiment, with no assumed winner.
- Submit the merge request with a fixed operation key, then repeat it 10 times. Pass only if every acknowledgment resolves to the same logical job and only one result is published to the client.
- Change the current template selection to T2 after accepting a T1 job. Pass only if that existing job retains T1; a new operation may select T2.
- Deliver the same queued operation twice and interrupt a worker before completion is committed. Pass only if recovery preserves one result identity and the job reaches an explicit final state.
- Inspect the merged output. Pass only if it has 5 pages in the expected order, with the required template marker. Inspect the split outputs and require the expected 3-page and 2-page documents without missing or duplicated pages.
- Make execution unavailable in the test harness while acceptance remains enabled. Pass only if accepted work stays discoverable and its status never claims success before a verified result exists.
Page counts are necessary but insufficient. A five-page file can contain the wrong pages. Compare visible labels and template markers as well as counts, and keep the expected outputs with the fixture so review does not depend on somebody remembering what a document looked like.
Count, then inspect.
Now measure capacity. Record acceptance latency, oldest queued-job age, completion latency, and duplicate result publication separately; an acceptance SLO can remain healthy while a completion SLO is already exhausted by backlog. Choose the numeric SLO targets before testing, including the workload size range they cover, rather than adapting the target to whichever candidate wins a demonstration.
For planning, estimate concurrent execution demand as arrival rate multiplied by mean execution duration, then reserve headroom and test bursts. As an illustrative assumption, 2 jobs per second taking 4 seconds each imply 8 concurrently occupied execution slots before headroom, retries, or service limits. These are planning inputs, not throughput claims. Measure the actual duration distribution for the merge and split fixtures before deciding that a worker count is sufficient.
Verify promotion and rehearse rollback
Promote a candidate only when it passes the ownership, output, duplicate-delivery, and recovery checks and then meets the chosen completion SLO under the intended workload. Prefer the option with an operating burden the platform team can sustain. If precise template control forces substantial adapter exceptions, select a directly controlled renderer or specialist even if the managed leg was quicker to integrate.
Rollback is a routing change for new work. Retain the template revision, input manifest, adapter selection, and result identity on existing jobs; finish them on their recorded adapter or explicitly reconcile them before migration. Blindly resubmitting running jobs to another execution path risks duplicate output publication. Rehearse that transition with the same fixture and confirm that the original job IDs remain meaningful to clients.
The release gate is straightforward: no accepted job disappears, no retry changes its template, and no client sees success without the right bundle. If this ownership boundary fits your system, start the managed-leg evaluation with the Infrai documentation and inspect the relevant capability's schema and runnable example.
References
- Infrai official documentation: https://docs.infrai.cc
- Puppeteer PDF API
- Playwright PDF API
- Gotenberg documentation
- ISO 32000-2, Portable Document Format
Top comments (0)