Django · Optimization · MySQL

ShopperMart — E-Commerce Platform

Django MySQL ORM Optimization E-Commerce

The Challenge

N+1 query problems causing 3s+ load times on high-traffic product listings during peak shopping events.

The Solution

Optimized ORM calls using select_related and prefetch_related; implemented composite indexing on frequently queried product attributes and categories.

Tech Stack

Full-stack backend built with Django, powered by MySQL for transactional database reliability. Implemented ORM-level caching, pagination, and query profiling to handle scalable product catalog browsing.

Query Optimization Architecture

      graph TD
          Client[Client Catalog Request] -->|1. HTTP GET /products| Router[Django URL Router]
          Router -->|2. Unoptimized: N+1 Loop (3.2s)| LegacyDB[(MySQL DB - 150+ Queries)]
          Router -->|3. Optimized: Joined Query (0.8s)| TunedORM[select_related + prefetch_related]
          TunedORM -->|4. Single Composite B-Tree Query| OptimizedDB[(MySQL B-Tree Indexed DB)]
          OptimizedDB -->|5. Single Batch Payload| Response[Rendered Catalog Response: 0.8s]
      

Key Impact

50% reduction in DB calls; product page load times dropped from 3.2s to 0.8s under heavy traffic simulations.