Book a call

From 64 seconds to 8: making month-end reports fast at scale

Every month, on the 1st, our platform builds a Month-End Pack for each business that uses it: revenue, payments, refunds and tips for the month, a books-ready CSV for the bookkeeper, and an email that says “your month is done.” At the end of the year, the same data becomes a zip file the accountant can work from.

It’s the kind of automation owners love because it removes a recurring chore entirely. It’s also the kind of automation that quietly gets slower every month, because the data it reads keeps growing. This is the story of making it fast, and staying fast, with real numbers.

The test: two years of data for 500 businesses

We don’t tune performance against an empty database. Before shipping, we generated a realistic load:

  • 500 businesses with uneven sizes: the busiest had 1,852 bookings in a month, the median 80, the quietest 37
  • 24 months of history
  • About 1 million bookings and 1.1 million payment events (2.1 million rows)

Then we ran the monthly worker the way it runs in production: build and freeze 1,500 packs, queue 1,000 emails.

First result: 64.3 seconds for the full pass, or about 43 milliseconds per pack. That sounds fine, until you notice how it grows.

Bottleneck 1: reading the whole history to answer “what happened this month?”

To build October’s pack, the system asks one question: which payments did business B receive between October 1 and November 1?

The database couldn’t answer that directly. Payment events weren’t labelled with their business, and there was no index on their date. So the only way to find a business’s October payments was to visit every booking the business had ever had, then check each one for payments in October.

For a median business, that meant walking 2,005 bookings to find 76 payment events. In database terms, it touched 10,570 data pages to return a few dozen rows.

The real problem is the growth curve: the cost grew with the age of the business, not with the size of the month. A client who had been with us three years would have been three times slower than a new one, for the same month.

The fix was two small, careful changes:

  1. Add the business to each payment event, filled in automatically by the database when the row is written, so no part of the code can ever forget or get it wrong.
  2. Add an index on (business, date), so “payments for business B in October” goes straight to the answer.

After: 1,068 pages instead of 10,570, and the median business’s ledger read dropped from 27 ms to under 1 ms. The busiest business went from 147 ms to 13 ms.

The full monthly pass went from 64 seconds to 8.

Bottleneck 2: decoding data just to write it out again

The year-end export had a different problem. Each month’s transactions were stored as structured JSON, about 313 bytes per transaction. To build the export, the system read the JSON, turned it back into objects, and then wrote those objects out as CSV.

For our busiest test business, with 24,555 transactions in a year, the timing split was telling:

Step Time
Query 70 ms
Decode JSON 138 ms
Write CSV and zip 68 ms

Half the time was spent converting data into a format we then immediately converted again.

The fix: when a month is frozen, store its CSV rows as finished text. The export just joins the months together. Decoding dropped from 138 ms to 1 ms, storage fell from 7.7 MB to 3 MB, and the year-end export went from 288 ms to 69 ms, about four times faster.

What we deliberately left alone

Not every slow thing is worth fixing. After both fixes, the biggest remaining cost in the year-end export is compressing 3 MB of CSV into a zip, about 49 ms. We could shave it, but the export runs once a year per business. That’s measured, written down, and left alone.

Why this matters if you’re buying automation

You’ll probably never care about index scans. But you should care about three things this example shows:

  1. Automations have growth curves. Something that takes a second today can take a minute next year if it reads more history every time it runs. Ask whoever builds yours how it behaves after three years of data, not three weeks.
  2. Test with realistic volume. We tested with 2 million rows before a single customer depended on it. The cost of finding this in production is a 1st-of-the-month email that arrives at noon, or not at all.
  3. Measure, then decide. We fixed the two problems that grew with your business and left the one that didn’t. Good engineering is as much about what you don’t change.

Every automation we build for clients gets the same treatment: realistic test data, measured before and after, and written-down decisions you can read later.

The numbers above come from load tests on generated data, not from client accounts. The full benchmark write-up ships with the code.