A SaaS client's dashboard was taking 4.2 seconds to render every time a user logged in. The user ...A SaaS client's dashboard was taking 4.2 seconds to render every time a user logged in. The user ...
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
A SaaS client's dashboard was taking 4.2 seconds to render every time a user logged in.
The user base was growing, but user retention was dropping. Users were literally refreshing the browser thinking the app had frozen.
Here is how we diagnosed and fixed the issue in a single afternoon dropping query times from 4,200ms to 85ms:
The Diagnosis (Laravel Debugbar & Telemetry) We ran a query trace on the dashboard endpoint. The culprit? A classic nested Eloquent loop pulling customer transaction metrics. Instead of 1 optimized query, the server was executing 180+ database queries per request (the dreaded N+1 problem).
The Fix: Eager Loading & Database Aggregates
Replaced individual loop queries with Eloquent's with() for eager loading.
Replaced memory-heavy PHP array manipulation ($user->orders->sum()) with native database aggregation using withSum() and withCount().
Strategic Indexing We checked the MySQL execution plan (EXPLAIN) and found the transactions table was running full-table scans across 500,000+ rows because user_id and created_at lacked composite indexing. Added a single composite index: $table->index(['user_id', 'created_at']);
The Result: Database Queries: Reduced from 184 to 3. Page Response Time: Dropped from 4.2s to 85ms. Server Load: CPU usage dropped by 65%.
You rarely need expensive server upgrades or a complete system rewrite to fix a slow application. Most of the time, you just need to fix how your code talks to your database.
How fast is your primary user dashboard loading right now?
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started