Menu

Why `FOR UPDATE SKIP LOCKED` Quietly Took Down Our Database (And `EXPLAIN ANALYZE` Lied to Us the Whole Time)
📰

Why `FOR UPDATE SKIP LOCKED` Quietly Took Down Our Database (And `EXPLAIN ANALYZE` Lied to Us the Whole Time)

DEV Community: backend·Ankit Sood·29 days ago
#xFwc4u4E
#devtobackend#devto#dev#time#query
Long article (1580 words) — no AI summary yet.
Reading 0:00
15s threshold

A story about a 0.143ms query that somehow pinned our Postgres CPU at 98%, and the one formula from queueing theory that finally explained why.

The Symptom

We run a small, boring-sounding microservice: it hands out unique IDs to callers. One endpoint, one job. GET /id?uniqueKey=... → here's your ID, go away.

It should be one of the fastest endpoints in our stack. Grab an available ID from a pool, mark it as taken, return it. Milliseconds, easily.

Except in production, at a perfectly reasonable ~50 requests per second, this is what we were actually seeing:

Average response time: 8–12 seconds.

Worst case: 67 seconds.

Postgres CPU: pinned at ~98%.

For an endpoint that does one SELECT , a tiny bit of logic, and one UPDATE .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.