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 pageshowhide
explore
- Redis (has its own guide)206 questions
- Core Data Structures42 questions
- Caching with Redis26 questions
- Persistence: RDB & AOF22 questions
- Pub/Sub & Streams21 questions
- Replication & Cluster25 questions
- Transactions & Scripting25 questions
- Eviction & Expiration25 questions
- Internals20 questions
- Memcachedempty
- Amazon ElastiCacheempty
- Redis Enterprise4 questions
- Redis Sentinel5 questions
- RedisInsightempty
- In-Memory Store Concepts251 questions
- The Volatile Tier20 questions
- Keyspace Design21 questions
- Server-Side Value Shapes24 questions
- Expiry Semantics21 questions
- The Memory Ceiling26 questions
- Atomicity & Concurrency21 questions
- Durability Options20 questions
- Spreading the Tier30 questions
- The Access Cost Model21 questions
- Ephemeral State Workloads21 questions
- Operating the Tier26 questions
→ has its own guide
questions
466 · 4 sectionsWalk 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?
basics
~20 sRead 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.
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.
basics
~20 sDeleting 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.
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.
basics
~20 sRedis 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.
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?
basics
~20 sOBJECT 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.
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?
basics
~20 sHSET 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.
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?
basics
~20 sThe 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.
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?
basics
~20 sEach 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.
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?
basics
~20 sKeys, 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.
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?
basics
~20 sThree 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.
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?
basics
~20 sThe 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.
What is Redis Sentinel, and which problems does it solve for a Redis deployment?
basics
~20 sSentinel 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.
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?
basics
~20 sA 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.
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?
basics
~20 sRun 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.
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?
basics
~20 sSentinel 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.
An in-memory store answers a lookup in microseconds, but the caller opens a fresh connection for every call - what does each call pay?
basics
~20 sConnection 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.
A request makes 500 single-key reads, each answered in microseconds, yet takes 300 ms overall — where did the time go?
basics
~20 sAlmost 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.
An in-memory store applies four submitted operations as one uninterleaved group; what does that promise, and what does it not?
basics
~10 sIt 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.
Two callers read one entry holding a quota count, each adds ten, and both write back — what is stored, and what is reported?
basics
~20 sThe 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.
A write presented with the version token read alongside the value is refused - what happened, and what must the caller do next?
basics
~20 sAnother 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.