How a 300‑Line Go PDF Invoice API Generates $2K/Month with Zero Overhead
This article explains how a compact Go‑based PDF invoice generator for freelancers, built as a single‑binary API, evolved from a weekend prototype to a steady side‑business earning $1,500‑$2,000 monthly, detailing its architecture, performance gains, low‑cost hosting, and monetization model.
What the Application Does
It is a lightweight PDF invoice generator designed for freelancers, exposing a simple HTTP API that creates invoices on demand.
Why Go?
Three reasons drove the switch to Go: (1) a single binary eliminates dependencies and simplifies deployment; (2) Go’s runtime delivers high performance, handling traffic spikes with ease; (3) built‑in memory safety and straightforward concurrency have prevented bugs since launch. The original Node.js prototype used 70% more memory and had a cold‑start time 90% slower than the Go version.
Codebase Overview
module pdfapi
go 1.21
require (
github.com/jung-kurt/gofpdf v1.16.0
) pdfapi/
├── main.go // Entry point
├── handler.go // HTTP logic
├── pdf.go // PDF generation
├── config.go // Env & config
├── auth.go // Simple API‑key auth
└── utils.go // Reusable helpersEach file stays under 100 lines, keeping the codebase concise and readable.
Request Flow (ASCII Diagram)
(Client)
|
| POST /generate
V
[Auth Layer] -- (API Key)
|
V
[Parse JSON] -- name, amount, items[]
|
V
[Generate PDF with gofpdf]
|
V
[Stream back PDF bytes]
|
V
(Client receives invoice)Hosting and Cost
The service runs on a $5‑per‑month Fly.io instance with 512 MiB RAM and a shared CPU, handling roughly 20 000 requests per month and averaging about 50 ms response time.
BenchmarkGeneratePDF-8 5020 225000 ns/op ~0.2 msNo external database or third‑party APIs are used; all data resides in memory or local cache.
Monetization
Paid API key access : $10 per month per key.
One‑time self‑hosted license : $49 flat fee.
Payments are processed via Stripe. The model avoids freemium traps and churn.
Decision Tree for Switching to Go
+------------------------------+
| Is your current stack slow? |
+-------------+----------------+
|
v
+-------------------------------+
| Do you need a single static |
| binary executable? |
+---------------+---------------+
|
v
+---------------------------------------+
| Is concurrency or memory a problem? |
+---------------+-----------------------+
|
v
Use Go. It fits.If you need to handle API, JSON, PDF, or other request‑intensive workloads, Go is a reliable choice.
Lessons Learned
Simple and scalable both technically and commercially.
Focusing on a niche solves a real pain point better than building a generic tool.
Go’s performance lets low‑spec servers deliver fast responses.
Conclusion
Even after six months without touching the code, the service remains bug‑free and continuously covers the author’s rent, proving that a small, well‑engineered Go binary can become a sustainable side‑business.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
