Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Data & storage

What is the difference between Redis and a database like PostgreSQL?

Redis keeps data in memory for microsecond reads and rich data structures, so it is used as a cache, queue or rate limiter; PostgreSQL is the durable system of record with SQL and transactions.

Technologies
2
Difference questions
50

What each one is

Redis

An in-memory data store with strings, hashes, lists, sets, sorted sets and streams.

Extremely fast, with TTLs, Pub/Sub and atomic commands; persistence is optional and memory is the limit.

PostgreSQL

A durable relational database on disk.

Stores the source of truth with constraints, transactions and complex queries.

At a glance

AspectRedisPostgreSQL
StorageMemory (optional persistence)Disk
LatencySub-millisecondMilliseconds
Query powerKey and structure commandsFull SQL
Typical roleCache, sessions, queues, rate limitsSystem of record
Data sizeBounded by RAMVery large

The 10 most-asked difference questions

Subjective questions 10

1What is the main difference between Redis and PostgreSQL?Asked almost every time

Redis is an in-memory data store with rich data structures and sub-millisecond operations, used for caching, sessions, queues and rate limits. PostgreSQL is a durable relational database on disk with SQL, constraints and transactions, used as the system of record.

2Can Redis replace PostgreSQL as the main database?Asked almost every time

For most applications, no. Redis keeps data in memory, offers limited querying and has weaker durability guarantees by default, so it complements a primary database rather than replacing it.

3Why put Redis in front of PostgreSQL?Asked almost every time

To serve hot data such as sessions, computed pages or frequent lookups from memory, cutting latency and database load, while PostgreSQL remains the source of truth.

4What is the cache-aside pattern?Asked almost every time

The app checks Redis first; on a miss it reads PostgreSQL, stores the result in Redis with a TTL and returns it. On writes it updates PostgreSQL and deletes or updates the cached key.

5How does durability differ?Asked almost every time

PostgreSQL writes to a write-ahead log on disk and confirms commits durably. Redis can persist with RDB snapshots and AOF logs, but depending on settings a crash can lose recent writes.

6What data structures does Redis offer?Very often asked

Strings, hashes, lists, sets, sorted sets, streams, bitmaps, HyperLogLog and geospatial indexes, each with atomic commands suited to specific problems.

7What is a sorted set used for?Very often asked

Leaderboards, rankings, time-ordered feeds and rate-limit windows, since members are kept ordered by score with fast range queries.

8How do you implement rate limiting with each?Very often asked

Redis implements counters or sliding windows with INCR, EXPIRE and sorted sets in microseconds. PostgreSQL can do it with tables but adds disk writes and latency per request.

9How do sessions differ?Very often asked

Redis stores sessions with expiry automatically, ideal for fast lookups on every request. PostgreSQL can store sessions but needs cleanup jobs and more I/O.

10What is cache invalidation and why is it hard?Very often asked

Removing or updating cached data when the source changes. Missing an invalidation shows stale data; over-invalidating loses the cache benefit. TTLs plus explicit deletes on writes are common.

See all 50 difference questions with answers in your dashboard →

Practise every comparison in your dashboard.

Start learning