Zomato Engineering | March 17, 2025 | 4 min read
Espresso: Brewing PDFs at Zomato, Faster Than You Can Say “Cappuccino”

Introduction

At Zomato, we love food and we love data. And sometimes, those two passions collide in the creation of beautiful, portable, and secure PDFs. From invoices and receipts to detailed reports, PDFs are a cornerstone of our operations and a staple across the industry. However, our existing PDF generation process, powered by a PHP-based library, was starting to show its age. We encountered latency issues, especially during the peak hours and the situation worsened with complex, multi-page PDFs that included significant graphical content.

We needed a solution that could sustain our growing demands – something faster, more efficient, and scalable.

The Perfect Blend: Chromium and Golang

In pursuit of a more tailored and efficient approach, we decided to develop our in-house PDF generation solution. We chose Go as our programming language, given its performance and our team’s familiarity with it.

For rendering, we leveraged Rod, a go library for controlling headless Chromium. For PDF signing, we integrated Go PDF (digitorus/pdf), allowing us to generate and sign PDFs directly from HTML templates. This approach gave us full control over layout, styling, and security.

Custom Certificate Signing

To ensure the authenticity and integrity of our PDFs, we implemented digital signing using a custom certificate. This adds a layer of security and trust to our documents, which is especially important for sensitive information like financial transactions.

Optimizations: Squeezing Every Last Drop of Performance

We’re always looking for ways to improve performance, and Espresso is no exception. We implemented several optimizations to make our PDF generation process as fast and efficient as possible:

  • Pre-Paint PDF Generation: We generate the PDF before the paint step of the rendering process, saving valuable time.
  • Chromium Flags: We fine-tuned various Chromium flags to further improve the start time of the application.
  • DataURI Image Prefetching: We prefetch HTML images from the template and save them as dataURIs, reducing the rendering cost by eliminating the need for the browser to download images on page load.
  • Streamlined Processing: By combining PDF generation and signing into a single application, we can work with streams instead of files, improving performance and reducing disk I/O.

Brewing PDFs for Everyone

We developed a small front-end application to accompany this system, allowing anyone at Zomato to create and customize PDF templates effortlessly. This tool empowers users to modify existing templates or design new ones from scratch, all while receiving real-time feedback on the appearance of their final PDF output.

Open Source: Sharing the Espresso Love

Driven by our commitment to open source, we’re excited to announce that Espresso is now available for everyone. You can deploy it in your environment, tailor it to your specific requirements, or even actively contribute to its ongoing development. This includes the lib package, which you can utilise as a library within your Go applications to build and customize your PDF generation solutions.

We hope that Espresso will serve as a powerful asset for organizations and developers seeking a rapid, efficient, and dependable PDF generation solution.

You can find the repository on github: https://github.com/zomato/espresso. We’re offering Espresso and the packages with a very permissive MIT license, allowing developers to utilise it as per their requirements/needs while retaining full ownership of the data.

Benchmarks: The Proof is in the Pudding

Espresso isn’t just fast – it’s incredibly fast. Espresso has been successfully deployed across the majority of our PDF generation workflows, delivering consistently impressive performance metrics.

  • Rendering and Signing Times Under 200ms: Espresso can render and sign PDFs in under 200 milliseconds, making it ideal for high-traffic applications.
  • Peak Load Handling: Espresso can handle peak loads of 120K requests per minute (RPM), ensuring your users never have to wait for their PDFs.
  • Massive Signing Capability: We recently signed 1.6 million PDFs in just 19 minutes – approximately 1,400 PDFs per second.

These numbers were witnessed when running espresso as an AWS ECS service with 4vcpu and 4G memory. This scaled to a hundred containers at peak load.

Espresso’s efficiency is truly remarkable. Compared to our prior system, it demands significantly less infrastructure, drastically reducing resource consumption. This translates directly into substantial cost savings, resulting in a 90% deduction in server costs for generating the same volume of PDFs.

Conclusion: The Perfect Cup of PDF

Espresso is the culmination of our quest for the perfect PDF generation solution. It delivers simplicity, speed, efficiency and unwavering reliability, all within an open-source framework. We’re proud of what we’ve built and are excited to share it with the world. So go ahead, grab a cup of your favorite beverage, and give Espresso a try. We think you’ll find it’s the perfect blend of speed, simplicity, and power.

And remember, much like a perfectly brewed coffee, the most effective solutions are often discovered in the simplest of places.

facebooklinkedintwitter

More for you to read

Technology

apache-flink-journey-zomato-from-inception-to-innovation
Data Platform Team | November 18, 2024 | 10 min read
Apache Flink Journey @Zomato: From Inception to Innovation

How we built a self-serve stream processing platform to empower real-time analytics

Technology

introducing-pos-developer-platform-simplifying-integration-with-easy-to-use-tools
Sumit Taneja | September 10, 2024 | 2 min read
Introducing POS developer platform: Simplifying integration with easy-to-use tools

Read more about how Zomato is enabling restaurants to deliver best-in-class customer experience by working with POS partners

Technology

migrating-to-victoriametrics-a-complete-overhaul-for-enhanced-observability
SRE Team | August 12, 2024 | 11 min read
Migrating to VictoriaMetrics: A complete overhaul for enhanced observability

Discover how we migrated our observability metrics platform from Thanos and Prometheus to VictoriaMetrics for cost reduction, enhanced reliability and scalability.

Technology

go-beyond-building-performant-and-reliable-golang-applications
Sakib Malik | July 25, 2024 | 6 min read
Go Beyond: Building Performant and Reliable Golang Applications

Read more about how we used GOMEMLIMIT in 250+ microservices to tackle OOM issues and high CPU usage in Go applications, significantly enhancing performance and reliability.