Every so often a feature works perfectly in testing, then crawls the moment a real client uses it. On the FHRS platform, the food safety compliance system I look after for FHR Services, that feature was competitor reporting. The first version of those reports took more than 50 seconds to run.

The cause has a slightly unfriendly name: the N+1 query problem. It is one of the most common reasons business software slows down, and one of the easiest to fix once you know it is there. Here is what it is, in plain English, and what it looked like in a real report.

The shopping trip problem

Imagine you send someone to the shop for ten items. They could take the list, go once and come back with everything. Or they could go for the milk, come home, check the list, go back for the bread, come home again, and so on. Same ten items. Ten times the travelling.

Software does the second thing more often than you would expect. Every time an application asks its database for something, that is a trip. Each trip takes a fraction of a second, but they add up. One trip to fetch a list, then one extra trip for every item on that list: that is N+1. N is however many items are on the list, and the 1 is the trip to get the list in the first place.

The tricky part is that the code looks perfectly reasonable. A developer writes something like "get the premises, then for each one show its latest inspection", and the framework quietly fetches each inspection with its own separate trip. Nothing breaks. It just gets slower as the list gets longer.

What it looked like in a real report

FHRS helps multi-site food businesses report on their food hygiene ratings, using official Food Standards Agency data. In January 2026 I built the second phase of a feature that lets clients include competitor businesses in their reports, so they can see how their own premises compare.

A report like that pulls together a lot of related information: establishments, their inspection history, the councils they fall under, and now competitors on top. In the first version, that related data was being fetched the N+1 way: one query for the list, then more queries for each row. Adding competitors meant many more rows, and every extra row brought its own extra trips. The result was report queries taking more than 50 seconds. In a web application that is long enough for people to assume something has crashed.

The fix: one trip with a list

The fix is called eager loading. Instead of fetching related data one row at a time, you tell the application up front what it is going to need, and it collects everything in a small number of bulk queries. One trip for the premises, one trip for all of their inspections, and so on. The number of trips stops growing with the number of rows.

In Laravel, the framework FHRS is built on, this is often a small change: adding a "with" instruction to the query that names the related data to bring along. The real work is finding exactly where the extra trips are happening, and then proving the report still shows the same figures afterwards.

With proper relationship loading in place, the competitor reports no longer suffered those 50 second query times. On the same day I removed a separate "row explosion" bug. Row explosion is what happens when related data is joined together carelessly: if one premises has several inspections and several competitors, the database can return every combination of them, and the report ends up churning through far more rows than really exist.

I also added database indexes as part of the same work. An index works like the index at the back of a book: the database can jump straight to the rows it needs instead of reading through everything. Three days earlier, new indexes on the establishments table had already cut report generation time by 40% for large clients.

The follow-up mattered as much as the fix. Over the following week I added automated tests covering the report output, and fixed a bug where competitor establishments were losing historic inspection data in reports. A faster report is only useful if the numbers in it are still right.

Why this matters if you own the software

The N+1 problem is a slow leak rather than a burst pipe. With ten rows, ten extra trips go unnoticed. With ten thousand, the same code makes ten thousand extra trips, and a page that was fine last year becomes painful this year. Nobody changed anything. The business just grew.

It is also why features pass testing and then struggle with real clients: test data is small and tidy, and your largest client's data is neither. The competitor feature is a good example: the extra data it adds is exactly what turned a hidden inefficiency into a wait of more than 50 seconds.

Signs to look out for

You do not need to read code to suspect an N+1 problem. These are the signs I would ask an owner about:

  • Slow for some clients, fine for others: often it is the accounts with the most data that suffer. If a small account is quick and a big one crawls, the work is growing with the data.

  • Gradually getting slower: no single release broke it. It has crept up as records have built up over months or years.

  • Reports or exports timing out: the request takes so long that the server gives up before it finishes.

  • A bigger server as the usual answer: more hardware can hide the problem for a while, but the number of trips keeps climbing.

None of these prove an N+1 problem on its own, but together they are a strong hint. The good news is that it is usually cheap to fix once it has been found. Developer tools can count the queries behind a single page, and Laravel can be set to refuse this kind of one-at-a-time loading during development, so new cases are caught before they ever reach your clients.

Measure first, then fix

The hard part is rarely the fix. It is knowing where to look. Guessing at performance problems tends to produce expensive changes in the wrong places, so I always measure before I change anything. That is why my Platform Audit includes a review of performance bottlenecks, slow queries among them, alongside security and infrastructure. Any work that follows is then aimed at what is actually slowing your platform down.

On FHRS, this kind of targeted work was part of turning a platform that was timing out on reports into one its users enjoy. You can read the story in the FHRS platform launch post, or the wider picture in the FHRS case study.

Further reading

If you want the technical detail, these are the articles I would point a developer to:

Is your platform slowing down as you grow?

If pages or reports are getting slower as your business grows, it is worth finding out why before paying for a bigger server. I start with a fixed-price Platform Audit: a plain-English report on what is slowing your platform down, with a costed plan to fix it.

Or, if you would rather talk it through first, get in touch directly. No jargon, no pressure.

The smallest safe first step

Not sure where your platform stands?

The fixed-price Platform Audit reviews your code, security and server, and gives you a plain-English report with a prioritised, costed action plan. £1,950, within two weeks.

champaign-2.png

Apr 29, 2026

From broken reports to a bottle of Champagne: the FHRS platform launch

I took over a food safety compliance SaaS that was timing out on reports, leaking memory on imports, and had serious security gaps. Here's what I fixed, and how Paul marked the launch.