Blog
Fewer round trips, faster reads: client-side caching in go-redis
Serve repeated reads from your application's memory
Go and Redis fit together nicely, because Go makes it cheap to handle many concurrent requests, and Redis answers each of them in under a millisecond. This benefits many different use cases across e-commerce, ad-tech and logistics, but only if the low latency is really won for the whole of the application.
As your product page is getting high traffic, hundreds of goroutines might be asking Redis for the same product details. In most workloads, reads are much more common than writes, so the value that Redis responds with rarely changes, yet every request makes the trip to fetch it again.
That trip can take far longer than the actual lookup in Redis, which can process a simple command in less than a microsecond. The network is an order of magnitude slower. Think of a 1 ms round trip between availability zones, or 50 ms between distant regions.
Let’s put that on a human scale: if the lookup took one second, the trip between availability zones would take about 17 minutes, and the trip between regions about 14 hours. Almost all the time your application spends on that read goes to travel, and that is exactly the part that is skipped when you use a local cache.
The obvious fix is to keep the value in the application's own memory. The hard part, as with any cache, is knowing when an entry has gone stale. Since Redis 6, the server has been able to help with this. With server-assisted client-side caching, Redis tracks which keys a client has read and notifies it when one of them changes.
When I started building this for go-redis, I wanted developers to enable the feature, keep using the same commands, and get a more efficient client. The complexity of making that happen would stay inside the library, hidden from the user. It matters to me that developers who rely on go-redis can use new features like this in the client they already know and get faster reads with fewer trips to Redis.
Three ways to build it
Inside the library, there were three reasonable ways to implement this:
- Keep a private cache for each connection
- Keep a private cache per client, shared by every connection in that client's pool, with tracking on each connection
- Keep a private cache per client, but have one dedicated broadcast connection to receive all the invalidations
Going in, I thought broadcast would be the one to go with, since invalidations get their own connection and handling them stays out of the way of the connections that serve commands. The implementation also looked fairly simple, and the first benchmarks backed that up.
The per-connection cache was the weakest of the three, because every connection held its own copy of the data, which meant values were duplicated across the pool and warming one connection did nothing for the others. The cache as a whole took a long time to warm up, and even a hit meant borrowing a connection from the pool.
The per-client cache was slower than broadcast. When I looked at where the time went, I found that reads were waiting on the lock around the shared cache. Inspired by how Redis Cluster partitions its keyspace, I split the cache into shards, each with its own lock and entries. When I ran the benchmarks again, the per-client cache came close to broadcast performance. That was the result that surprised me most.
Up to this point, broadcast had come out ahead in my benchmarks. Then I tried a workload that wrote to keys the application never read. My broadcast prototype subscribed broadly, so it received invalidations for those keys too. As I increased the unrelated writes, the invalidation consumer fell behind and stale reads went up, even while throughput stayed strong. Broadcast supports prefix-based subscriptions, so the cost depends on how broadly you subscribe. I would have missed it if I’d looked at read throughput alone.
I brought the benchmark results back to my team. With the sharded cache now close to broadcast on reads, my team and I chose a cache shared across the pool, with tracking on each connection. That choice kept go-redis aligned with the per-client cache model in the other Redis clients and tied invalidations to keys the application had actually read.
Enable it in a few lines
None of that complexity is visible from the outside, where all you write is this:
That's the whole change: you keep calling the same command APIs, while go-redis uses Redis command metadata to decide which reads are eligible, looking at what each operation does, its arguments, and the keys its response depends on. Common reads such as GET, MGET, HGET, and HGETALL qualify, as do less obvious ones like BF.EXISTS and CMS.QUERY, whereas scripts, blocking commands, explicit pipelines, and transactions take the uncached path.
What happens to a read
- Your application calls
GET product:42, and on a miss go-redis sends the command to Redis. - Redis tracks the key on that connection, and go-redis stores the eligible response locally.
- Repeated reads are served from the local cache, and when any client changes the key, Redis sends an invalidation.
- go-redis removes the affected entry, so the next read fetches the value again.

There is still a window between a value changing in Redis and go-redis receiving and processing the invalidation. A read during that window can return the older value, so CSC doesn’t guarantee immediate consistency. If a tracking connection is lost, go-redis evicts the entries that depend on it, and when the client cannot establish that a cached answer is still covered, it fetches from Redis.
Because the cache is shared across the connection pool, a value read through one connection is a hit for every goroutine, and a hit doesn't borrow a connection at all, while concurrent misses for the same command and arguments share one in-flight fetch.
The numbers
I ran the benchmark against Redis 7.4.4 on an Apple M4 Max over local TCP, using the same go-redis v9.23.0 build with CSC disabled and enabled, 64 concurrent callers, and a workload of 99% GETs and 1% SETs.
| Metric | CSC disabled | CSC enabled |
|---|---|---|
| Read throughput | 150,289 reads/s | 4,909,979 reads/s |
| Median read latency | 418.82 µs | 0.63 µs |
That's 32.7× the read throughput, with about 99% of application GETs never reaching the server. Keep in mind, though, that this workload is nearly ideal for caching, since almost every operation is a read and the 1,000 keys with 128-byte values fit comfortably in the cache.
Where to use it, and how to tune it
Product details, configuration, and reference data are good candidates, because many requests read them between changes, whereas counters that change rapidly and leaderboards that update often are less suitable, because their entries may be invalidated before another reader needs them.
You can bound the cache with MaxEntries, MaxMemoryBytes, or both, with the memory limit working from estimated entry sizes. If you also want an age limit on top of invalidation, you can set MaxStaleness, which is off by default, is separate from Redis key TTL, and doesn't make invalidations synchronous.
Two options change how misses are handled, and both are off by default. ClientSideCacheCoalesceMisses sends concurrent misses over a tracked connection, which reduces competition for pooled connections, while ClientSideCacheRefreshOnInvalidate refetches invalidated entries in the background so that they may already be warm when the next reader arrives, at the price of extra traffic.
With ClusterClient, each node has its own cache, shared across that node's connection pool, and reads follow normal routing before checking the selected node's cache. Capacity limits apply per node, like PoolSize, keeping cache configuration consistent with how go-redis manages each node’s connections. With the same limits on each node, adding nodes increases the total cache budget, so account for that when sizing your application's memory.
If you need finer control, there are opt-in and opt-out tracking modes, a cacheability predicate, and per-call controls, all of which are covered in the CSC documentation.
Try it with your hot keys
Run the complete example, then pick data your application reads repeatedly and compare throughput, latency, and server traffic with caching on and off. I’d love to hear how it goes. If something doesn’t work as expected or you have an idea for making it better, feel free to open a GitHub issue. If your reads get faster, I’d be curious to hear what your workload looks like.
Get started with Redis today
Speak to a Redis expert and learn more about enterprise-grade Redis today.




