Redis became infrastructure because the mental model fit in a sentence: a process that reads a command, mutates an in-memory structure, and writes a reply, one command at a time. That single-threaded event loop (for command execution) made INCR and LPUSH atomic without locks, made latency distributions understandable, and made the source code approachable. It also meant one slow command stalls everyone else on that instance. The design is not "Redis cannot use more than one core." It is "the core that executes the data model does not interleave two commands."

Atomicity without a lock manager

If two clients issue INCR, they do not race inside a hash table because they never run together. Pipelines and Lua scripts extend the same idea: a Lua script runs to completion. That is why Redis is a good rate limiter and a bad place to run KEYS * in production. The event loop is also why expiry, eviction, and persistence (fork for RDB, AOF rewrite) have to be designed not to stall the loop for too long. Copy-on-write after fork can still cause memory and latency incidents when the dataset is huge and dirty.

Later Redis versions added I/O threads for reading/writing sockets, and modules, and (in some distributions) more parallelism around specific work. Command execution remaining serialized is still the compatibility contract for the data structures people rely on.

Data structures are the API

Lists, streams, sorted sets, hashes: they are in-memory algorithms with Redis protocol on top. Big O is user-visible. HGETALL on a million-field hash is a latency event. Cluster mode shards by key slot so you can use more cores by using more processes. That is horizontal scale of the same single-threaded idea, plus the hash-slot tax (multi-key operations need the same slot).

Persistence and replication are where the simple loop meets disks and networks. A blocked fsync policy is a latency policy. "I wanted a cache" plus "AOF every byte" is a contradiction you will meet at 3 a.m.

Failure modes of a single-threaded store

The concrete failure is a SORT or a huge SMEMBERS from a debug session that pauses a 20 GB cache used as a session store. Mid-size steal: rename-command for dangerous ops, timeouts, and Redis as a fleet of small instances rather than one heroic box.

Operational gotcha: using Redis as a primary database with objects larger than your p99 budget. Another is hot keys: clustering does not help if everyone hits the same slot. Replicate that key or break it up. Fork-based BGSAVE on a memory-saturated host OOMs. Know your overcommit settings. Lua scripts that call time and then sleep are still occupying the loop if you wait inside them — don't. If you enable I/O threads and then run CPU-heavy commands, you will believe you "scaled Redis" and you have not. Measure command stats (latency history, slowlog). Steal the atomicity idea for your own in-process caches: a single writer can be faster than a locked skip list. Do not steal KEYS. Use SCAN. When Redis is used for distributed locks, remember the loop does not make your lock safe across a pause or a partitioned replica; the Redlock debate exists because single-threaded is not a consensus algorithm.

What you can borrow

  • Serialize mutation of an in-memory structure when it buys simpler atomicity than locks.
  • Treat command complexity as part of the public API; ban unbounded reads.
  • Scale with many small single-threaded instances and a shard key, not one giant loop.
  • Watch slowlog and hot slots; clustering will not save a single hot key.