Skip to the workspace
Pebellslearn by building
Introduction  ›  Lesson

PostgreSQL vs NoSQL

PostgreSQL vs NoSQL Databases 12 minNoSQL stores relax guarantees such as transactions and joins to scale one access pattern, while PostgreSQL keeps them and covers flexible data with jsonb.

postgresql dba / PostgreSQL vs NoSQL

Explore each scene at your own pace.

01 · The rule

The rule

PostgreSQL vs NoSQL Databases

Pedal's mobile team wants to log every tap in the app, and someone suggests "a NoSQL database, because it is faster". Before you add a second system to run, back up and secure, you should know what NoSQL actually trades away, and how much of it PostgreSQL already does.

The rule

NoSQL trades guarantees for one shape of scale; PostgreSQL keeps the guarantees.

"NoSQL" is not one thing. It is a family of databases that each choose one data shape and optimise for it:

  • Document stores (MongoDB, Couchbase) keep JSON-like documents.
  • Key-value stores (Redis, DynamoDB) fetch a value by its key, very fast.
  • Wide-column stores (Cassandra, ScyllaDB) spread huge write volumes across many machines.
  • Graph databases (Neo4j) follow links between nodes.

Most of them relax something PostgreSQL insists on: a fixed schema, joins, multi-row transactions, or reading the very latest write everywhere. In return they get easier scale-out or a natural fit for one access pattern.

PostgreSQL narrows the gap from its side. Its jsonb type stores documents in a binary form that can be indexed and queried:

CREATE TABLE app_events (
  event_id  bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  member_id bigint REFERENCES members (member_id),
  payload   jsonb NOT NULL
);

SELECT count(*) FROM app_events
WHERE payload @> '{"screen": "unlock"}';

The events keep a flexible shape, yet they still sit inside transactions and can still join to members.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.