Redis

Lua Scripting Interview Questions

Lua Scripting interview questions for Redis — fundamentals through advanced scenarios.

  • 20Questions with answers
  • 3Difficulty levels

Questions (20)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Beginner
Question

What atomicity does EVAL actually give you?

Answer:

Lua EVAL runs atomically on the primary: no other command interleaves until the script returns. That is stronger than MULTI/EXEC with WATCH for read-modify-write on the listed keys. Long scripts still block the whole instance.

Question 2
Interview Beginner
Question

Why does EVALSHA return NOSCRIPT, and what should the client do?

Answer:

EVALSHA sends the SHA1 of a loaded script so the body is not retransmitted. NOSCRIPT means the server does not have that SHA; the client must EVAL the body and retry. Pools that connect to new nodes must handle NOSCRIPT.

Question 3
Interview Beginner
Question

Why do key names belong in KEYS rather than ARGV?

Answer:

KEYS array versus ARGV: Cluster hashing uses KEYS, not ARGV. Putting key names in ARGV to be flexible breaks Cluster and the atomicity contract. Always declare keys in KEYS.

Question 4
Interview Beginner
Question

What does lua-time-limit protect, and what does it not prevent?

Answer:

lua-time-limit, default five seconds, kills a runaway script with an error but the instance was blocked until then. Busy scripts show up as everyone else timing out. Split work or do it in the app.

Question 5
Interview Beginner
Question

When do you SCRIPT LOAD versus sending EVAL every time?

Answer:

SCRIPT LOAD plus EVALSHA is the deploy path; SCRIPT FLUSH on a node creates a NOSCRIPT storm. Do not FLUSH in production casually. SCRIPT EXISTS checks SHAs before a rollout.

Question 6
Interview Beginner
Question

What is the difference between redis.call and redis.pcall?

Answer:

redis.call raises on Redis errors and aborts the script; redis.pcall returns an error value. Uncaught errors still leave the atomic block. Handle WRONGTYPE explicitly when the key might be the wrong structure.

Question 7
Interview Beginner
Question

When should you not use Lua at all?

Answer:

When not to use Lua: multi-key work that spans slots, scripts that call Redis with huge payloads, or logic that belongs in the app for testability. Lua is not a general application server. If you need loops over SCAN of the whole keyspace, stop.

Question 8
Interview Intermediate
Question

How can non-deterministic Lua desync replicas?

Answer:

Non-deterministic Lua using TIME or math.random used to desync replicas when the script body was re-executed. redis.replicate_commands() or writing only deterministic Redis calls is the safe pattern. Prefer redis.call of INCR over computing random in Lua.

Question 9
Interview Intermediate
Question

When is a short Lua script better than a WATCH/MULTI retry loop?

Answer:

WATCH/MULTI versus Lua: WATCH retries on conflict; Lua does not yield, so it cannot deadlock with another Lua, but it can starve others by running long. For a short compare-and-set, Lua is simpler than WATCH loops.

Question 10
Interview Intermediate
Question

How are Lua scripts replicated to replicas?

Answer:

Replication of scripts: replicas either re-execute the script or apply the write commands the script produced, depending on version and replicate_commands. Non-deterministic scripts plus script replication equal split-brain data. Keep scripts as pure Redis writes.

Question 11
Interview Intermediate
Question

Can you EVAL a write script against a replica?

Answer:

EVAL on a replica: replicas reject writes unless you are in an unusual debug story. Read-only Lua that only redis.call GET can still be wrong if it assumes it can SET. Send writes to the master.

Question 12
Interview Intermediate
Question

Why does EVALSHA work on one Cluster shard and fail on the next?

Answer:

Script cache is per node: Cluster means every master you hit needs the SHA. A client that EVALSHA against a new shard gets NOSCRIPT. Frameworks should load on all nodes or fall back to EVAL.

Question 13
Interview Intermediate
Question

How do you debug a Lua script without harming production?

Answer:

Debugging Lua: redis.log, SCRIPT DEBUG, and isolating with redis-cli --eval. Never debug with MONITOR on production while a hot script runs. Unit-test scripts with a throwaway instance.

Question 14
Interview Intermediate
Question

Does pipelining EVALSHA make scripts run concurrently?

Answer:

Lua and pipelining: you can pipeline EVALSHA but each script still runs atomically and serially. Pipelining does not make two scripts concurrent. Giant pipelines of EVALSHA can still spike p99.

Question 15
Interview Advanced
Question

Why are global Lua variables a footgun across SCRIPT LOAD?

Answer:

Global variables in Lua persist in the interpreter across scripts unless you take care—this is a footgun. Use local. Shared globals plus SCRIPT LOAD lead to cross-request contamination.

Question 16
Interview Advanced
Question

Why do Lua scripts that pass standalone tests fail on Cluster?

Answer:

Breaking Cluster rules inside Lua with undocumented tricks will pass on standalone and fail in production Cluster. Test scripts against a real Cluster. Hash tags in KEYS are the supported way to touch two keys.

Question 17
Interview Advanced
Question

Why can Redis Lua not call HTTP APIs, and why is that good?

Answer:

lua sandbox: Redis Lua cannot do OS or network; that is a feature. Needing a JSON HTTP call from Lua means the design is wrong. Keep side effects as Redis writes only.

Question 18
Interview Advanced
Question

What happens if a script uses a Redis 7 command on a Redis 6 node?

Answer:

Version skew: a script that uses Redis 7 commands fails on 6 with a runtime error inside EVAL, rolling back the atomic block. Pin script compatibility. Deploy scripts in the same change as the server upgrade.

Question 19
Interview Advanced
Question

Can Lua remove contention on a single hot INCR key?

Answer:

High contention INCR in Lua around a HASH is still one thread; Lua does not add parallelism. If the hot key is the bottleneck, Lua cannot save you. Shard the counter instead.

Question 20
Interview Advanced
Question

When does SCRIPT KILL refuse to stop a script?

Answer:

SCRIPT KILL only stops a script that has not yet written; after the first write you wait. A stuck write script is why lua-time-limit and short bodies matter. Design for killability.

Practice with AI mock interviews

Run Redis mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required