Video in progress
What is Redis, and what do you typically use it for on the backend?
Redis is an in-memory key-value store. It's mostly used for caches, sessions, counters, queues and rate limiting, because replies come back in microseconds.
📖 Answer
Redis keeps its data in RAM and accepts commands over a simple TCP protocol. A single GET usually returns in about 1 ms including the network, several times faster than an average PostgreSQL query.
In practice you'll see it in these places:
- caching data that is read heavily from the DB (a product card, settings);
- HTTP sessions (Spring Session);
- counters with
INCR: page views, login attempts; - a simple queue, or messaging through Streams;
- leaderboards (Sorted Set).
One thing to keep in mind: Redis is not a "fast DB", it's a specialized tool. There are no complex queries, no JOINs, no secondary indexes. That's why the main data usually stays in a relational database, and Redis sits in front of it.
Sign up to mark studied questions and save your progress.