Command Palette

Search for a command to run...

Hectal
PHASE 0Beginner ~17 min· topic 1 of 5

Topic 0.1

What Redis Is (and What It Isn't)

In one line

Redis is an in-memory data structure server: you send it small commands over TCP, and it runs them against strings, hashes, lists, sets, sorted sets, streams and more, one at a time. It can play many roles, but each role comes with different durability and consistency guarantees.

0/5 · 0%

Think of it like this

A restaurant's pass, the counter between the kitchen and the dining room. Orders sit there for seconds, not years. It's small, very fast to reach, and one person manages it so nothing is double-served. The pantry in the back (your database) holds everything permanently but is slower to reach. Redis is the pass: the fast shared surface every waiter can reach, not the pantry.

Key ideas

  1. 01

    Redis keeps the whole dataset in RAM and exposes it as a key → value map where the value is a typed data structure: String, Hash, List, Set, Sorted Set, Stream, Bitmap (a view on strings), HyperLogLog, Geo (a view on sorted sets), and in Redis 8 also JSON, time series, probabilistic filters and vector sets. The command you call decides the algorithm: ZADD inserts into a skiplist, LPUSH into a linked list of compact nodes.

  2. 02

    Because the data structures live on the server, you move the computation to the data instead of reading a blob, changing it in your app and writing it back. INCR views is one round trip and atomic; "GET, add one, SET" is three steps and racy. That single idea explains most of Redis's power.

  3. 03

    Redis plays many roles: cache, session store, rate limiter, counter store, leaderboard, lightweight queue, pub/sub bus, event stream, coordination point (locks, leader election), and sometimes a primary database. Each role has a different answer to "what happens when Redis restarts or fails over?" A cache can lose everything; a rate limiter can briefly fail open; a payment ledger must never live only in Redis.

  4. 04

    Redis is not a replacement for a relational database. It has no joins, no secondary indexes on plain keys (the Query Engine adds them, see Topic 4.5), no multi-key transactions across shards, bounded durability (asynchronous replication, fsync once a second by default), and a dataset limited by RAM, which costs about 10–30× more per GB than disk.

  5. 05

    Today "Redis" is a family. Redis Open Source (by Redis Ltd.) moved from the BSD licence to RSALv2/SSPLv1 in 2024 and added AGPLv3 as an option with Redis 8 in 2025. Valkey is the Linux Foundation fork of Redis 7.2.4 under BSD, adopted by AWS, Google Cloud and most Linux distributions. The commands in this course work on both unless a topic says otherwise.

  6. 06

    The interview mindset this course trains: never say "use Redis" on its own. Say which primitive, why it's atomic, what happens under concurrency, what it costs in memory, how it scales, and what breaks when Redis is slow or gone.

Code & diagrams

redis-roles.mermaiddiagram

The same server, many roles. Each role needs its own answer to "what if Redis restarts?"

Rendering diagram…
first-look.redisredis

The same server holds different data types. The command decides the structure.

127.0.0.1:6379> SET greeting "hello"
OK
127.0.0.1:6379> INCR page:home:views
(integer) 1
127.0.0.1:6379> HSET user:42 name "Asha" plan "pro"
(integer) 2
127.0.0.1:6379> ZADD leaderboard 1200 "asha" 950 "ravi"
(integer) 2
127.0.0.1:6379> TYPE user:42
hash
127.0.0.1:6379> ZRANGE leaderboard 0 -1 REV WITHSCORES
1) "asha"
2) "1200"
3) "ravi"
4) "950"

Interview problem

The problem

Should this data live in Redis?

Your team wants to move five things into Redis: product catalogue pages, user login sessions, the per-user API quota, the order history, and a "who's online now" list. For each one, decide whether Redis is a good home, what the source of truth is, and what happens if Redis loses its data.

You're given

  • 50K requests/sec at peak
  • Orders are financial records
  • Sessions last 30 minutes
  • Quota: 1,000 calls/hour/user

The interviewer follows up

01

The CTO says "Redis has persistence, so let's put orders there too." What's your answer?

02

When is Redis a reasonable primary database?

When it breaks

Redis is used as the only store for data nobody can rebuild

What you see

After a crash or a failover with replica lag, recent writes are gone. Nobody notices until a customer asks where their data went.

Fix & prevent

Classify every keyspace as cache, derivable, or source of truth. Sources of truth get a durable home (database, or MemoryDB), or at least AOF plus replicas plus tested backups.

Every team puts its data in one shared Redis

What you see

One team's KEYS * or 500 MB value blocks everyone; one team's cache fill evicts another team's sessions.

Fix & prevent

Separate instances (or clusters) per workload class: caches with allkeys-lru, stateful data with noeviction. Enforce key prefixes and ACLs per service (Topic 14.1).

Explain it without notes

01

Explain the difference between "Redis stores values" and "Redis is a data structure server", with an example.

02

Why is "use Redis" never a complete answer in a design interview?

Practice

01

List three pieces of state in an application you know. For each, write whether it's cache, derivable, or source of truth, and what Redis loss would cost.

02

Check which Redis-family server your company (or a cloud provider you know) runs: Redis Open Source, Redis Enterprise, Valkey, or a managed service. What version?

Trade-offs

  • ↔

    Speed vs cost: RAM is roughly an order of magnitude more expensive per GB than SSD, so Redis holds the hot working set, not everything.

  • ↔

    Simplicity vs guarantees: Redis's single-threaded execution makes every command atomic and easy to reason about, but that same design means one slow command stalls every client.

  • ↔

    One Redis for everything vs one per workload: sharing is cheaper and simpler until workloads interfere; separate instances cost more but isolate failures and eviction policies.

Done when you can

  • I can describe Redis as a data structure server and give three examples of server-side operations.

  • I can list at least six roles Redis plays and the failure behaviour of each.

  • I can explain when Redis should not be the source of truth.

  • I know the difference between Redis Open Source and Valkey, and why it matters for version-specific commands.