1 hour ago · 12 min read2375 words · Tech · hide · 0 comments

Say you put a cache in front of Postgres to speed up reads. A hot key expires: the next request misses the cache, so it queries Postgres to refill the key the key is popular, so while that first query runs, a hundred more pile in for it they all miss too, and each fires its own query Postgres ends up running a hundred identical queries at once, all for the same value sequenceDiagram participant U1 as User 1 participant UN as User N participant App as Application participant DB as Database U1->>App: Get Product 123 UN->>App: Get Product 123 App->>DB: SELECT * FROM products WHERE id=123 App->>DB: SELECT * FROM products WHERE id=123 DB-->>App: Product data DB-->>App: Product data App-->>U1: Product data App-->>UN: Product data Note over App,DB: N identical queries! That’s a thundering herd , or a cache stampede . Every request wants the same value, yet each one still fires its own query. It’s wasted work, and it pounds your database for nothing. Request coalescing aims to fix that. I’ve…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.