Catalogue / ersteiger-2025-serverless-pdf-rendering

A test of a Rust and Typst PDF pipeline on AWS Lambda rendered 1,000 PDFs in 11 seconds under a 10-invocation limit

None named; a personal project by Erik Steiger, built for an imaginary client, 2025. Serverless PDF rendering pipeline (API Gateway, SQS, Lambda, S3) using the Papermake library.

Organisation
None named; a personal project by Erik Steiger, built for an imaginary client
Evidence
Experiment
System
Serverless PDF rendering pipeline (API Gateway, SQS, Lambda, S3) using the Papermake library
As of
2025-04
Source
Generating 1 Million PDFs in 10 Minutes with Serverless Rust

Erik Steiger (personal blog), published 2025-04-21

Architecture

API Gateway passes batches of render requests to a request-handler Lambda, which queues jobs on SQS and returns at once; a renderer Lambda takes jobs from SQS, renders each PDF with Papermake on the Typst typesetter, and uploads it to S3, where templates are also kept.

Section: Architecture Decisions | Section: Request handler | Section: Renderer

Components

ComponentRoleWhere
API GatewayEntry point that accepts render requests.Near: API Gateway: Entry-point to our rendering service.
Request handler LambdaTakes a batch of render definitions from API Gateway, puts the jobs on SQS and answers 202 Accepted with job ids.Section: Request handler | Section: Terraform definition
SQS render queueHolds rendering jobs and passes them, possibly in batches, to the renderer.Near: SQS: Managing rendering jobs. | Section: 3. Batching
Renderer LambdaFetches the template from S3, renders the PDF with Papermake and uploads the result to S3.Section: Renderer
S3 bucketsOne bucket holds document templates and another the finished PDFs.Near: S3: Holding our document templates and the | Section: Terraform definition

Figures, as the source states them

FigureAs statedNoteWhere
Test throughput91 PDFs per secondPreliminary test of 1000 requests, limited to 10 unreserved concurrent invocations shared by both LambdasNear: Throughput: 91 PDFs / second
Total processing time for the test batch11 seconds1000 requests, measured until every PDF was uploaded to S3Near: Total processing time: 11 seconds
Renderer time per PDF when warm35 msRoughly; hot-started with template and compilation cachedNear: our renderer takes roughly 35ms per PDF
First single render including template fetch141 msBefore tuningNear: fetching the template and rendering it took 141ms
Unreserved concurrent Lambda invocations available10 invocationsLimit on a brand new AWS accountNear: I had a limit of only 10 unreserved
Target throughput for the imaginary client1,667 PDFs per secondStated as 1,667; a design target, not achieved in the testNear: We are still below our target of

Records

Decision#d1

Render PDFs with the Typst typesetter in Rust Lambdas behind an SQS queue, not with a browser, Crystal Reports or LaTeX

ersteiger-2025-serverless-pdf-rendering#d1 at corpus version 26a1b3a7e3dd
Chosen

The pipeline renders with Papermake, the author's library built on Typst, inside Rust Lambdas compiled to native binaries, with SQS between the request handler and the renderer.

Near: I started working on Papermake, a PDF | Near: Rust compiles to a native binary so | Section: Architecture Decisions

Rejected

Puppeteer. About 1 to 2 seconds per PDF in the author's experience, because of headless browser startup.

Near: Puppeteer: ~1-2sec, due to headless browser startup

Crystal Reports. About 750 to 900 ms per PDF, legacy Windows dependencies, and fixed-size layout boxes that cut off long values.

Near: Crystal Reports: ~750-900ms, even worse has legacy | Near: In Crystal Reports, you move around boxes

LaTeX. About 500 to 800 ms to compile and render, plus a very large package and a tendency to be rather memory-hungry, which suit Lambda poorly.

Near: LaTeX: ~500-800ms for compilation plus rendering | Near: LaTeX comes with a huge compilation package

Reasoning

The imaginary client needs about 1 million trade confirmations within minutes of market close; the author set a 10-minute target, put at 1,667 PDFs per second, and did not want to make up for slow renderers with large amounts of compute. Lambda was chosen as an example of how it could be done, not as the easiest or cheapest way.

Section: Setting the stage | Near: Since I have neither the intention nor | Near: not because I think this is the

Outcome

Before tuning, the first test request took 141 ms in the renderer Lambda, template fetch included, which the author judged not good enough.

Near: fetching the template and rendering it took 141ms

Decision#d2

Reuse clients, templates and partly compiled templates across warm Lambda invocations, and batch jobs

ersteiger-2025-serverless-pdf-rendering#d2 at corpus version 26a1b3a7e3dd
Chosen

The renderer keeps its S3 client, downloaded templates and part of the template compilation in memory between warm invocations. Render data is grouped by template, and the author notes that SQS can hand the renderer jobs in batches.

Section: 2. Caching | Section: 3. Batching

Reasoning

Opening S3 or SQS connections costs tens of milliseconds, most jobs reuse one template so the S3 round trip can be skipped, and sending a million separate requests through API Gateway would add enough network latency to become the bottleneck in testing.

Near: creating a connection to S3 or SQS | Near: we can also cache the template and | Near: The network latency from sending 1 million

Outcome

With the tuning in place, a preliminary test processed 1000 requests in 11 seconds, 91 PDFs per second, under the 10 unreserved concurrent invocations of a new AWS account, and a warm renderer with cached template and compilation took roughly 35 ms per PDF. The million-PDF run was not done while the author waited for a quota increase.

Section: Results | Near: I had a limit of only 10 unreserved | Near: for now I am waiting for the

Review

Extracted by
Claude (feed 72)
Human review
Not started. Status recorded on 2026-12-02.