01 · The briefA khata book built for their business, with tiny running costs
Nexora Global Ventures is a plywood and face veneer trader in Perumbavoor. They supply designers, builders and furniture makers. Like many traders, they track credit and payments party by party, the way a traditional khata book does.
They wanted their own app for this, built around how they work rather than a generic one. Their numbers were small: at most about 150 entries a month. So their top priority was clear: keep the monthly running cost as low as possible.
02 · Our approachAn honest experiment
We were upfront with them. Running a business app this cheaply was an experiment, and we couldn't promise it would be enough for everything. But at 150 entries a month it was worth trying, as long as we measured carefully and had a way out if it didn't hold.
It worked. Day-to-day entries, party ledgers and reports all ran smoothly on the small server.
03 · The problemOld data arrived, and one button maxed out the CPU
Everything stayed smooth until we migrated the client's old records. Every page still loaded quickly. But exporting a party statement as a PDF pushed the server's CPU to 100%. Parties with long histories now had statements with thousands of rows.
On a single-CPU server, that's not just one slow download. A busy CPU slows the app down for everyone using it at that moment.
The easy answer would have been a bigger server, but that would have raised the monthly cost the client cared about. We decided to measure first.
04 · What we foundMeasured, not guessed
The statements were being produced with WeasyPrint. It turns an HTML page into a PDF using a full layout engine, much like a web browser does. That is a good choice for invoices, but it's expensive for very long tables: for every row it works out styles, column widths and the position of every cell.
| Test (old method) | Time |
|---|---|
| 300-row statement | 2.4 s |
| 1,000-row statement | 6.6 s |
| 1,000 rows, with the text-wrapping style on the narration column | 12.4 s |
| 3,000 rows, split into 6 parts and merged | ~20 s |
Benchmarks on a development machine with test data and caches turned off.
The tests showed several things were adding up:
- The layout engine itself took roughly 6–7 milliseconds per row. That adds up to many seconds for a long statement.
- One line of styling doubled the time. The rule that wrapped long narration text roughly doubled the cost. Changing the font made no difference.
- Splitting the work didn't help. Breaking big statements into parts meant each part paid the setup cost again, and then the parts had to be merged.
- Users queued behind each other. A safety lock let only one PDF render at a time, so two people exporting at once had to wait in line.
- The cache only helped repeats. Re-downloading the same statement was fast, but every new or changed statement paid the full price.
We also found a bug along the way: statements large enough to be split into parts crashed because of a change in a PDF library. We fixed that too.
05 · The fixDraw the statement directly, skip the layout engine
A statement is a simple, predictable table, so it doesn't need a browser-style layout engine. We rewrote statement export to draw the PDF directly with ReportLab, placing text straight onto the page. The finished statement still has everything the client needs:
- Letterhead, party details, and an opening balance / debit / credit summary
- A table header that repeats on every page, striped rows, and Dr/Cr colouring
- Long narrations wrapped neatly, with a footer on every page showing the date and "Page X of Y"
Two more details kept it fast and light on a 1 GB server:
- Rows are streamed in batches of 500 from the database instead of being loaded all at once, so memory use stays flat even for very long statements.
- We profiled our own first version too. The profiler showed each cell's text was being wrapped three times. Wrapping it once halved the time again.
06 · The results15–20× faster statement exports
| Statement size | Before | After |
|---|---|---|
| 1,000 rows | ~6.7 s | ~0.3 s |
| 3,000 rows | ~20 s | ~1.3 s |
| 10,000 rows, full download through the app | ~70 s (estimated) | ~2.5 s |
Benchmarks on a development machine with test data. The live server has a single CPU, so real-world times are somewhat higher, but the improvement is just as large.
All 73 automated tests pass, including new ones. These check that long statements split correctly across pages, show the right totals and page numbers, and no longer use the slow engine.
Most importantly, the client didn't need a bigger server. The app still runs on the same ~₹700-a-month droplet.
07 · Trade-offsWhat we changed on purpose
- A slightly different look. To keep files small and fast, statements use a built-in font. That font has no ₹ symbol, so amounts show "Rs". The layout is very close to the original.
- No cache for repeat downloads. Even a 10,000-row statement is fast now, so caching wasn't worth the extra complexity.
08 · What we learnedSmall businesses don't need big infrastructure
- Size the system to the real workload. 150 entries a month doesn't need a database server, a load balancer or a large cloud bill.
- Measure before you spend. The fix for the slow export was in the code, not the hardware. Upgrading the server would only have hidden the problem at a higher monthly cost.
- Monitor from day one. Slow-page logging and benchmarks turned "it feels slow" into numbers we could act on.
- Be honest about experiments. We told the client the low-cost setup was a trial. When we found a limit, we fixed it and showed them the numbers.
