Part 0 · 2 chapters · ~12 min

Why Redis

In-memory data structures over a network, measured throughput and latency, what makes Redis fast (memory, simple structures, a single command thread and an event loop), what Redis is used for, its licensing history and the Valkey fork, and when not to use it.

1

A data structure server, measured

code
redis-benchmark -q -n 100000 -c 50 -t set,get,incr,lpush,zadd      # measured: ~165k-172k ops/s, p50 0.151 ms
redis-benchmark -q -n 300000 -c 50 -P 16 -t set,get                  # pipelined: 1.32M SET/s, 1.81M GET/s
REDIS, MEASURED
redis-benchmark against Redis 8.6.2 on this machine, 50 clients
SET168,634/sGET172,414/sINCR166,113/sZADD165,017/sSET, pipelined ×161,315,790/sGET, pipelined ×161,807,229/s
swipe the figure sideways, or tap expand for full screen
1/4
one at a time
Without pipelining, each client sends a command and waits for the reply: about 165,000-172,000 operations per second across 50 clients, with a median latency of 0.151 ms. The limit is round trips and system calls, not the data structure.
~170k ops/s, p50 0.151 msround trips are the limit
2

Uses, licensing and limits

common usestructure
cachestrings or hashes with TTLs
sessionshashes with TTLs
rate limitingstrings with INCR and EXPIRE, or Lua token buckets (Backend System Design P2)
job queueslists or streams (BullMQ, Sidekiq, Celery)
leaderboardssorted sets
unique countsHyperLogLog (12 KB for billions of items, ~0.81% error)
pub/sub and eventspub/sub channels or streams

Licensing: Redis moved from BSD to source-available licences in 2024, which led to the Valkey fork under the Linux Foundation (now used by many cloud providers); Redis 8 added AGPL as an option. The commands and protocol remain compatible. When not to use Redis: as the only copy of data you cannot lose, for large values (megabytes), or for complex queries a database does better.