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:

1

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.

2
3

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.

4
5

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
query
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

Other projects

VPUT
VPUT

VPUT is an aggregator for apartment rentals in Bulgaria. Over a dozen people worked on this project, with an overall investment of 300,000 euros. This rental property database currently features 2,200 units.

Web Development, Web Design, SEO
Stooller
Stooller

Stooller - an automated freight booking service.

Web Development
Trade Bot
Trade Bot

Trading bot for LocalBitcoins

Web Development, Web Design, SEO
Wineship
Wineship

WineShip Liquor Store – advanced catalog functionality with over 2,000 bottles of wine.

Web Development, Web Design
Ansy
Ansy

A modern site for selling elite, handmade carpets. Our main goal was to create a user-friendly, trustworthy website.

Web Development, Web Design, SEO
RiseX
RiseX

Successful launch of the RiseX cryptocurrency exchange from scratch – in just 7 months. The project involved 5+ people.

Web Development, Web Design, SEO, Digital marketing
BolgarskiyDom
BolgarskiyDom

Bolgarskiy Dom is an aggregator for apartment sales in Bulgaria. Over 10 of our people worked on launching this project, creating a database of 5,000 apartments (as of 2024).

Web Development, Web Design, SEO, Digital marketing
Neweurofences
Neweurofences

Neweurofences.com is an online store specializing in metal fences and gates. It operates in the USA, with delivery available to other countries.

Web Development, Web Design, SEO
Tetri’s Smile
Tetri’s Smile

Webdelo recently worked with a brand new dental office in a highly competitive market. We started with a limited budget, and this was one of our first projects in the USA. Read more to learn how we approached this project.

SEO, Web Development, Digital marketing
SoleaWellness
SoleaWellness

Solea Wellness is a beauty and health salon in Miami offering rejuvenation treatments. The client came to us with the request to increase the website's visibility in search results and attract new customers. The project started with zero rankings, which required a comprehensive approach to promotion and development.

Web Development, SEO
Solea Beauty Salon
Solea Beauty Salon

🔹 As a salon in Miami increased applications by 3 times and organic traffic by 250%
🔹 From 0 to 180+ requests in TOP-3: real business growth case

Web Development, SEO
Online Optical Store
Online Optical Store

Case study of the development and promotion of an online optical store. Over 10 people worked on this project, creating a catalog with over 10,000 individual items.

Web Development, Web Design, SEO
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 development of a dental office located in south Florida, USA. This establishment is owned by a doctor with extensive experience in her field, and numerous awards.

SEO, Digital marketing
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 holistic dentistry with a unique approach to treatment.

SEO
MyMoneyArt Promotion and Development Case
MyMoneyArt Promotion and Development Case

Migrated MyMoneyArt to WordPress, optimized SEO & UX: +500% traffic, 6× more leads.

SEO
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, 200 keywords in the top 10 of Yandex and Google.

Web Design, SEO, Digital marketing
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 Top 10 in Six Months

SEO
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 China through local social networks and marketplaces, including: WeChat, Weibo, Baidu, Douyin, LRB, and others. We helped their team increase traffic by 12 times over a period of 7 months.

Web Development, Web Design, SEO
VPUT
VPUT

How We Built a Vacation Rental Service in Bulgaria and Reached 1,500 Seasonal Bookings – From Idea to Full-Scale Product with SEO and Marketing

Web Development, Web Design, SEO, Digital marketing
Stooler
Stooler

Online service with automatic price calculation and +40% orders right after launch.

Web Development, Web Design
Solea Dental Spa
Solea Dental Spa

A dental clinic located in Sunny Isles Beach tripled its number of patient inquiries through search engine traffic and digital marketing. We started promoting the website from scratch, right after the clinic launched.

SEO
Webdelo SEO
Webdelo SEO

Explore our SEO approach — from analysis and audits to content, links, and ads. See how we drive businesses to the top of search results.

SEO, Digital marketing
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 regions, and a timely launch.

Web Development
WineShip
WineShip

A wine catalog with 2000+ bottles, smart filters, and selection by volume and vintage. Seamless UX and internal linking for better SEO.

Web Development, Web Design, Custom Web App Development
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, site optimization, and increased service bookings.

SEO
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 since Feb 2023 from content and tech improvements.

SEO
Berger 3D Design
Berger 3D Design

WordPress showcase website with catalog for German B2B- storage systems for measuring equipment. User-friendly catalog, shipping calculation, VAT validation.

Web Design, SEO, Digital marketing
Solea Brickell Spa
Solea Brickell Spa

Do you want your website to do more than just exist? Most likely; you want to bring real people to your website and attract customers to your business. At Webdelo, we know how to make that happen. The SoleaBrickellSpa case study is clear proof of our expertise and effective approach.

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 local patient traffic.

SEO