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
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.
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#d1at 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
Reuse clients, templates and partly compiled templates across warm Lambda invocations, and batch jobs
ersteiger-2025-serverless-pdf-rendering#d2at 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