A slow application loses users and revenue. In most Laravel projects the biggest performance wins come from a handful of techniques — caching, eager loading, queues and database indexing — applied where they matter. This guide covers the optimizations that give the highest return with the least effort.
Measure first, optimize second
Never optimize by intuition. Start with measurements — Laravel Telescope or Debugbar for development, New Relic or Sentry for production. Look at three numbers: response time (p50 and p95), database query count per request and cache hit ratio. Optimization without measurement is guessing.
The N+1 problem — the most common Laravel performance bug
Loading a list of records and then querying related data for each one generates hundreds of queries. The fix is eager loading.
$orders = Order::with(['customer', 'items.product'])->paginate(50);
One query for orders, one for customers, one for items — instead of 50 or 150. In almost every audit we run, N+1 queries are the single biggest source of unnecessary database load.
Caching — config, routes, views and data
Laravel offers several cache layers, and they compound
- Config and route caching in production —
php artisan config:cacheandroute:cacheremove filesystem lookups on every request. - Query and data caching with Redis — cache expensive aggregations and external API responses with sensible TTLs.
- Response caching — full HTML responses for public pages through a middleware or reverse proxy.
Wskazówka: Cache invalidation is the hard part, not caching itself. Design keys around your data model (per-user, per-tenant, per-resource) and always set a TTL — even a short one protects you from stale data disasters.
Queues — move heavy work out of the request
Anything that does not have to finish before the response — e-mails, PDFs, external API syncs, image processing — belongs in a queue. Moving heavy operations to the background often cuts response times by 80% with no changes to the user-facing logic. We covered the setup in depth in our Laravel queues and Horizon guide (available on the Polish blog).
Database indexing and query optimization
- Index columns used in WHERE, ORDER BY and JOIN clauses — especially foreign keys.
- Use EXPLAIN to verify that queries use indexes instead of full table scans.
- Select only the columns you need; avoid SELECT * in hot paths.
- Watch out for LIKE queries with leading wildcards and unindexed JSON filters.
PHP and infrastructure
- Run the latest PHP version — each release brings measurable speedups for free.
- Enable OPcache in production; verify it is actually active.
- Use a CDN for static assets and correct Cache-Control headers.
- Consider HTTP/2 or HTTP/3 and compression at the edge.
Frontend performance
Backend optimization is half the story. Optimize images (WebP/AVIF), lazy-load below-the-fold content, keep JavaScript bundles small and measure Core Web Vitals — they affect both user experience and search rankings.
What optimization projects typically cost
Performance work is billed at our standard rate of 90–160 PLN net + VAT per hour. A focused optimization sprint — profiling, fixing N+1 queries, adding caching and queues — usually takes 2–5 days and delivers the largest gains. Bigger architecture work is scoped after an audit.
FAQ
Where should I start optimizing a Laravel application?
With measurement. Profile the slowest endpoints, count queries per request and check cache usage. In practice the first fixes are almost always N+1 queries, missing indexes and heavy work that should be queued.
How much faster can a Laravel app get?
It depends on the starting point. Removing N+1 queries and adding caching and queues commonly cuts response times by 50–80%. Applications with structural issues (missing indexes, no caching at all) often improve even more.
Is Redis required for good performance?
Not required, but highly recommended in production. Redis serves as cache, queue driver and session store — offloading the database and enabling Horizon monitoring. For small applications, database cache and queues can be enough.
How do I find N+1 queries?
Enable query logging in development (Telescope or Debugbar) and look for repeated identical queries with different IDs. Laravel also offers Model::preventLazyLoading() in development to fail loudly when a lazy load sneaks in.
How much does performance optimization cost?
A focused sprint is typically 2–5 days at 90–160 PLN net + VAT per hour. Describe your application and its symptoms via the contact form — we will propose a scope and a free estimate.
👉 Need your Laravel app to run faster? Check our Laravel development services or hire a Laravel developer for a performance sprint.
📖 Read more: Laravel application security — OWASP Top 10 and CI/CD automation for Laravel.