The Real Fullstack

The Million-Row Problem

The page was instant at launch. A year and a million orders later it takes 150 ms per call. Why?

Ingénieur9 minLaboratoire de performanceDéfi de code
postgresqlsqlredisspring-data-jpa

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Read the (simulated) execution plan and choose indexes so that even an uncached request meets a 20 ms budget, without slowing down writes with indexes nobody uses.Contexte · Objectifs d'apprentissage ▾

Fernway Outfitters, a fictional online shop, shows each customer their 20 latest shipped orders. The query has not changed since launch, but the orders table has grown to a million rows and the p95 latency of the endpoint has followed it. A teammate suggests putting Redis in front of it.

Mission: Read the (simulated) execution plan and choose indexes so that even an uncached request meets a 20 ms budget, without slowing down writes with indexes nobody uses.

Objectifs d'apprentissage

  • Read a query plan: sequential scan, index scan, sort, rows examined.
  • Order composite index columns: equality columns first, then the sort column.
  • Distinguish a cache (mitigation for repeated reads) from fixing the access path.
SimulationSimulé
Account pageOrders APIRedisPostgreSQL
Lancer la simulation
SELECT id, total, status, created_at  FROM orders WHERE customer_id = $1 AND status = 'SHIPPED' ORDER BY created_at DESC LIMIT 20;
CREATE INDEX idx_status   ON orders (status);CREATE INDEX idx_created  ON orders (created_at);CREATE INDEX idx_customer ON orders (customer_id);-- equality columns first, then the ORDER BY column:CREATE INDEX idx_customer_status_created ON orders (customer_id, status, created_at);

Simplification

A tiny cost model with uniform data replaces PostgreSQL's real statistics. Real planners consider correlation, caching of pages, parallel workers and many more paths. Modèle pédagogique — les chiffres illustrent un comportement, ce ne sont pas des benchmarks.

Concepts

Défis liés

Références