How We Handle 10,000+ Product Queries with Django + PostgreSQL Without Breaking a Sweat

작성자

카테고리:

← 피드로
DEV Community · mobin mollapor · 2026-10-01 개발(SW)

mobin mollapor

`—
title: “How We Handle 10,000+ Product Queries with Django + PostgreSQL Without Breaking a Sweat”
published: false
description: “A practical look at how we optimized a high-traffic e-commerce backend for a car parts store using Django, PostgreSQL, and Redis.”

tags: django, postgres, performance, ecommerce

Running an e-commerce platform for car parts is not like running a normal online store.

Car parts have hundreds of attributes: make, model, year, engine type, trim level, and more. A single product can fit 50 different car models. And when you have 10,000+ products, a simple search query can bring your database to its knees.

We learned this the hard way while building DrNitro, an online store for car headlights and electrical parts. Here’s what we learned about scaling a Django + PostgreSQL backend for a high-traffic e-commerce site.

The Problem: Too Many Joins, Too Slow

Our initial schema looked logical:

  • Product → has many ProductFitment (which car models it fits)
  • Product → has many ProductAttribute (lumens, color temp, base type)
  • Product → has many ProductImage

A simple query like “find all H7 LED headlights that fit a 2015 Toyota Camry” required:

sql
SELECT p.* FROM product p
JOIN product_fitment pf ON pf.product_id = p.id
JOIN car_model cm ON cm.id = pf.car_model_id
JOIN product_attribute pa ON pa.product_id = p.id
WHERE cm.make = 'Toyota'
AND cm.model = 'Camry'
AND cm.year = 2015
AND pa.name = 'base_type'
AND pa.value = 'H7'

원문에서 계속 ↗