YouTube video summary

How We Replaced Crystal Reports with Rust & Typst (Sub-2ms PDFs)

Technology
27 Jul 202610 min summaryFrom InfoQ
How We Replaced Crystal Reports with Rust & Typst (Sub-2ms PDFs)
InfoQ
YouTube

Challenges in Legacy Document Generation

  • Document generation and PDF rendering are significant pain points in industries such as banking and manufacturing, particularly within regulated environments where compliance is mandatory 15s.
  • A banking client faced regulatory pressure from the German regulatory institute because their legacy PDF pipeline, which relied on COBOL, was too slow to meet requirements for timely document delivery 1m15s.
  • The banking client attempted to migrate their PDF rendering to the cloud using AWS Lambda, but struggled for years to establish an efficient pipeline, eventually resorting to complex methods involving Java and pre-compiled programs for each template 1m45s.
  • In the manufacturing sector, the primary challenge involved managing regulatory requirements for shipping documentation, such as weight slips and medical gas certificates, which were essential for truck departures 2m25s.
  • The troubleshooting process for manufacturing PDF errors was highly inefficient, requiring service providers to navigate multiple VPNs, download multi-gigabyte production database backups, and recreate orders in a test environment to reproduce issues 2m55s.

Limitations of Crystal Reports

  • Crystal Reports, a software originating in 1984, is frequently cited as a source of frustration and is considered an outdated tool for modern document generation needs 4m5s.
  • Crystal Reports functions by connecting to a database to fetch a schema, allowing users to drag and drop fields onto a PDF template 0s.
  • Managing documents for multiple international factory locations using Crystal Reports proved inefficient, as translating templates required manually copying and pasting every element into translation tools 15s.

Comparison of Typesetting and Rendering Tools

  • LaTeX is a typesetting system often used in scientific contexts that functions like a programming language to generate PDFs, which is particularly effective for rendering complex mathematical formulas 42s.
  • Puppeteer is a tool used in web development to generate PDFs by rendering web technologies through a headless Chrome instance 1m10s.
  • While Puppeteer allows developers to leverage CSS and web design skills, it carries the overhead of launching a full browser instance to produce a PDF 1m25s.

Requirements for Modern Document Systems

  • Traditional document management workflows often lack the benefits of modern software development practices, such as Git version control, Docker-based reproducibility, and CI/CD pipelines 1m45s.
  • Ideal requirements for a document generation system include high rendering speed for large volumes of PDFs, low memory consumption, and support for version control 2m15s.
  • Crystal Reports is limited by its lack of cross-platform support, as it is restricted to Windows and does not function on ARM-based Apple silicon 2m45s.
  • The workflow for testing document templates in Crystal Reports is cumbersome because it requires a direct database connection, whereas a more efficient approach would involve simply providing the necessary JSON data 3m5s.

Introduction to Typst and LaTeX

  • Typst is a newer typesetting system developed by a team in Berlin based on a master's thesis that serves as a leaner alternative to LaTeX 3m20s.
  • Both LaTeX and Typst operate as typesetters where users write code to define text and formatting, which the system then processes to create professional layouts with features like automatic paragraph breaks 3m30s.
  • Typst utilizes a domain-specific language (DSL) that resembles Markdown, using syntax such as equal signs to denote section headers 3m45s.
  • LaTeX distributions are described as complex, requiring approximately 5 GB of space and involving numerous dependencies 0s.
  • Typst is presented as a modern alternative that is under 50 megabytes, offers a better developer experience, provides clearer error messaging, and performs faster with large files compared to LaTeX 5s.

System Architecture and Serverless Implementation

  • The objective was to create a system that injects dynamic customer data from a database into a fixed document template to generate PDFs, such as invoices 35s.
  • The system was designed to be easily used as a library, allowing for the rendering of templates using strings or files combined with JSON data 55s.
  • A prototype was developed using Rust and deployed on AWS Lambda, utilizing Terraform for infrastructure as code 1m12s.
  • The project was created to demonstrate a superior alternative to Crystal Reports, a tool widely associated with negative user experiences 1m25s.
  • The serverless architecture utilizes two AWS Lambda functions: the first receives requests and places them into an SQS queue, while the second retrieves templates from S3, renders the PDF using Typst, and saves the result back to an S3 bucket 1m55s.
  • Cargo Lambda was used to facilitate the development of the Rust-based AWS Lambda functions 2m15s.
  • The system allows users to submit a request containing a template name and data, receiving a confirmation that the job has been queued for rendering 2m25s.
  • The rendering process is highly performant, requiring less than 50 megabytes of memory and completing in under 100 milliseconds, which is more efficient than traditional methods like launching a browser or using LaTeX 2m45s.

Performance Optimization and Caching

  • Rendering a million PDFs using this approach costs less than 50 cents, which is approximately 20 times cheaper than alternative methods 0s.
  • The rendering process achieves speeds in the double-digit millisecond range, and with template caching, rendering times on a small AWS Lambda can drop below 2 milliseconds 0s.
  • Caching works by compiling the static parts of a template and only updating the specific variables that change, such as a new number 42s.
  • Initial performance was hindered by sequential uploads to S3, but optimizing this process could yield an additional 30% reduction in time 1m5s.
  • Provisioned concurrency on AWS Lambda generates continuous billing, leading to the consideration of using Lambda function URLs to avoid unnecessary costs 22s.

Template Management and Versioning Challenges

  • The system utilizes Typst templates that are editable in standard code editors, support Git version control, and accept JSON as input for easy mocking 1m15s.
  • The initial version lacked support for multi-file structures, making it difficult to manage large templates or include assets like logos without creating massive, single-file documents 1m45s.
  • Challenges remain for financial institutions or organizations that prefer to host services on-premises rather than using AWS 1m35s.
  • Inspiration for future improvements, such as better version control and debugging, is drawn from package managers and Docker Hub, which utilize strict versioning and hashes 2m5s.

Content-Addressable Storage and Compliance

  • Content-addressable storage is proposed as a solution, where files are stored based on a hash of their content rather than their original filenames 2m25s.
  • This storage method provides automatic deduplication, ensuring that identical files used across multiple templates are not stored multiple times 2m35s.
  • A human-readable versioning system is desired, allowing users to reference specific template versions, such as an "invoice at latest" 2m50s.
  • Regulated industries require the ability to specify exact document templates to ensure consistency, particularly when corporate designs are updated or versioned 0s.
  • A template must be treated as a comprehensive bundle that includes the main file, logos, assets, and fonts to guarantee that the output remains identical across different renders 22s.

Template Registry and Data Integrity

  • The system architecture allows for a backend endpoint where users manage templates by defining a main entry point, attaching necessary files, and adding metadata 45s.
  • Upon submission, the system generates a hash representing the entire data set, which is stored alongside a manifest file 1m3s.
  • The storage mechanism utilizes a structure similar to a Merkle tree, where data components are referenced by their individual hashes within a JSON document that is itself hashed 1m15s.
  • Users can access specific templates by referencing a hash directly or by using a reference pointer, such as "latest," which maps to a specific manifest hash 1m35s.
  • The workflow enables the reproduction of failed renders by storing the template reference, the specific data used, and the render ID, allowing for inspection and testing to identify missing information like expiry dates 1m55s.

Scalability and System Features

  • A registry built on top of the rendering engine can provide template management, compliance, and analytics, similar to the functionality found in Docker Hub or package managers 2m35s.
  • Implementing this architecture on a server allows for horizontal and vertical scaling, efficient use of CPU cores through parallelization, strong caching to reduce latency, and a modern JSON-based data interface 2m55s.
  • A proposed system architecture includes a user interface that allows faculty to view past renders, identify failed attempts, inspect data, and download generated PDFs 0s.

Comparative Analysis of Rendering Engines

  • Traditional document generation tools like LaTeX are described as having heavy dependencies, requiring up to 5 GB for installation and resulting in large Docker images, whereas the new approach bundles into less than 100 megabytes 22s.
  • Unlike Crystal Reports, which requires an active database connection, the new system functions by combining a template with provided data 35s.
  • Puppeteer is noted for its CSS design capabilities but is criticized for high memory consumption and long cold start times, making it slow for use in environments like AWS Lambda 42s.
  • Typst, originally designed for scientific publishing, is highlighted as a performant alternative for industrial document generation 1m5s.
  • Integrating modern tools such as Docker, Git, and version control with this document generation process provides strong compliance guarantees and consistent PDF output 1m18s.

Open Source Projects and Benchmarking

  • The original Typst PDF renderer and the associated code are available as open-source projects 1m35s.
  • A benchmark comparison was conducted using a trade confirmation template designed for a bank, featuring a single page with significant text, lines, and a PNG image 2m15s.
  • The benchmark test included randomized data, which necessitated dynamic re-layouting of tables and occasionally resulted in multi-page documents depending on the length of the content 2m55s.
  • No direct speed comparison was performed against LaTeX, although the reduction in Docker container size compared to LaTeX is acknowledged as a significant improvement 3m25s.

Performance Benchmarks and Technical Specifications

  • Historical PDF rendering solutions, such as LaTeX, typically achieve speeds between 300 and 500 milliseconds 0s.
  • While LaTeX can be heavily optimized, it is often perceived as outdated due to large compilation sizes and difficult error messaging 12s.
  • Documentation regarding the deployment of Rust programs into AWS Lambda functions using Terraform is available online 42s.
  • The described PDF rendering system is entirely open source and consists of three primary crates: a main library built around Typst, a registry for manifest and hash creation, and a server wrapper 1m12s.
  • The system relies heavily on the Typst PDF rendering engine 1m32s.
  • Depending on the complexity of the caching implementation, PDF generation can achieve speeds of under 10 milliseconds 1m55s.

Data Tracking and Compliance Verification

  • The primary motivation for developing this system was the need to generate very large volumes of PDFs in a timely manner 2m6s.
  • The rendering pipeline involves taking text in JSON format, creating a hash of that data, mapping it to a template, and rendering the final PDF 2m25s.
  • It is possible to trace a rendered PDF back to its original data if the system stores the PDF or its hash in a bucket, which allows for the identification of the manifest used during generation 2m40s.
  • Storing hashes and manifests is useful for compliance purposes, as it allows organizations to verify which version of a document was used 3m5s.
  • A change in the underlying data, even if not visually apparent in the final PDF, will result in a different hash, meaning that identifying a document based on visual similarity requires a different approach than hash-based tracking 3m25s.

Capabilities and Future Outlook

  • While Typst is capable of handling most standard PDF layouts, it is unclear if it supports animation, though most common PDF layouts are achievable 3m55s.
  • Typst is capable of generating graphs and incorporating images, extending its utility beyond the scientific use cases typically featured in its documentation 0s.
  • The software is considered powerful and suitable for document generation, provided the requirements are not highly exotic 12s.
  • The presentation concludes with an invitation for audience members to share their experiences or challenges regarding document creation 18s.
  • The session ends with a transition to a lunch break 28s.
Made with Recall · in 3 seconds

Get a summary like this for anything you read, watch or save.

Recall summarizes any link you paste, then keeps it in your personal library so you can search, chat with it, and never lose a key idea again.

YouTube videosArticlesPodcastsPDFsAnything else
Save this summary

Keep it in your library.

Save to your library

Ready to get started?

Save, summarize and chat with your content.

GET STARTED
IT'S FREE

No credit card required · 30 Day Refund on Premium · 24 Hour Support

Recall web app on laptop, personal AI knowledge base for summarizing and chatting with your content