Query optimization: 5 real scaling case studies
5 of the 94 engineering write-ups in our database are tagged with the technique "query optimization". They come from 5 companies (Axiom, Datadog, GitLab, OpenAI and Shopify) and were published between 2021 and 2026. Stack that shows up most often in these stories: PostgreSQL (3). Often combined with connection pooling (2) and read replicas (2). 4 of the 5 state concrete scale numbers, for example "$5.1 million sales/minute (Black Friday 2025 peak)" (Shopify). Each card below links to our short summary and the original post.
We replaced Redis with MySQL for inventory reservations—and it scaled
Shopify moved checkout inventory reservations from Redis to MySQL using one row per sellable unit, a bounded pool of 1,000 rows per item/location and SELECT ... FOR UPDATE SKIP LOCKED. The real ceiling was connections held by other checkout code: tagging SQL by business process and measuring hold time in ProxySQL found it, and the cleanup removed 50% of reads and 33% of transactions on the primary.
When upserts don't update but still write: Debugging Postgres performance at scale
Datadog tracks last-seen time for millions of ephemeral hosts so inactive ones can be deleted after 7 days. An ON CONFLICT DO UPDATE upsert meant to touch each host at most once a day still locked the conflicting row and wrote Heap LOCK plus COMMIT WAL records even when the WHERE clause skipped the update—at 500 upserts/sec that roughly doubled write IOPS and quadrupled WAL syncs, and at 25,000/sec it would overwhelm a single writer. Using pg_walinspect and a debugger on heap_lock_tuple, they replaced it with an ON CONFLICT DO NOTHING CTE plus a conditional UPDATE that generates no WAL on true no-ops, keeps HOT updates when a day has passed, and preserves correctness for coarse host tracking.
Scaling PostgreSQL to power 800 million ChatGPT users
OpenAI runs ChatGPT on a single-primary Postgres with nearly 50 global read replicas. Reads are offloaded, write-heavy shardable workloads move to Cosmos DB, and PgBouncer, cache leasing and multi-layer rate limits keep the primary safe.
Haydex: From Zero to 178,600,000,000 rows a second in 30 days
Axiom turned a failed filter-index prototype into a production system for its event store, letting queries skip data and scan 178.6B rows per second.
Why we spent the last month eliminating PostgreSQL subtransactions
GitLab traced replica stalls to Postgres subtransaction overflow and removed subtransactions from its code.