Video in progress

How do you choose between a relational database and NoSQL for a new project?

If the data is interconnected and you need transactions and complex queries, use a relational database like PostgreSQL. If you need a huge volume, simple key-based access and easy horizontal scaling, use NoSQL. For most projects, a relational database is the default choice.

📖 Answer

The queries decide the choice, not fashion. Ask yourself: "How will I read the data?"

A relational database fits when:

  • you have money, orders, stock levels — ACID transactions are a must;
  • there are lots of JOINs, filters and reports;
  • the schema is fairly stable.

You pick the type of NoSQL by purpose:

  • key-value (Redis, DynamoDB) — sessions, cache, cart;
  • document (MongoDB) — records of varying shapes, like product attributes;
  • wide-column (Cassandra) — very heavy writes: logs, message history, IoT;
  • graph (Neo4j) — relationships like "friends of friends".

Having both in one project is normal: orders in PostgreSQL, chat messages in Cassandra, cache in Redis.

In an interview, don't say "NoSQL is faster". It is faster for certain kinds of queries, but it can be awkward for others. And today's PostgreSQL stores documents well too, with jsonb.