skip to content

Caching / in-memory

You will learn the in-memory tier of a system: Redis and Memcached as the stores themselves, the managed and enterprise offerings built on them, and the high-availability and inspection tooling around them. Interviewers return to this area constantly because caching is the first lever anyone pulls on a latency problem.

on this pageshow

explore

→ has its own guide

questions

466 · 4 sections

Walk through the read path of a cache-aside (lazy-loading) cache built on Redis: which commands run on a hit, which run on a miss, and what exactly gets written back?

level: juniorimportance: must knowfreq 75%
basics
~20 s

Read with GET. Hit: return the cached value. Miss (nil): load from the system of record, serialize it, write it back with a single SET key value EX <ttl>, and return it. Readers fill the cache lazily; a miss is normal, not an error.

open as a page

A record that your service caches in Redis is updated by the write path. Should the write path delete the cache key, overwrite it with a fresh TTL, or overwrite it while keeping the key's remaining time-to-live? Explain how each choice changes the worst-case staleness a reader can see.

level: juniorimportance: must knowfreq 58%
basics
~20 s

Deleting is the safest default: the next reader reloads from the database. Overwriting with a fresh TTL restarts the clock, so a hot key's expiry never fires and a wrong value can live forever. Overwriting while keeping the remaining TTL keeps a hard age bound.

open as a page

In Redis Cluster, how does the system decide which node stores a given key? Walk through the computation from the key string to the node that serves it.

level: juniorimportance: must knowfreq 62%
basics
~20 s

Redis Cluster computes CRC16 of the key modulo 16384, giving a hash slot. Each of the 16384 slots is owned by exactly one master node, so the slot decides the node. Keys are never hashed against node addresses.

open as a page

Running OBJECT ENCODING on a small Redis hash returns "listpack", and on a large one it returns "hashtable". What is that command reporting, and why does Redis keep more than one internal representation for the same data type?

level: juniorimportance: must knowfreq 50%
basics
~20 s

OBJECT ENCODING reports the internal memory layout Redis chose for that value. Small collections use a compact, cache-friendly flat array (listpack/intset) that saves a lot of memory; once they grow past configured thresholds Redis switches to a real hash table or skiplist for O(1)/O(log n) access.

open as a page

How would you store a user profile in a Redis hash, and which commands read a single attribute, several attributes, and the whole object? What happens to the key when you delete its last field?

level: juniorimportance: must knowfreq 68%
basics
~20 s

HSET user:42 name Ada email [email protected] writes fields; HGET reads one, HMGET reads several in one call, HGETALL returns every field and value. HDEL removes fields, and when the last field goes the key itself is deleted — Redis has no empty hashes.

open as a page

Redis Enterprise puts a proxy in front of its shards, while open-source Redis Cluster expects the client to be cluster-aware. What does that proxy layer actually buy you operationally, and what does it cost?

level: middleimportance: should knowfreq 30%
basics
~20 s

The proxy gives clients one stable endpoint: it routes to the right shard, so clients need no slot map or redirect handling, and resharding, failover and scaling happen behind it. The cost is an extra network hop, another component to size and make highly available, plus licensing and a more opaque topology.

open as a page

Redis Enterprise offers active-active geo-replication, where several regions accept writes to the same dataset simultaneously. What mechanism makes concurrent writes converge without a coordinator, and which guarantees do you NOT get from it?

level: seniorimportance: should knowfreq 28%
basics
~20 s

Each region holds a full replica built on conflict-free replicated data types. Writes are applied locally, then replicated asynchronously and merged by per-type rules: counters sum, sets and hashes are add-wins, plain string values resolve last-write-wins. You do not get global linearizability, cross-region atomicity, or loss-free failover.

open as a page

Redis Enterprise can keep part of a dataset on SSD rather than entirely in RAM (marketed as Auto Tiering, previously Redis on Flash). How does that work, what workload does it assume, and why is it not a durability feature?

level: seniorimportance: nice to knowfreq 18%
basics
~20 s

Keys, indexes and hot values stay in RAM while cold values live on local NVMe SSD, fetched on access. It assumes a strongly skewed access pattern, since a miss costs an SSD read instead of a memory read. It is a cost-per-gigabyte optimisation, not persistence — durability still comes from snapshots and replication.

open as a page

Some Redis capabilities are absent from the open-source distribution because of how the system is constructed, not because of how it is packaged — for example accepting writes to the same dataset in more than one region simultaneously, serving cold values from flash instead of RAM, and moving shards between nodes without the connected client observing it. For each of those three, what would you actually have to build to provide it yourself on top of open-source Redis, and which workloads genuinely need none of them?

level: principalimportance: nice to knowfreq 22%
basics
~20 s

Three gaps are structural, not packaging. Multi-master writes need merge rules built into every data type. RAM/flash tiering needs a storage engine under the shard with a promotion policy. Invisible resharding needs a routing layer owning the client connection. Single-region caching needs none of them.

open as a page

In a Redis deployment fronted by Sentinel, how should an application client find the current master's address, and what goes wrong if it just configures the master's IP directly?

level: middleimportance: must knowfreq 45%
basics
~20 s

The client is given the list of Sentinel addresses plus the master's logical name. It asks a Sentinel with SENTINEL get-master-addr-by-name, connects there, and subscribes to the +switch-master event so it drops connections and re-resolves after a failover. A hardcoded master IP keeps pointing at the dead or demoted node.

open as a page

What is Redis Sentinel, and which problems does it solve for a Redis deployment?

level: middleimportance: must knowfreq 60%
basics
~20 s

Sentinel is a separate Redis process that watches a master and its replicas. It detects when the master is down, promotes a replica automatically, reconfigures the other replicas, and tells clients the current master address. Data never flows through it.

open as a page

Walk through how Redis Sentinel detects that a master has failed and promotes a replica. What do the terms SDOWN and ODOWN mean in that flow?

level: seniorimportance: must knowfreq 50%
basics
~20 s

A Sentinel marks the master SDOWN (subjectively down) after it fails to reply for down-after-milliseconds. It asks the other Sentinels; when quorum agree it becomes ODOWN (objectively down). Sentinels then elect a leader by majority, which picks the best replica, sends REPLICAOF NO ONE, and repoints the others.

open as a page

How many Redis Sentinel processes should you deploy, and what is the difference between the configured quorum value and the majority a Sentinel needs to actually perform a failover?

level: seniorimportance: should knowfreq 40%
basics
~20 s

Run an odd number, at least three, on hosts that fail independently. Quorum is how many Sentinels must agree the master is down to declare ODOWN. Performing the failover additionally requires a leader elected by a majority of all Sentinels (N/2+1). Quorum can lower but never bypass that majority.

open as a page

A network partition leaves a Redis master reachable by some application clients but cut off from all Redis Sentinel processes, so Sentinel promotes a replica on the other side. What happens to the writes those clients keep sending to the old master, what actually bounds how long that can go on, and which Sentinel-side settings or hooks (down-after-milliseconds, client-reconfig-script, replica-priority) let an operator observe or shorten that window?

level: seniorimportance: should knowfreq 33%
basics
~20 s

Sentinel never tells the isolated master anything, so it keeps accepting and acking writes from clients that still reach it. Only client re-resolution ends that window, not a server timeout. On rejoin it full-resyncs and those writes are discarded silently.

open as a page

An in-memory store answers a lookup in microseconds, but the caller opens a fresh connection for every call - what does each call pay?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Connection setup, paid before any work begins: at least one network round trip for the handshake, plus further trips where an encrypted transport or a credential exchange is required. Microseconds of server work end up buried under milliseconds of setup.

open as a page

A request makes 500 single-key reads, each answered in microseconds, yet takes 300 ms overall — where did the time go?

level: juniorimportance: must knowfreq 76%
basics
~20 s

Almost all of it went into the network. Each read pays one full crossing, so 500 sequential reads pay 500 crossings. The store's microseconds are far too small to explain the delay; the number of crossings is the cost.

open as a page

An in-memory store applies four submitted operations as one uninterleaved group; what does that promise, and what does it not?

level: juniorimportance: must knowfreq 68%
basics
~10 s

It promises only that no other caller's operation is applied between the four. It is not a database transaction: there is no rollback, so when the third step fails, the first two stay applied.

open as a page

Two callers read one entry holding a quota count, each adds ten, and both write back — what is stored, and what is reported?

level: juniorimportance: must knowfreq 80%
basics
~20 s

The second write lands whole and the first caller's addition is gone. An entry that held 100 holds 110, not 120 — and nothing is reported: both callers were told their write succeeded. That default outcome is last-writer-wins.

open as a page

A write presented with the version token read alongside the value is refused - what happened, and what must the caller do next?

level: juniorimportance: must knowfreq 64%
basics
~20 s

Another caller changed that entry between the read and the write, so the store refused it instead of overwriting. The caller must re-read the entry, recompute the change from the new value, and write with the new token.

open as a page