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)266 questions
- Core Data Structures66 questions
- Caching with Redis26 questions
- Persistence: RDB & AOF22 questions
- Pub/Sub & Streams21 questions
- Replication & Cluster30 questions
- Transactions & Scripting25 questions
- Eviction & Expiration26 questions
- Internals20 questions
- Query Engine6 questions
- Security & Access12 questions
- Operational Tooling12 questions
- Memcachedempty
- Redis Enterprise4 questions
- Redis Insight5 questions
- In-Memory Store Concepts (has its own guide)252 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 Workloads22 questions
- Operating the Tier26 questions
questions
527 · 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.
What is Redis Insight for, and which of its tools do you open to browse keys, run commands, and watch live traffic?
basics
~20 sRedis 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.
In Redis Insight, when do you use the Profiler and when the Slow Log screen, and what does each one do to the server?
basics
~20 sSlow 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.
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?
basics
~10 sDatabase 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.
Your team wants Redis Insight pointed at production Redis: should it be allowed, from where, and with what access?
basics
~20 sDefault 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.
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?
basics
~20 sBulk 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.
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.