9bNine Bits

PostgreSQL vs Redis: Which One Do You Need?

PostgreSQL vs Redis is not an either-or choice: PostgreSQL is a durable relational database for your system of record, while Redis is an in-memory data structure store usually placed in front of it as a cache, session store or queue. Redis can persist data to disk, but it works with an in-memory dataset, so it rarely replaces PostgreSQL for data that must survive and be queried relationally. Start with PostgreSQL, and add Redis when you need fast, short-lived access to hot data.
PostgreSQL vs Redis: Which One Do You Need?

Decision summary

Pick PostgreSQL when the data is the system of record: it must survive a crash, obey relational constraints, or be queried with joins, aggregates and ad hoc SQL. Pick Redis when you need a fast layer in front of that data, such as caching, session storage, counters, pub/sub or a lightweight queue. Most production stacks run both. This comparison applies to PostgreSQL 19, announced 19 November 2026; versions 19, 18, 17, 16 and 15 are currently supported.

CriterionPostgreSQLRedis
What it isExtensible relational SQL databaseIn-memory data structure store, described by its own site as the world's fastest in-memory database
Data modelRelational tables, SQL data types, JSON/JSONB, indexes, full-text search; supplied modules and extensions add further typesStrings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes and streams
PersistenceAlways on, built around the write-ahead logOptional: periodic dumps of the dataset to disk, an append-only command log, both, or none
TransactionsMulti-statement transactions with concurrency control, foreign keys and SQL isolation levelsAtomic operations on individual data types, transactions and Lua scripting; no SQL isolation levels or foreign keys
Scaling and availabilityReplication, load balancing, logical replication, parallel queryBuilt-in replication, Redis Sentinel for high availability, Redis Cluster for automatic partitioning
Query languageSQLCommand protocol plus Lua scripting
LicenceThe PostgreSQL LicenseChoice of RSALv2 or SSPLv1 (source-available, not OSI-approved open source)
Managed service exampleIBM Cloud Databases for PostgreSQLIBM Cloud Databases for Redis
Typical roleSystem of record, reporting, relational queriesCache, session store, queue, pub/sub, leaderboards

Data model and persistence

PostgreSQL stores data in tables and rows, protects it with a write-ahead log, and handles semi-structured fields through JSON/JSONB. Its manual also covers indexes, full-text search and the extension mechanism, so you can add specialized data types without leaving the relational model. Add extensions deliberately and check each one's documentation first.

Redis works with an in-memory dataset to achieve top performance. Persistence is a choice rather than a default: you can have it persist by periodically dumping the dataset to disk, by appending each command to a disk-based log, or both. You can also disable persistence entirely if you only need a feature-rich, networked in-memory cache. Because the working set lives in RAM, dataset size is bounded by memory, which is why Redis is rarely used to hold the full, growing history of an application.

# redis.conf: append-only logging for data you do not want to lose on restart
appendonly yes
appendfsync everysec

Redis also supports keys with a limited time-to-live, which suits cache and session data that should expire on its own. It is written in ANSI C for POSIX systems and has no official Windows build support, which matters if your servers or developer machines run Windows.

Transactions and durability

PostgreSQL transactions are all-or-nothing across multiple statements, and foreign keys and check constraints enforce integrity inside the database. That is the main reason it is the default system of record.

Redis offers transactions and Lua scripting, and operations on individual data types are atomic. It has no foreign-key enforcement and no SQL-style isolation levels, and a command that fails at execution time inside a queued block does not undo the others. For simple compare-and-swap patterns, WATCH gives optimistic locking, which covers most counter and cache use cases.

-- PostgreSQL: all-or-nothing
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

# Redis: atomic batch, not a rollback-capable transaction
MULTI
DECRBY balance:1 100
INCRBY balance:2 100
EXEC

One durability caveat matters for the cache-in-front pattern: Redis replication is asynchronous. It offers fast non-blocking synchronization and partial resynchronization after a net split, but a write acknowledged by a primary can still be lost if that node fails before replicas catch up. Treat anything you cannot rebuild from PostgreSQL as unsafe to keep only in Redis.

Scaling and architecture

PostgreSQL documents high availability, load balancing and replication, plus logical replication, so reads can be spread across replicas and selected tables can be replicated to other systems. Spreading writes across many nodes is not a built-in feature; it usually means partitioning in the application or adding a sharding layer. Routine maintenance is improving too: PostgreSQL 19 introduces REPACK (CONCURRENTLY), which lets you reclaim table bloat without blocking reads or writes and replaces VACUUM FULL and CLUSTER for that job.

Redis provides built-in replication, high availability via Redis Sentinel, and automatic partitioning with Redis Cluster, so horizontal scaling and failover are part of the core design rather than an add-on. It also includes LRU eviction, which lets a memory-bounded cache discard its least recently used keys instead of failing when memory fills. The trade-off is the simpler consistency and transaction model described above.

When PostgreSQL write throughput or read latency becomes the bottleneck, teams often add Redis to absorb hot reads before re-architecting the database.

Licensing

PostgreSQL is distributed under the PostgreSQL License; see the project's own legal notice for the current terms.

Redis currently offers a choice of two licences rather than one: the Redis Source Available License 2.0 (RSALv2) or the Server Side Public License v1 (SSPLv1). Both are source-available rather than OSI-approved open-source licences. For most application teams that simply use Redis as a service or a server, this changes little day to day. It matters more if you redistribute Redis, embed it in a product, or offer it as a hosted service, where you should read the licence text and check the terms for the exact release you deploy.

Redis in front of PostgreSQL

The dominant pattern is pairing, not choosing. PostgreSQL stays the source of truth, and Redis absorbs read traffic, session data, rate-limit counters or queue workloads that do not need durable relational storage.

  • Cache-aside: read from Redis first, fall back to PostgreSQL on a miss, and write the result back with a time-to-live.
  • Session store: short-lived session data with an expiry, which keeps churn out of the relational schema.
  • Queue or pub/sub: Redis streams or lists for simple job queues, and Redis pub/sub for fan-out notifications.
  • Leaderboards and rankings: sorted sets with range queries.
def get_user(user_id):
    cached = redis.get(f"user:{user_id}")
    if cached:
        return cached
    row = postgres.query("SELECT * FROM users WHERE id = %s", user_id)
    redis.set(f"user:{user_id}", row, ex=300)
    return row

Whichever cache you use, invalidate or expire entries explicitly when PostgreSQL data changes. Relying on a long TTL alone to hide stale data is a common source of subtle bugs.

If you would rather not run either service yourself, managed options exist for both; IBM Cloud, for example, offers Databases for PostgreSQL and Databases for Redis.

When one can replace the other

Redis rarely replaces PostgreSQL for anything that must persist reliably and support relational queries. Without foreign keys, joins or SQL isolation levels, and with a dataset bounded by memory, it is a poor primary store for business-critical data.

PostgreSQL can replace some narrower Redis jobs. Unlogged tables skip write-ahead logging for data you are willing to lose after a crash, which suits some cache-like tables. LISTEN/NOTIFY covers simple pub/sub without another service, and materialized views can hold precomputed results that you refresh on a schedule. Check the SQL command reference for your PostgreSQL version before relying on any of these.

None of these is built to match an in-memory store under heavy, low-latency key lookups. Drop Redis only if your workload does not need that access pattern, and keep both when it does.

Common questions

Can Redis replace PostgreSQL as the primary database?

Generally no. Redis works with an in-memory dataset, has no foreign keys or SQL isolation levels, and uses asynchronous replication. It works well as a layer in front of a durable database but is a weak fit for data that must never be lost.

Can PostgreSQL replace Redis for caching?

For simple cases, yes. Unlogged tables, materialized views and LISTEN/NOTIFY cover basic cache and pub/sub needs. It will not match an in-memory store for high-volume, low-latency key lookups, so the swap works best when that speed is not a hard requirement.

Is Redis open source?

Redis is source-available rather than OSI-approved open source. Its own site says you may choose between the Redis Source Available License 2.0 (RSALv2) and the Server Side Public License v1 (SSPLv1). Check the licence attached to the exact release you deploy.

Does Redis lose data when it restarts?

Only if persistence is off. Redis can persist by periodically dumping the dataset to disk, by appending each command to a disk-based log, or both. Because replication is asynchronous, a failover can still lose recent writes, so keep the authoritative copy in PostgreSQL.

Sources

  1. PostgreSQL Documentation
  2. Redis: About
  3. IBM Cloud Databases offerings
  4. PostgreSQL 19 release announcement

About this page

Last reviewed November 26, 2026 by the Nine Bits editors. Read our editorial policy or report an error.