The Friday Deploy
The plain English newsletter for people who run the business, not the tech stack. No jargon. Every Friday.
What Does “N+1 Query Problems” Actually Mean?
Your developer just flagged “N+1 query problems” as the reason your site is loading slowly. If you’re wondering what that means and whether it’s worth fixing, this article explains the problem in plain terms, what it costs your business, and how to decide if you should prioritise it.
What Are N+1 Queries?
N+1 queries happen when your application makes too many trips to the database instead of getting all the information it needs in one go.
Think of it like this: you’re ordering coffee for 10 people. You could walk to the counter 11 times (once to get the list of people, then once per person to order their coffee), or you could walk once and order all 10 coffees together. N+1 queries are the inefficient approach.
In technical terms, your application runs one query to get a list of items (products, orders, blog posts), then runs a separate query for each item to get related information. If you’re displaying 50 products, that’s 51 database queries when you only needed two.
Why This Happens
This problem typically appears when developers add features quickly. They get the main functionality working, then realise they need additional data. Instead of restructuring the original query, they add a loop that fetches extra details for each item.
It’s rarely intentional. It’s usually a trade-off between speed of delivery and optimisation, and it often slips through because test databases are small enough that the performance hit isn’t noticeable during development.
How N+1 Queries Affect Your Business
Every extra database query adds milliseconds to page load time. When you multiply those milliseconds across thousands of page loads, you get real business impacts.
Slower page load times directly affect conversion rates. Amazon found that every 100ms of latency cost them 1% in sales. Google reported that an extra half-second in search page generation time dropped traffic by 20%.
Beyond lost conversions, N+1 queries increase your infrastructure costs. Your database server works harder than necessary, which means you’re either paying for more server capacity than you need, or your existing infrastructure struggles during traffic spikes.
If you’re seeing page load times over 3 seconds on product or category pages, N+1 queries might be the culprit. Users typically abandon slow pages, and search engines rank faster sites higher.
How to Spot N+1 Query Problems
There are several signs that suggest N+1 queries might be affecting your site. Pages that load slowly only when displaying lists (product catalogues, search results, blog archives) are classic symptoms. If individual product pages load quickly but category pages with 20 products are slow, you likely have this problem.
Database server CPU usage that spikes during normal traffic is another indicator. If your hosting costs keep climbing without a proportional increase in visitors, inefficient queries might be consuming unnecessary resources.
The most definitive way to identify N+1 queries is through your application’s query logs or performance monitoring tools. Tools like New Relic, Scout APM, or Sentry can automatically detect and flag N+1 patterns. If you’re on Rails, the Bullet gem catches these during development. For Node.js applications, tools like Sequelize’s built-in logging can expose these patterns during development.
The Fix: Eager Loading
Developers solve N+1 queries through a technique called eager loading. Instead of fetching data in a loop, they tell the database upfront what related information they’ll need.
For a typical Rails application, this means changing Product.all to Product.includes(:category, :manufacturer). In Node.js with Sequelize, it’s Product.findAll({ include: ['category', 'manufacturer'] }). The syntax varies by framework, but the concept is the same: fetch everything in one or two queries instead of dozens.
Instead of 51 queries for 50 products, you’re back to 2-3 queries total.
What Fixing N+1 Queries Costs
For a typical web application, fixing N+1 queries on a few problem pages usually takes a developer 4-8 hours, depending on how many pages are affected and how complex your data relationships are.
More complex fixes involving restructured queries or optimised database indexes might take several days. If the problem is widespread across your entire application, budget for 1-2 weeks of developer time.
The return on investment is usually immediate. One client saw page load times drop from 3.2 seconds to 0.8 seconds after fixing N+1 queries on their product catalogue, which translated to a 12% increase in add-to-cart conversions within two weeks.
Questions to Ask Your Developer
Before committing to fixes, get specific information about the scope and impact.
Which pages are affected? The priority is different if it’s your homepage versus a rarely-visited admin page.
How many queries are we talking about? There’s a significant difference between 50 extra queries and 500. Ask for actual numbers.
What’s the measured performance impact? Request before-and-after load times, not estimates. Good developers will profile the slow pages and show you concrete data.
Is this causing problems now or could it wait? If you’re not seeing complaints and traffic is stable, this might not be urgent.
When to Prioritise N+1 Query Fixes
Fix N+1 queries immediately if you’re experiencing slow page loads on high-traffic pages, your database CPU is consistently above 70%, you’re about to launch a marketing campaign that will drive significant traffic, or hosting costs are climbing without traffic increases.
You can defer the fix if affected pages are low-traffic admin sections, you’re not seeing performance complaints from users, or you have more urgent revenue-affecting bugs in the queue.
For ecommerce sites, prioritise fixes on product listing pages, search results, and checkout flows. For content sites, focus on article listings, category pages, and homepage feeds. These high-traffic areas deliver the best return on optimization investment.
Long-Term Prevention
Rather than treating N+1 queries reactively, implement systems to catch them before they reach production.
Good developers configure their local development environments to flag N+1 queries during testing. Tools like Bullet for Rails or query logging in Node.js frameworks surface these issues immediately.
Code review processes should include performance checks. When reviewing pull requests, experienced developers specifically look for loops that trigger database queries.
Application performance monitoring tools like Scout, New Relic, or Skylight automatically detect N+1 patterns in production and alert your team. Setting these up costs a few hundred dollars monthly but prevents expensive performance problems.
The Bigger Picture
N+1 queries are one of the most common database performance problems in web applications. They’re easy to introduce, often invisible in development, and only become obvious when your database grows or traffic increases.
If your developer is identifying and flagging these problems proactively, that’s a positive sign. They’re thinking about performance and scalability, not just delivering features.
The conversation shouldn’t end at “we have N+1 queries.” The better question is: what process can we implement to catch these before they affect users? Good development practices include performance testing, code review checklists, and monitoring that surfaces these issues automatically.
Most N+1 query problems can be fixed quickly and deliver immediate, measurable improvements. The key is prioritising based on business impact rather than technical perfection. Fix the queries that affect revenue first, implement monitoring to catch new ones, and you’ll avoid this becoming a recurring problem.
Read more Technical Translation
Database, Optimisation, Performance, Rails
Previous NextThe Friday Deploy
The plain English newsletter for people who run the business, not the tech stack. No jargon. Every Friday.