Redis
Redis is eventually consistent model when in cluster. Single instance is strong consistent since it's just 1 node.
Single thread execution
Redis uses one thread to process all the commands. It's single thread for everything
Redis has a single event loop that processes commands one at a time, sequentially. Even if 1000 clients send commands simultaneously, Redis queues them and executes them one after another:
Time →
Instance A sends: XADD stream * field value
Instance B sends: XADD stream * field value
Redis executes:
[A's XADD] → done → [B's XADD] → done
(or B first, then A — depends on who arrived first in the queue)
This is regardless of the key. However redis cluster will be 1 thread per key
Per shard single thread execution (ONLY IN CLUSTER)
See Redis cluster
Single thread does not avoid race condition
A single Redis command (like XADD, DECRBY, GET) is already atomic — it can't be interrupted. The problem is when you need multiple commands as one unit:
# Without Lua — these are 2 separate commands:
tokens = GET rl:user123 # ← Instance B could sneak in here!
if tokens > 0: DECR rl:user123
# With Lua — these run as ONE uninterruptible block:
EVAL "local t = redis.call('GET', KEYS[1])
if tonumber(t) > 0 then redis.call('DECR', KEYS[1]) end
return t"
Without Lua, Instance A does GET (sees 1 token), then Instance B does GET (also sees 1 token), then both do DECR → token goes to -1. Race condition.
With Lua, the entire script is treated as a single command in Redis's queue — nothing else runs until it finishes.