Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

Since Redis 6 the server can help clients keep local copies of keys by telling them when those keys change, a feature called client-side caching or key tracking.

Explain how CLIENT TRACKING works in default mode and in broadcasting mode, and what RESP3 changes about how invalidations reach the client.

With CLIENT TRACKING in default mode, Redis remembers which keys each client has read and sends that client an invalidation message when one of those keys changes or expires, at the cost of server memory for that table. In broadcasting mode Redis remembers nothing per key and instead sends invalidations for every change under the prefixes a client registered. With RESP3 the invalidations arrive as push messages on the same connection; with RESP2 the client needs a second connection subscribed to __redis__:invalidate and links the two with REDIRECT.

Why this question is asked

A local in-memory copy of a Redis value is the fastest read there is, but it raises the old caching question: how do we know when our copy is stale? Since Redis 6, the server can tell us, which is what client-side caching, also called key tracking, is about. Interviewers ask about it because the two modes behave very differently under load, and because the protocol version decides how messages reach the client. In this answer, we will recap the idea, walk through default mode and broadcasting mode, look at the options that fine-tune tracking, and then see what RESP3 changes.

1A Quick Recap of Server-Assisted Client-Side Caching

In client-side caching the application keeps a copy of some Redis values in its own memory, for example in a Map or a Caffeine cache, and answers reads from there. That saves a network round trip on every hit. The hard part is invalidation, the act of throwing away a local copy once the real value has changed.

Without help from the server, we would rely on TTLs and accept stale data, or build our own pub/sub messages. With tracking, the client tells Redis that it keeps local copies, and Redis takes on the job of telling it when to drop one. An invalidation message just carries key names; the client deletes those keys locally and reads them again from Redis next time.

2Default Mode: Redis Remembers What Each Client Read

We switch tracking on per connection. In default mode, every key the client reads from then on is recorded on the server in an invalidation table, a map from key name to the ids of clients that may hold a copy.

Java
CLIENT TRACKING ON -- OK, this connection is now tracked
GET user:42 -- "Ana"; Redis records: user:42 -> [this client]
-- another client runs: SET user:42 "Anna"
-- Redis sends this client: invalidate [user:42], and forgets the entry
GET user:42 -- "Anna"; recorded again
Step throughDefault tracking mode
Client ARedisClient B
CLIENT TRACKING ON
GET user:42
"Ana" (remember A read user:42)
SET user:42 "Anna"
invalidate [user:42]
drop user:42 locally

6 messages in order. Play them, or step through them one at a time.

Redis tracks per key and per client, so only clients that read the key hear about it.

Notice that Redis sends one invalidation and then removes the entry, so the client receives at most one message per key until it reads the key again. An expiry or eviction of the key counts as a modification too. The cost is on the server: the table grows with the number of distinct keys read by tracking clients, and it is capped by tracking-table-max-keys. The benefit is precision: a client only hears about keys it actually cached.

3Broadcasting Mode: Redis Remembers Prefixes Only

In broadcasting mode the client subscribes to key prefixes instead. Redis keeps no per-key record at all. Whenever any key matching a registered prefix changes, every client registered for that prefix receives an invalidation, whether or not it ever read that key.

Text
CLIENT TRACKING ON BCAST PREFIX user: PREFIX flags: -- OK
-- any client runs: SET user:99 "Li"
-- this client receives: invalidate [user:99] (even if it never read user:99)

So the trade is the reverse of default mode: no server memory per key, but more messages, because clients hear about keys they do not hold. It fits a small, well-defined hot dataset, such as feature flags, where most clients hold most keys anyway. It fits badly with a prefix covering millions of frequently written keys.

4Fine-Tuning: OPTIN, OPTOUT and NOLOOP

In default mode we often do not want every read tracked. With CLIENT TRACKING ON OPTIN, reads are not tracked unless the client sends CLIENT CACHING yes immediately before the read, which says that it intends to cache the next key. OPTOUT is the opposite: everything is tracked except reads preceded by CLIENT CACHING no. This keeps the invalidation table to the keys the client really caches.

NOLOOP stops Redis from sending a client invalidations for changes that the same connection made. That saves messages, but it moves a duty to the client: when it writes a key, it must update or drop its own local copy itself, because nobody will tell it.

5What RESP3 Changes

RESP is the Redis serialization protocol, the format of requests and replies on the wire. RESP2, the older version, has no way for the server to send a message the client did not ask for on a normal connection, except in subscriber mode. So with RESP2 the client opens a second connection, subscribes it to the special channel __redis__:invalidate, and enables tracking on the data connection with REDIRECT followed by the second connection's client id. Invalidations then arrive on the second connection as pub/sub messages.

RESP3, which a client negotiates by sending HELLO 3 and which needs Redis 6 or later, adds push messages: out-of-band data the server can send on the same connection at any time. Invalidations then arrive on the data connection itself, so there is one connection and no REDIRECT. RESP3 also adds typed replies such as maps, sets, doubles, booleans and a real null, so HGETALL can come back as a map instead of a flat list, which client libraries use for clearer APIs. The client library must support RESP3; Lettuce has supported it for years, and in Lettuce 6 and later it negotiates RESP3 by default where the server supports it, but check your client and version.

How invalidations reach the client
RESP2RESP3
ConnectionsData connection plus a subscriber connectionOne connection
SetupSUBSCRIBE __redis__:invalidate, then TRACKING ON REDIRECT <id>HELLO 3, then CLIENT TRACKING ON
Message typePub/sub message on the other connectionPush message on the same connection
Ordering riskInvalidation can overtake a replyArrives in order on one stream

6Follow-up questions

What must a client do when its connection drops?

Flush its whole local cache before trusting it again. While the connection was down, Redis may have sent invalidations that never arrived, and after reconnecting the server does not remember the old tracking state for the new connection. So the client empties the cache, reconnects, enables tracking again and refills lazily. With RESP2 the same applies if the invalidation connection drops while the data connection stays up.

Does default mode send an invalidation for every write to a key?

No. After sending one invalidation for a key, Redis removes that client from the key's entry. The client gets another message only after it reads the key again and is re-registered.

Is tracking available in Redis Cluster?

Yes, but tracking is per node: the client must enable it on the connection to each node it reads from, and with RESP2 the redirect connection must be to the same node. Most clients that support client-side caching handle this for you; check your client's documentation.

7Conclusion

In this answer, we saw that CLIENT TRACKING lets Redis tell clients when to drop local copies. Default mode remembers each client's reads in an invalidation table and sends precise messages at the cost of server memory, while broadcasting mode keeps only prefixes and sends more messages. OPTIN, OPTOUT and NOLOOP tune what is tracked. With RESP2 invalidations need a separate subscribed connection and REDIRECT, while RESP3 delivers them as push messages on the same connection and also brings typed replies.

What to say in the interviewAbout 80 seconds aloud

Open with

Client tracking is Redis's support for client-side caching. In default mode, I run CLIENT TRACKING ON, and from then on Redis remembers every key my connection reads in an invalidation table.

Then, if they want more

When one of those keys is modified, expires or is evicted, Redis sends me an invalidation with the key name, I drop my local copy, and Redis forgets the entry until I read the key again. That is precise, but the table costs server memory, which is capped by tracking-table-max-keys.

In broadcasting mode I register prefixes, such as user:, and Redis remembers nothing per key; it sends an invalidation for every change under that prefix to every registered client. That trades server memory for more messages, so it suits small hot datasets.

OPTIN lets me track only reads I mark with CLIENT CACHING yes, OPTOUT the reverse, and NOLOOP suppresses messages about my own writes, so I must update my copy myself. With RESP2, invalidations go to a second connection subscribed to __redis__:invalidate, linked with REDIRECT.

With RESP3, negotiated with HELLO 3, they arrive as push messages on the same connection, and I also get typed replies like maps and a real null.

About this answer

Last updated
13 November 2026
Versions it names
Redis 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain how CLIENT TRACKING works in default mode and in broadcasting mode, and what...": https://scrivio-interview-library.netlify.app/databases/redis-internals/046a2b4a7a/