Java Backend Interview Q&A← All stacks

Redis — Interview Q&A Matrix

Parent stack: Persistence & Caching Technology: Redis Levels: Junior · Senior · Architect Questions: 4

Each entry contains a Question, the Expected Depth, an Ideal Answer, and Red Flags.

Junior

Q1 — Redis basics and core data types

Question: What is Redis, why is it fast, and which data types would you use for a session store and a leaderboard?

Expected Depth:

Ideal Answer:

bash
MULTI
HSET session:abc userId 42 role CUSTOMER
EXPIRE session:abc 1800
EXEC

ZADD leaderboard 1500 "player:42"
ZREVRANGE leaderboard 0 9 WITHSCORES

Red Flags:


Senior

Q2 — Cache-Aside pattern and invalidation pitfalls

Question: Implement caching for a read-heavy product endpoint with Redis. Which pattern do you use, and how do you avoid stale data and stampedes?

Expected Depth:

Ideal Answer:

java
Product get(long id) {
    String key = "product:" + id;
    Product cached = redis.get(key);
  if (cached != null) {
    return cached;
  }

  Product product = repo.findById(id).orElseThrow();
  Duration ttl = Duration.ofMinutes(10)
      .plusSeconds(ThreadLocalRandom.current().nextLong(60));
  redis.set(key, product, ttl);
  return product;
}

Red Flags:


Q3 — Redis persistence, atomicity, and distributed locks

Question: Explain RDB vs AOF persistence, how to do atomic multi-step operations, and the caveats of a Redis distributed lock.

Expected Depth:

Ideal Answer:

lua
local available = tonumber(redis.call('GET', KEYS[1]) or '0')
local requested = tonumber(ARGV[1])

if available < requested then
    return -1
end

return redis.call('DECRBY', KEYS[1], requested)
bash
SET lock:invoice:42 8f4c... NX PX 30000
lua
if redis.call('GET', KEYS[1]) == ARGV[1] then
    return redis.call('DEL', KEYS[1])
end
return 0

Red Flags:


Architect

Q4 — Distributed cache consistency models

Question: Compare Cache-Aside, Write-Through, and Write-Behind for a distributed cache, and how do you keep caches coherent across many app instances?

Expected Depth:

Ideal Answer:

text
Database commit -> durable change event -> evict shared and local cache entries

Red Flags:


Scoring Rubric

Level Pass bar
JuniorSelects Redis data types and expiration rules correctly.
SeniorDesigns cache and atomic-operation behavior for races and failures.
ArchitectDefines explicit consistency, durability, invalidation, and recovery policies.