In Meeting 00:15:42
Meeting
00:15:42
Done
Snapshot H
Solve
Show/Hide B
Hello everyone, thanks for joining today's architecture review.
Can someone explain the current implementation?
When the cache key expires, all concurrent requests fall through to the DB directly.
Right. The singleflight pattern should handle this.
- How to fix cache stampede in Go?
⌥↑ ⌥↓
How to fix cache stampede in Go?
Use the singleflight pattern — only one goroutine executes the fetch while others wait and share the result.
import "golang.org/x/sync/singleflight" var g singleflight.Group func GetData(key string) (string, error) { v, err, _ := g.Do(key, func() (interface{}, error) { return fetchFromDatabase(key) }) return v.(string), err }