Quick revision
The short answer
Replicas lag the primary, so only reads that tolerate slight staleness can move: product details, reference data, display counters and leaderboards. Carts, anything that needs read-your-writes, and reads that decide a write (check stock, then reserve) stay on the primary. In Spring Boot, ReadFrom.REPLICA_PREFERRED applies to a whole connection factory, so we create one factory and template for replica reads and keep a primary one for the rest, then verify with CPU, per-node command counts and a staleness probe.
What to remember
In this answer, we saw that replicas lag the primary, sometimes by seconds, so only staleness-tolerant reads such as product details, reference data, counters and leaderboards should move, while carts, read-your-writes reads and check-then-write logic stay on the primary. We configured two Lettuce connection factories with UPSTREAM and REPLICA_PREFERRED instead of one global setting, watched replica behaviour with stale data and LOADING errors, and verified the change with CPU, commandstats and a staleness probe.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Replicas lag the primary, so only reads that tolerate slight staleness can move: product details, reference data, display counters and leaderboards. Carts, anything that needs read-your-writes, and reads that decide a write (check stock, then reserve) stay on the primary. In Spring Boot, ReadFrom.REPLICA_PREFERRED applies to a whole connection factory, so we create one factory and template for replica reads and keep a primary one for the rest, then verify with CPU, per-node command counts and a staleness probe.
Why this question is asked
Sending reads to replicas looks like free capacity: two replicas sit mostly idle while the primary runs at 80 percent CPU. But replicas are copies that trail the primary, and a user who adds a cart item and then sees an empty cart will not care that the system was technically eventually consistent. Interviewers ask this question to see whether we can sort reads by their consistency needs, configure Lettuce precisely, and prove the change worked. In this answer, we will recap replica lag, sort the reads, configure two connection factories in Spring Boot, look at replica behaviour during trouble, and verify the result.
1A Quick Recap: Replicas Trail the Primary
Redis replication is asynchronous. The primary replies to the client and then sends the write to its replicas, so every replica is a little behind. On a healthy network that is a few milliseconds. During a full sync, a network problem or a burst of large writes, it can be seconds or minutes.
So a read from a replica returns a value that was true a moment ago. For some data that is irrelevant; for some it is a bug. The question is never whether replicas are stale, but whether each read can tolerate it.
2Sorting the Reads
Two kinds of reads must stay on the primary. The first needs read-your-writes: the user just changed something and expects to see it. A cart is the classic case. The user adds an item, the page reloads, and a replica 20 ms behind returns the cart without it. The second kind reads a value and then decides a write based on it, such as checking stock before reserving. A stale stock value can approve a reservation that the primary would have refused, so both the check and the write belong on the primary, ideally in one atomic Lua script.
Good candidates for replicas are reads where slight staleness changes nothing a user can notice: product descriptions and prices that change a few times a day, reference data such as categories or country lists, display counters such as 1,240 people viewed this, and leaderboards.
| Read | Stale for 1 s acceptable? | Route |
|---|---|---|
| Product details, images | yes | replica |
| Categories, reference data | yes | replica |
| View counters, leaderboards | yes | replica |
| Cart after the user changed it | no, read-your-writes | primary |
| Stock check before reserving | no, decides a write | primary (Lua script) |
| Stock shown on a listing page | usually yes | replica |
3Configuring Two Connection Factories in Spring Boot
The simplest switch is a LettuceClientConfigurationBuilderCustomizer that calls readFrom(ReadFrom.REPLICA_PREFERRED). But it applies to the one connection factory Spring Boot creates, so every RedisTemplate, including the cart code, would read from replicas. Instead we define two factories over the same Sentinel setup, one reading from the primary and one from replicas, and a template for each.
Because we declared our own factories, Spring Boot's auto-configured one backs off, and the @Primary factory is what the default templates and the cache manager use. That is the safe default: anything not explicitly moved still reads from the primary. Only code that injects catalogTemplate reads from replicas, so moving a read is a visible, reviewable change. REPLICA_PREFERRED falls back to the primary when no replica is available; ReadFrom.REPLICA would fail instead.
4How Replicas Behave When Things Go Wrong
Two replica behaviours surprise people. With replica-serve-stale-data yes, the default, a replica that has lost its connection to the primary keeps answering reads with whatever data it has, which may be minutes old. And a replica that is loading a snapshot during a full sync answers with LOADING errors until it finishes. So replica reads need the same care as any dependency: watch master_link_status, master_last_io_seconds_ago and the offset difference per replica, and alert when a replica falls behind.
Lettuce also keeps sending reads to a replica it knows about until the topology refresh or the Sentinel tells it otherwise, so a replica in trouble can serve stale data for a while. Setting replica-serve-stale-data no makes such a replica return errors instead, which Lettuce can route around; whether that is better depends on whether stale catalogue data or a brief error hurts more.
5Verifying the Split
After the change, three numbers should move. Primary CPU should drop roughly in proportion to the read share we moved. INFO commandstats on each node should show GET and HGET calls appearing on the replicas. And staleness should be measured, not assumed: a small job writes a version key on the primary every second and reads it back from each replica, recording the difference.
If the primary's load is mostly writes, or a handful of hot keys, replicas will not help much, and the real answer is sharding with Redis Cluster or reducing the hot keys. The commandstats numbers show which case we are in before we spend effort on read routing.
6Follow-up questions
What does ReadFrom.LOWEST_LATENCY change in a multi-zone setup?
It sends each read to the node with the lowest measured latency, which may be the primary or any replica. In a multi-zone setup that usually means the node in the client's own zone, which saves cross-zone latency and transfer cost. But it means the same client may read from the primary one moment and a replica the next, so staleness varies from read to read, which is fine only for reads that tolerate it.
Could we keep carts on replicas by waiting for replication after writes?
WAIT 1 50 after the cart write would block until one replica acknowledged it, but with two replicas the next read may hit the other one, and WAIT adds latency to every write. Keeping cart reads on the primary is simpler and correct.
Would client-side caching help the primary instead?
Yes, for hot, rarely changing keys. With Redis client-side caching the server tracks which keys a client cached and tells it when they change, so repeated reads never leave the JVM. It complements replicas for very hot keys.
7Conclusion
In this answer, we saw that replicas lag the primary, sometimes by seconds, so only staleness-tolerant reads such as product details, reference data, counters and leaderboards should move, while carts, read-your-writes reads and check-then-write logic stay on the primary. We configured two Lettuce connection factories with UPSTREAM and REPLICA_PREFERRED instead of one global setting, watched replica behaviour with stale data and LOADING errors, and verified the change with CPU, commandstats and a staleness probe.
Open with
Replicas are asynchronous copies, so they lag the primary by a few milliseconds normally and by much more during full syncs or network trouble. That rules out two kinds of reads: anything where the user expects to see their own write, like the cart right after adding an item, and anything that reads a value and decides a write on it, like checking stock before reserving, which I would keep on the primary in one Lua script.
Then, if they want more
Reads that tolerate slight staleness move: product details, reference data, view counters and leaderboards.
In Spring Boot, a customizer setting readFrom REPLICA_PREFERRED would change the single connection factory for everything, including carts, so I would define two Lettuce connection factories over the same Sentinel setup, a primary one with ReadFrom UPSTREAM marked as the default, and a replica one with REPLICA_PREFERRED behind its own template that only catalogue code uses.
I would also watch replica health, because with replica-serve-stale-data yes a replica that lost its primary keeps serving old data, and a loading replica returns LOADING errors, so I alert on master_link_status and lag.
Then I verify: primary CPU should drop, commandstats should show reads on replicas, and a probe that writes a version key and reads it back from replicas measures real staleness. If the load is mostly writes or a few hot keys, replicas will not help and sharding will.
About this answer
- Last updated
- 13 November 2026
- 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 "Which reads can safely move to replicas, which cannot, and how do you configure and...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/5169e4fff3/