Shard your locks: benchmarking 6 Go cache designs – Beyond the Happy Path
A developer benchmarks six Go cache designs, showing that sharded locks with proper tuning outperform single mutex caches under high contention, while cautioning about the impact of shard count and hash distribution on performance.
Background
- The article explores six different Go cache implementations, each using a different locking strategy (from a single global mutex to sharded locks and lock-free designs).
- "Sharding" locks means splitting the lock into multiple independent locks (e.g., one per memory bucket), so concurrent accesses to different keys don't block each other.
- The author, Vladimir Strebkov, is a senior backend engineer at Avito (Russia's largest classifieds platform), writing about performance engineering in Go.
- Go (Golang) is a statically typed, compiled language developed at Google, widely used for backend services due to its concurrency primitives (goroutines, channels, mutexes).
- The "happy path" refers to the ideal, uncontended case; the article focuses on what happens under real-world load where many goroutines fight for the same lock — cache stampedes, lock contention, and memory overhead tradeoffs.