Request coalescing with Go singleflight 0 ▲ Redowan's Reflections 151 days ago · 12 min read2375 words · Tech · hide · Fediverse post 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… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town