Is singleflight the right way to prevent a cache stampede in my Go API?
Start with singleflight plus stale-while-revalidate, and add a Redis distributed lock only once per-pod rebuilds measurably hurt Postgres.
Tag
Cache layers, key design and invalidation — the second one being the hard part. questions under this tag, answered directly.
3 answered questions carry this tag.
Start with singleflight plus stale-while-revalidate, and add a Redis distributed lock only once per-pod rebuilds measurably hurt Postgres.
A single-flight lock plus TTL jitter covers most cases; reach for XFetch only when recompute is truly expensive, and add stale-while-revalidate either way.
The moment a price changes, write through to KV or purge the key in the same transaction or outbox; a short TTL and versioned keys are only the safety net.