Laravel Performance & Optimization

How to Find and Fix N+1 Queries in Laravel

May 14, 2026
How to Find and Fix N+1 Queries in Laravel

Why N+1 Queries Hurt Laravel Performance

N+1 queries are one of the most common reasons Laravel dashboards slow down under real traffic. A single page can jump from 12 SQL statements to 400+ when relationships are loaded inside loops.

Step 1: Measure Before You Refactor

Start with Laravel Telescope or Clockwork on staging. Filter requests above 200ms and inspect the query tab. If you see the same table queried dozens of times with different IDs, you have an N+1 pattern.

Step 2: Replace Loops with Eager Loading

  • Use with() for standard relationships
  • Use withCount() when you only need counts
  • Use load() after conditional logic when eager loading upfront is wasteful

Step 3: Validate in Production Safely

After refactoring, compare P95 response time and total queries per route. Most LaravelOps clients see 60–90% fewer queries on reporting pages within one sprint.

Need a full performance audit? Book a Laravel performance review with our team.

Common Questions

Engineering FAQs

Direct answers to the most frequent inquiries regarding Laravel performance, security, and infrastructure scaling.

Our audits are data-driven, leveraging tools like Blackfire.io and Laravel Telescope. We focus on Time to First Byte (TTFB), N+1 query identification, memory consumption per request, and CPU profiling under simulated high-concurrency loads.
A typical migration to a Blue-Green or Canary deployment pipeline on Kubernetes takes 10–15 business days. This includes CI/CD pipeline refactoring, infrastructure-as-code (Terraform) development, and exhaustive load-test verification.
Yes. Most enterprise clients opt into our Security Retainer, which includes real-time vulnerability scanning, patch management for the Laravel core and its dependencies, and monthly penetration test reports.
Absolutely. We specialize in legacy modernization. We provide a phased performance improvement plan that often includes upgrading PHP versions, refactoring bottlenecked Eloquent models, and implementing modern caching patterns without requiring a full rewrite.
While results vary by application complexity, we typically achieve a 3x to 5x increase in request throughput (requests per second) and a 40-60% reduction in response latency by eliminating the framework bootstrap overhead.