PostgreSQL vs MongoDB vs Redis: which database for what?

Doha I. · Published · Lire en français

PostgreSQL vs MongoDB vs Redis: which database for what?

Use PostgreSQL for structured, related data that needs transactions and SQL; MongoDB for flexible JSON-like documents whose shape changes often; and Redis for fast in-memory data such as caches, sessions, rate limits and queues. Many applications combine PostgreSQL or MongoDB as the primary store with Redis as the cache.

PostgreSQL, MongoDB and Redis are three of the most used databases, and they solve different problems. Choosing well is less about which is "best" and more about matching each one to the shape of your data.

At a glance

PostgreSQL MongoDB Redis
Model Relational tables, SQL Documents in collections Keys and data structures in memory
Strength Transactions, joins, constraints Flexible schema, nested data Sub-millisecond reads and writes
Typical use Orders, users, accounting, most app data Catalogs, content, events, profiles Cache, sessions, rate limits, queues, counters
Durability Primary store Primary store Usually a companion to a primary store

PostgreSQL: the default for application data

Choose PostgreSQL when your data has relationships (customers have orders, orders have lines), when integrity matters (constraints, foreign keys, transactions), and when you want SQL for reporting. Extensions add full-text search, geospatial queries and vectors.

MongoDB: documents that change shape

Choose MongoDB when records are naturally nested JSON and their fields vary or evolve quickly: product catalogs with different attributes, content, or event payloads. You trade some relational guarantees for schema flexibility.

Redis: speed, not storage

Redis keeps data in memory. Use it for things that must be fast and can be rebuilt or are short-lived: caching query results, user sessions, rate limiting, job queues and leaderboards. Pair it with a primary database rather than using it as the only copy of important data.

Using them together

A common setup:

  1. PostgreSQL (or MongoDB) holds the source of truth.
  2. Redis caches hot reads and stores sessions.
  3. MongoDB stores semi-structured data when a relational model would be awkward.

The cost is operational: three engines to provision, secure, monitor and back up.

Running all three with LordBase

LordBase hosts PostgreSQL, Redis and MongoDB in one dashboard and one API, included in every plan. The free plan covers 3 databases and 2 GB of storage, so a small app can start with PostgreSQL plus Redis at no cost. See managed PostgreSQL, managed Redis and managed MongoDB.

Free for up to 3 databases

PostgreSQL, Redis and MongoDB in one place. Upgrade when your project grows.

PostgreSQL vs MongoDB vs Redis: which database for what? | LordBase