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.
Data & storage
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.
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.
A durable relational database on disk.
Stores the source of truth with constraints, transactions and complex queries.
| Aspect | Redis | PostgreSQL |
|---|---|---|
| Storage | Memory (optional persistence) | Disk |
| Latency | Sub-millisecond | Milliseconds |
| Query power | Key and structure commands | Full SQL |
| Typical role | Cache, sessions, queues, rate limits | System of record |
| Data size | Bounded by RAM | Very large |
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.
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.
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.
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.
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.
Strings, hashes, lists, sets, sorted sets, streams, bitmaps, HyperLogLog and geospatial indexes, each with atomic commands suited to specific problems.
Leaderboards, rankings, time-ordered feeds and rate-limit windows, since members are kept ordered by score with fast range queries.
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.
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.
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.
Practise every comparison in your dashboard.
Start learning