The problem Redis solves vs relational databases, the in-memory model, Redis vs Memcached, installing Redis, and your first key-value operations — zero prior knowledge assumed.
F-1 — What Is Redis and Why Does It Exist?
Who this module is for: You have heard of Redis — maybe you have even used it to "add caching" to a project — but you have never understood what it actually is under the hood. You might be a backend engineer who copies the
redis.set()andredis.get()pattern without understanding why it is fast, what guarantees it provides, or when it is the wrong tool. This module assumes nothing. By the end, you will have a working Redis installation, a precise mental model of what Redis is and is not, and your first real key-value operations running against a live server.
The Problem Redis Was Built to Solve
To understand Redis, you need to first understand the bottleneck it eliminates.
Imagine a typical web application. A user requests their profile page. Your application server receives the request and runs a query against PostgreSQL:
PostgreSQL runs this query. It reads pages from disk (or from its buffer cache), executes the join, and returns the result. On a well-tuned database with proper indexes, this might take 2–5 milliseconds.
That sounds fast. But now multiply it:
- 10,000 users make requests per second
- Each request runs this query (and usually several more)
- Your database is now handling 50,000–100,000 queries per second
- Each query consumes a connection, CPU, I/O, and memory
The database becomes the bottleneck. You scale it vertically (bigger machine), then horizontally (read replicas), then you hit the wall of what SQL databases are designed to do: store data reliably, enforce constraints, execute complex queries — not answer the same simple lookup 100,000 times per second.
The problem Redis solves: answering simple, repeated data lookups at a speed and scale that disk-based databases cannot match.
The core insight is obvious once stated: if you have already computed the answer to a question and the answer has not changed, do not compute it again. Store it somewhere faster than your database and return it instantly.
Redis is that somewhere faster.
What Makes Redis Different: The In-Memory Model
Every database you have likely worked with — PostgreSQL, MySQL, MongoDB, SQLite — stores its primary data on disk. Disk is durable (data survives a power outage) but slow relative to RAM. Even with SSDs, a disk read involves seeking to the right location and waiting for the storage controller. With spinning hard drives, this is measured in milliseconds. With NVMe SSDs, it is measured in microseconds.
RAM is different. A RAM read is measured in nanoseconds — roughly 100 nanoseconds vs 100 microseconds for SSD, which is 1,000x faster.
Redis stores its entire dataset in RAM. When you set a key, it goes into memory. When you get a key, it comes from memory. There is no disk I/O on the hot path for reads or writes.
This is what gives Redis its speed. A well-configured Redis instance on modest hardware can handle 1 million read operations per second with single-digit millisecond latency. That is not an exaggeration from a benchmark. That is what engineers encounter in production.
The trade-off you accept: RAM is volatile. If the Redis process crashes or the machine loses power, data stored only in memory is gone. Redis has mechanisms to address this (RDB snapshots, AOF logging — covered in P-1 and P-2), but you must understand the default: without persistence configured, Redis loses data on restart.
This is not a bug. It is a design decision. For pure caching — where your primary database is the source of truth — losing the cache on restart is acceptable. You simply warm the cache again. For other use cases (as a message broker, a session store, a rate limiter), you need persistence, and Redis supports it.
Redis vs Memcached: The Question Engineers Ask First
If you have researched caching before, you have encountered Memcached. Both are in-memory key-value stores. The question "which one?" comes up in every engineering team. Here is the honest comparison:
Memcached gets right:
- Pure simplicity. It does one thing: store and retrieve values by key. No data structures, no persistence, no pub/sub, no scripting.
- Multi-threaded by design, which can utilize multiple CPU cores more efficiently for pure throughput.
- Slightly lower memory overhead per key due to simpler internals.
Where Memcached stops:
- The value is always a string. There are no lists, sets, sorted sets, or hashes. You cannot atomically increment a counter, push to a list, or add to a set.
- No persistence. Data is gone on restart, period.
- No pub/sub. No streams. No scripting.
- No built-in replication or clustering (community solutions exist but are not first-class).
- No transactions or atomic multi-key operations.
What Redis adds:
- Rich data structures (Strings, Hashes, Lists, Sets, Sorted Sets, HyperLogLogs, Bitmaps, Streams, Geospatial indexes).
- Optional persistence (RDB snapshots, AOF).
- Pub/Sub messaging.
- Lua scripting and Redis Functions for atomic compound operations.
- Transactions (MULTI/EXEC).
- Built-in replication, Sentinel (automatic failover), and Cluster (horizontal sharding).
The practical answer in 2025: Choose Redis. The days of "Memcached for simple caching, Redis for everything else" are largely over. Redis has caught up to and surpassed Memcached's throughput in most real-world workloads, and its additional capabilities mean you get more done with one infrastructure component. Unless you have a specific, measured reason to prefer Memcached (a very old codebase already using it, or a specific multi-threaded throughput requirement), Redis is the default choice.
The Redis Data Model: A Key-Value Store That Is More Than Key-Value
The simplest description of Redis is a key-value store: you associate a key (a string) with a value, and you retrieve the value by key.
But calling Redis a "key-value store" is like calling PostgreSQL a "file storage system." It is technically accurate and practically misleading.
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion