1.5M PDFs in 25 Minutes
zerodha.tech
zerodha.tech
> By converting our HTML templates into TEX formats and utilizing pdflatex for PDF generation, we observed a 10X increase in speed compared to the original Puppeteer way of generating
8*60/10 = 48 minutes. So this speedup alone would've been enough, wouldn't it?
Crazy example of how fast typst is: 30”x30” document with 2600 tiny images generates a 40MB PDF in under a half second.
Check typst out. It’s amazing. Not quite latex equivalent in some ways but moving fast on an amazing foundation.
This looks much more reasonable than fpdf's bare bones nature, or wkhtmltopdf / snappy / puppeteer needing esoteric, old CSS specs and having a lot of quirks because of it.
Particularly happy at how it can swap page size as needed.
It appears they are emailing PDF copies of stock market transactions to fulfill a regulatory requirement, so the PDF generation should be deterministic and email delivery of a receipt is an idempotent operation.
Instead of all that scheduled orchestration complexity they could just queue their PDF jobs to SQS and do the work in a Lamba function, this would also let them queue the PDFs as the transactions are happening instead of continuing to run this as a nightly batch job.
It's also unclear why render + sign + add to mail queue need to be 3 separate queued tasks. They have to execute serially, so a single worker could do the whole process and checkpoint to S3 after each step, or not because the output is deterministic anyway.
It would also eliminate their issues with S3 request limits by keeping all the data relevant to a PDF local to 1 worker for the duration of processing.
> For the contract note generation job, we spawn about 40 instances in total currently, a mix of c6a.8xlarge, c6a.2xlarge, and c6a.4xlarge.
As a very rough benchmark, print this page to a PDF file to see how long it takes.
It's like switching from a gym where you're on your own and no one cares to one where you're yelled at if you miss your training. Naturally, the former delivers much better results, but there is an adaptation period which makes a lot of people give up.