Microservices

High-Throughput Go PDF Generation: Sub-10ms Typst Without CGO

By Rubrol Engineering Team • 5 min read • Updated September 2026

Go microservices are celebrated for their raw concurrency, low memory footprint, and single-binary deployments. However, the moment a Go service needs to generate dynamic PDF invoices or statements, architecture teams hit an ugly wall:

The Zero-CGO Sidecar Solution

Rubrol deploys as an ultra-lean Rust sidecar (under 40MB image size) that communicates with your Go service over a local Unix Domain Socket or HTTP connection. Your Go application sends JSON data, and Rubrol returns a compiled PDF/A-3b document in sub-10ms with zero CGO overhead.

Go Implementation Snippet

package main

import (
	"bytes"
	"encoding/json"
	"io"
	"log"
	"net/http"
	"os"
)

type InvoicePayload struct {
	Template   string                 `json:"template"`
	Data       map[string]interface{} `json:"data"`
	Compliance string                 `json:"compliance"`
}

func GenerateInvoice(invoiceID string, amount float64) ([]byte, error) {
	payload := InvoicePayload{
		Template: "enterprise_receipt",
		Data: map[string]interface{}{
			"id":     invoiceID,
			"amount": amount,
		},
		Compliance: "factur-x",
	}

	body, _ := json.Marshal(payload)
	resp, err := http.Post("http://localhost:8080/v1/compile", "application/json", bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	return io.ReadAll(resp.Body)
}

func main() {
	pdfBytes, err := GenerateInvoice("INV-8821", 1250.50)
	if err != nil {
		log.Fatalf("Compilation failed: %v", err)
	}
	os.WriteFile("invoice.pdf", pdfBytes, 0644)
	log.Println("Invoice compiled in sub-10ms!")
}

Ready for Microsecond Document Latency?

Test the Rubrol compiler live in the browser studio.

Open Live Studio