What Is Redis Used For? 7 Real Use Cases in Web Applications Beyond Caching
Short answer: Redis is an in-memory data structure store used as a cache, a database, a message broker and a coordination layer. In real web applications it is most often used for caching, session storage, rate limiting, real-time messaging (pub/sub), leaderboards and counters, background job queues, and distributed locks. Almost every article on this topic stops at “Redis is a fast cache”. That is true, and it is also the least interesting thing about it. If you already have a Postgres or MySQL database, the real question is not what is Redis, it is: which problem on my current backlog does Redis actually solve better than my database? This post answers that. Seven concrete use cases, each with the Redis data structure behind it, a short code snippet, and the trade-offs you should know before shipping it. Redis in 60 seconds: why it is fast and why that matters Redis (REmote DIctionary Server) keeps your data in RAM and serves it over a very simple protocol. Typical response times are sub-millisecond, and a single node routinely handles tens of thousands of operations per second on modest hardware. A Crash Course in Redis tackles the same question from another angle. Three properties explain most of its use cases: In-memory storage: no disk seek on the read path, so lookups are extremely cheap. Atomic commands: each command (and each Lua script or transaction) runs to completion without interleaving, which makes counters, locks and queues safe without you writing locking logic. Rich data structures: it is not just key to string. You get lists, hashes, sets, sorted sets, streams, bitmaps, HyperLogLog, geospatial indexes and vector indexes. That last point is the one developers underuse. Picking the right structure is usually what turns a hard problem into five lines of code. Data structure to problem mapping Redis structure What it is good at Typical use case String Blob storage with TTL, atomic counters Cache entries, feature flags, rate limit counters Hash Objects with field level updates Sessions, user profiles, shopping carts List FIFO / LIFO with blocking reads Simple job queues, activity feeds Set Uniqueness, intersections Online users, tags, deduplication Sorted set (ZSET) Ranking and range queries by score Leaderboards, sliding window rate limits, delayed jobs Pub/Sub channel Fire and forget fan-out WebSocket broadcast across app servers Stream Persistent log with consumer groups Event pipelines, reliable task distribution Vector index Similarity search on embeddings RAG retrieval, semantic caching for LLM apps 1. Caching (the baseline use case, done properly) Yes, caching is the number one answer to “what is Redis used for”. The part most tutorials skip is the policy around it: key naming, TTL, and invalidation. The classic pattern is cache-aside: // Node.js with ioredis async function getProduct(id) { const key = `product:v2:${id}`; const hit = await redis.get(key); if (hit) return JSON.parse(hit); const product = await db.products.findById(id); // 5 minute TTL, always set one await redis.set(key, JSON.stringify(product), ‘EX’, 300); return product; } Practical rules that save you pain later: Always set a TTL. A cache without expiry is a memory leak with extra steps. Version your key prefixes (product:v2:). Changing the serialized shape then becomes a one-line deploy instead of a mass invalidation script. Configure maxmemory and an eviction policy such as allkeys-lru on pure cache instances. Beware of stampedes. When a hot key expires, hundreds of requests may hit the database at once. Add a short lock or a randomized TTL jitter. 2. Session storage for stateless app servers The moment you run more than one application instance behind a load balancer, in-process sessions break: a user logs in on server A and the next request lands on server B. Storing sessions in Redis makes your app servers stateless and disposable. // Express + connect-redis import session from ‘express-session’; import { RedisStore } from ‘connect-redis’; app.use(session({ store: new RedisStore({ client: redis, prefix: ‘sess:’ }), secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false, cookie: { httpOnly: true, secure: true, sameSite: ‘lax’, maxAge: 86400000 } })); Why Redis beats a database table here: the session TTL is handled natively by Redis (no cron job to clean rows), writes happen on almost every request, and the data is cheap to lose compared to business data. In Spring Boot the equivalent is Spring Session with spring-session-data-redis; in Django it is django.contrib.sessions.backends.cache; in Laravel it is SESSION_DRIVER=redis. Watch out: if your Redis instance is purely a cache with LRU eviction, do not put sessions on it. An eviction becomes a forced logout. Use a separate instance or logical database with noeviction. 3. Rate limiting and abuse protection Rate limiting needs a shared, atomic counter that all your app instances can agree on. That is a textbook fit for Redis. The simplest version is a fixed window with INCR plus EXPIRE, done atomically in Lua so two concurrent requests cannot both skip the expiry: — KEYS[1] = rate:login:ip:1.2.3.4 , ARGV[1] = window seconds local current = redis.call(‘INCR’, KEYS[1]) if current == 1 then redis.call(‘EXPIRE’, KEYS[1], ARGV[1]) end return current # Python, redis-py allowed = 20 count = limiter_script(keys=[f”rate:login:ip:{ip}”], args=[60]) if count > allowed: abort(429) Need something smoother than a fixed window? Use a sorted set as a sliding window log: add one member per request scored by timestamp, drop everything older than the window, then count. ZREMRANGEBYSCORE rate:api:user:42 0 <now_ms – 60000> ZADD rate:api:user:42 <now_ms> <request_id> ZCARD rate:api:user:42 EXPIRE rate:api:user:42 60 Fixed window is cheaper, sliding window is fairer. For very high volume endpoints, a token bucket in Lua gives you burst tolerance with a constant memory footprint. 4. Pub/sub and real-time features across servers You have WebSockets, three Node or Rails processes, and a message that must reach a user connected to a different process. Redis pub/sub is the standard glue. # terminal A (consumer side, one per app instance) SUBSCRIBE room:general # terminal B (whatever process produced the event) PUBLISH room:general ‘{“user”:”amelie”,”text”:”deploy done”}’ // Socket.IO Redis adapter: broadcast works across all instances import { createAdapter } from ‘@socket.io/redis-adapter’; io.adapter(createAdapter(pubClient, subClient)); io.to(‘room:general’).emit(‘message’, payload); Important limitation: classic pub/sub is
What Is Redis Used For? 7 Real Use Cases in Web Applications Beyond Caching Read More »










