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

questions

527 · 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

What is Redis Insight for, and which of its tools do you open to browse keys, run commands, and watch live traffic?

level: juniorimportance: should knowfreq 20%
basics
~20 s

Redis Insight is the official Redis GUI. Browser lists and edits keys, Workbench and the CLI pane run commands, Profiler streams live commands, and Slow Log, Database Analysis and Pub/Sub cover slow commands, memory and messages.

open as a page

In Redis Insight, when do you use the Profiler and when the Slow Log screen, and what does each one do to the server?

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

Slow Log lists commands that exceeded a runtime threshold, so open it first. Profiler runs MONITOR on every node and streams all commands, so keep it short. Slow Log's settings and Clear button change shared server state.

open as a page

When you use Redis Insight's Database Analysis to prove which keys hold the memory on a shared staging Redis, what does the report measure and what can it miss?

level: seniorimportance: should knowfreq 14%
basics
~10 s

Database Analysis scans about 10,000 keys per node, reads each one's MEMORY USAGE, and reports by type, namespace, expiry and top keys, extrapolating some totals. It can miss a huge key outside the scan.

open as a page

Your team wants Redis Insight pointed at production Redis: should it be allowed, from where, and with what access?

level: principalimportance: should knowfreq 10%
basics
~20 s

Default to no standing GUI access on production: explore on lower environments or a copy, and grant a narrow ACL user, network path and time window when needed. Redis Insight's tags and confirmations are friction, not control.

open as a page

In Redis Insight's Bulk Actions, what actually runs when you delete keys matching a Browser filter on a live database, and what can go wrong?

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

Bulk Actions scans with your Browser filter, then pipelines one DEL or UNLINK per matched key on each primary, looping without pause until done or stopped. There is no undo, and the expected count is only an estimate.

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