SQL Load Optimization

Client:

Major E-commerce Platform

Discover How We Reduced Overloaded Queries from 16,685 to 24 in 1.5 Hours
SQL Load Optimization

Introduction

A client approached us with a task: speed up the loading time of a key website page that was experiencing delays of several seconds. An initial audit revealed the root cause — excessive load on the database: opening the page triggered over 16,000 SQL queries.

This load not only impacted performance but also posed a risk of outages under increased traffic. The task was to optimize the system within a tight timeframe without affecting core business logic or disrupting other parts of the website.

Our team performed a targeted optimization of the data loading architecture and achieved a result: just 24 queries instead of 16,685. The entire process took no more than an hour and a half.

System Overview

The project is a multifunctional e-commerce platform built on Laravel 10 using Eloquent ORM, with MySQL as the database. The frontend is based on Blade, with partial use of Vue.js.

The problematic page displays a product catalog. Each item includes images, characteristics, filter parameters, brand info, availability status, and personalized user data (e.g., favorites).

Due to high data interconnectivity and the lack of optimization mechanisms, the number of SQL queries grew exponentially.

The issue was not the volume of data, but how it was retrieved: eager loading was not used, resulting in the N+1 problem, where additional queries are executed for every record to fetch related data.

Challenge: Excessive Number of SQL Queries on a Single Page

With profiling tools enabled (Laravel Debugbar, SQL logging), we identified 16,685 queries being executed during a single page load. Key reasons included:

  • Related entity queries executed inside loops
  • Undefined or unused relationships between models
  • Template logic accessing relationships without preloading

The client also set strict requirements:

  • No changes to business logic or the API
  • The solution must be scalable
  • Full adherence to Laravel best practices, with no “hacky” workarounds like manual data aggregation

Solution: Implementing Eager Loading and Optimizing Models

The optimization was carried out in several key areas:

Architecture overview: templates, controllers, models, and performance bottlenecks

Bottleneck Analysis

All involved models, controller logic, and templates were reviewed to identify performance issues.

Refining Model Relationships

Relationships like hasMany, belongsTo, hasOne, and morphMany were clarified in the models, making table relationships explicit and enabling eager loading.

Optimized data loading: explicit loading and adjustment of database relationships
Data loading optimization and reduction of SQL query count

Eager Loading Implementation

Wherever deferred relationship access was previously used, with() and load() calls were introduced to fetch all necessary data in a single, joined query.

Example:

Product::with(['images', 'brand', 'filters', 'favorites'])->get();

Template and Presentation Logic Optimization

Blade templates were revised: relationship access inside loops was eliminated, rendering logic was simplified, and redundant queries removed.

Blade template optimization: logic simplification, testing, and performance improvement
Number of SQL queries before and after system optimization

Testing and Benchmarking

After implementation, load tests and a second SQL audit were conducted. Result: only 24 queries were executed for a full page load.

Results

Browser window with a telemetry dashboard showing the Request Details page on telemetry.yourdomain.com
SQL queries reduced from 16,685 to 24
Page response time improved by over 5×
Database load stabilized even under peak traffic
Codebase aligned with Laravel best practices and became easier to maintain
The entire optimization process, from task assignment to production deployment, took less than 2 hours
Portfolio

Other projects

VPUT VPUT VPUT is an aggregator for apartment rentals in Bulgaria. Over a dozen people worked on thi... Stooller Stooller Stooller - an automated freight booking service. Trade Bot Trade Bot Trading bot for LocalBitcoins Wineship Wineship WineShip Liquor Store – advanced catalog functionality with over 2,000 bottles of wine. BeFamily BeFamily We developed a family clothing online store, optimizing the catalog, design, and user expe... Ansy Ansy A modern site for selling elite, handmade carpets. Our main goal was to create a user-frie... RiseX RiseX Successful launch of the RiseX cryptocurrency exchange from scratch – in just 7 months. Th... Bolgarskiydom Bolgarskiydom Bolgarskiy Dom is an aggregator for apartment sales in Bulgaria. Over 10 of our people wor... Neweurofences Neweurofences Neweurofences.com is an online store specializing in metal fences and gates. It operates i... Tetri’s Smile Tetri’s Smile Webdelo recently worked with a brand new dental office in a highly competitive market. We... SoleaWellness SoleaWellness Solea Wellness is a beauty and health salon in Miami offering rejuvenation treatments. The... Solea Beauty Salon Solea Beauty Salon 🔹 As a salon in Miami increased applications by 3 times and organic traffic by 250% 🔹 Fr... Online Optical Store Online Optical Store Case study of the development and promotion of an online optical store. Over 10 people wor... Promotion and Development for SvetlanaDental.com Promotion and Development for SvetlanaDental.com Our case study of Svetlanadental.com explores Webdelo’s work in the promotion and website... Promoting and Developing Holistic Dentistry – A Case Study Promoting and Developing Holistic Dentistry – A Case Study Advanced Dental Wellness Center is a dental office in Miami, Fort Lauderdale. ADW offers h... MyMoneyArt Promotion and Development Case MyMoneyArt Promotion and Development Case Migrated MyMoneyArt to WordPress, optimized SEO & UX: +500% traffic, 6× more leads. Case Study of Webdelo’s Development and Promotion of Biomilk.ru Case Study of Webdelo’s Development and Promotion of Biomilk.ru Biomilk is a food distributor in Moscow and the regions. +100% organic traffic in 3 months... Sutton Advanced Cosmetic Dentistry Sutton Advanced Cosmetic Dentistry Promotion of VIP Dentistry in Manhattan, New York City From 13 to 80 Queries in Google’s... Case Study of Webdelo’s Work with Mates China - A Marketing Agency Case Study of Webdelo’s Work with Mates China - A Marketing Agency Mates China is a digital marketing agency that helps businesses promote their products in... VPUT VPUT How We Built a Vacation Rental Service in Bulgaria and Reached 1,500 Seasonal Bookings – F... Stooler Stooler Online service with automatic price calculation and +40% orders right after launch.
Solea Dental Spa Solea Dental Spa A dental clinic located in Sunny Isles Beach tripled its number of patient inquiries throu... Webdelo SEO Webdelo SEO Explore our SEO approach — from analysis and audits to content, links, and ads. See how we... Case Study: Developing the Nevapallete.cn Paint Store Case Study: Developing the Nevapallete.cn Paint Store We built Nevapallete.cn for China: Hong Kong hosting, Chinese domain, fast loading across... WineShip WineShip A wine catalog with 2000+ bottles, smart filters, and selection by volume and vintage. Sea... How We Promoted Annazur Beauty Salon in Jacksonville, Florida How We Promoted Annazur Beauty Salon in Jacksonville, Florida Comprehensive SEO for Annazur beauty salon in Florida: traffic growth, local rankings, sit... Dental SEO Case Study: Novaya Orbita Dental Practice Dental SEO Case Study: Novaya Orbita Dental Practice Dental clinic SEO case: 50-80 target calls/month, top search rankings, and traffic growth... Berger 3D Design Berger 3D Design WordPress showcase website with catalog for German B2B- storage systems for measuring equi... Solea Brickell Spa Solea Brickell Spa Do you want your website to do more than just exist? Most likely; you want to bring real p... KidsJumpTech KidsJumpTech From a Website on the Brink of Collapse to 40 Leads in a Weekend Alanta Clinic Alanta Clinic Discover how Webdelo helped a dental clinic with a small, one-page website double its loca... Optimizing Automated Deal Matching Optimizing Automated Deal Matching Reducing Load and Increasing Transaction Reliability Brand Synonym Search Brand Synonym Search How We Boosted Performance and Reduced System Load for Inquiries in Russian Digital Marketing for Dental Clinics Digital Marketing for Dental Clinics Digital marketing for dental clinics: SEO, Google Maps, and targeted ads. Over 15 years of... Optimizing Bookings for a Skydiving Experience Optimizing Bookings for a Skydiving Experience Discover how we moved 5 business locations from Excel to a unified system. How We Scaled a Complex EdTech Platform How We Scaled a Complex EdTech Platform Refinement and development of the educational portal. Redesign and Migration of a Dental Supply Online Store Redesign and Migration of a Dental Supply Online Store We transformed the dental supply store with a faster platform, real-time city-based invent... We set up an ad-matching service – saving 72% of time on changes We set up an ad-matching service – saving 72% of time on changes Optimization of automatic ad matching. Webdelo Dev Webdelo Dev Full-cycle development: from detailed technical planning and API architecture to launch an... Bonadomus Bonadomus BONADOMUS is a purpose-built digital platform for Dubai real estate. Created from the grou... Lackmann GmbH Lackmann GmbH Development of a multilingual landing page for the Lackmann Fleisch- und Feinkostfabrik Gm... An internal ERP for running a team An internal ERP for running a team For a company of thirty people, an internal ERP gives HR and finance back two to four full...
cookies We use Cookies

We use cookies to improve website performance, personalize content, and analyze traffic. You can choose which categories of cookies to allow. For more information, please see our Cookie Policy. You can change your preferences at any time.

Essential (Required)

Ensure the website functions properly (navigation, access to secure areas). Always enabled and can only be changed in your browser settings.

Analytics

Help us understand how you use the website so we can improve our services. Do not collect personal data. We use several analytics tools for this purpose.

Advertising

Used to deliver personalized ads and measure the effectiveness of advertising campaigns.