Skip to the page

NoSQL and MongoDB · core

SQL or NoSQL: the families and how to choose

NoSQL is not one thing. Each family fits a data shape and an access pattern. You choose by shape, queries, consistency and what the team can run, not because someone says SQL does not scale.

The notes

What you must know

  • Relational (PostgreSQL, MySQL): relationships, ad-hoc queries, strong consistency, multi-row transactions. Good for orders, payments and inventory.
  • Document (MongoDB): nested data that is read together, and a shape that changes. Good for catalogs, content and profiles.
  • Key-value (Redis, DynamoDB): access by a known key at large scale. Good for sessions and carts.
  • Wide-column (Cassandra, ScyllaDB): heavy writes with time order. Good for messages and events.
  • Graph (Neo4j): questions about relationships, such as fraud rings. Search engines and time-series stores have their own jobs.
  • The costs of NoSQL: you model per query, you copy data, you have few or no joins, and you choose consistency per read or write. DynamoDB needs the access patterns known up front.
  • The lines blur: PostgreSQL has JSONB, MongoDB has multi-document transactions, and distributed SQL databases keep SQL and transactions with horizontal scale at the cost of latency and operations.

The red pen

Common traps: mistake → fix

  • Mistake: NoSQL has no schema, so no design is needed

    Fix: the schema lives in your code and your queries, and a bad design is still slow.

  • Mistake: SQL does not scale

    Fix: one well-tuned server goes far, and SQL can also scale out.

  • Mistake: Use MongoDB for money movement with no thought about transactions

    Fix: decide how you get atomic multi-record updates first.

Easy to hard

Questions interviewers ask, easy to hard

  1. For a new feature, how do you choose between SQL and NoSQL?
  2. Give one example where you pick each.
  3. What do you give up when you move from SQL to a document or key-value store?
  4. Which store fits a ledger of payout events read by key?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview