Practical caching for backends — run Redis, use the data types that matter, build the cache-aside pattern, handle invalidation and stampedes, rate-limit and store sessions, and cache at the HTTP layer with Cache-Control and ETags.
This is a hands-on caching course built around Redis and Node. You should be comfortable writing JavaScript and async/await, and know what a database query is — every lesson is runnable code, not theory.
Before you start
You need two things: a running Docker (so Redis runs the same on any OS), and a Node project for the client. Follow the steps for your operating system.
1. Install Docker
Windows
Install Docker Desktop, then restart your PC, launch Docker Desktop once, and wait until the tray icon says it is running.
winget install Docker.DockerDesktopmacOS
Install Docker Desktop with Homebrew (or download it), then launch it and wait until it reports running.
brew install --cask dockerLinux
Install Docker Engine with the official script. On Linux you run the docker commands with sudo (or add yourself to the docker group).
curl -fsSL https://get.docker.com | sh2. Start Redis (first time only)
Same command on every OS — it downloads the redis image the first time and runs it on port 6379 (prefix with sudo on Linux):
docker run -d --name redis -p 6379:6379 redisRun this once — it creates the container. Coming back in a later session? Skip straight to docker start redis (see below).
Check it answers — you should see PONG:
docker exec -it redis redis-cli ping3. Create a Next.js app
The lessons run server-side code, so you need a project to put it in. Scaffold one and accept the defaults (App Router, TypeScript), then cd into it:
pnpm
pnpm create next-app@latest my-appnpm
npx create-next-app@latest my-appYou run docker run only once — it creates the container. After that, manage that same container with these commands:
docker start redisStart it again after a reboot or a stop.docker stop redisPause it when you are done (frees memory).docker psSee what is currently running.Do not run docker run a second time — it fails because the name redis is already in use. Keep Redis running while you work through the lessons.
Connecting to Redis
Run Redis locally with Docker, connect from Next.js with a shared ioredis client, and use the core commands — SET, GET, DEL, and expiry with TTL. Everything else builds on these.
Redis Data Types You'll Actually Use
Go beyond strings — atomic counters with INCR, store objects in hashes, and build a leaderboard with sorted sets. The three data types that cover most real backend caching work.
The Cache-Aside Pattern
The caching pattern you will use most — check the cache first, fall back to the database on a miss, then store the result with a TTL. Build it once as a reusable helper.
Invalidation & Stampede Protection
Keep cached data correct and your database safe — delete keys on write so reads never serve stale data, cache empty results to stop repeated misses, and prevent a cache stampede with a lock.
Rate Limiting & Sessions
Two everyday Redis jobs beyond caching — a fixed-window rate limiter built from INCR and EXPIRE, and a fast server-side session store. Both are a handful of lines.
HTTP Caching for APIs
Cache at the protocol level — set Cache-Control on your API responses, return 304 Not Modified with ETags, and use s-maxage and stale-while-revalidate so a CDN caches for you.