All the basics

What are SQL and NoSQL databases?

Two ways to keep data: neat tables with strict columns, or flexible documents and lookups that spread across many machines.

SQL is a filing cabinet of forms with fixed boxes, cross-referenced by number. NoSQL is a stack of folders, each holding whatever you put inside.

Press Play to watch it run · 5 steps

An app saves an order as a single document, as linked tables, and then as data grows.

One order, stored two waysAn app saves an order as a single document, as linked tables, and then as data grows.split by keyYour appSQL tablesDocumentsAnother machine

Tap any box to see what it is and what it talks to.

  • Service
  • Database
  • Object storage
Open in playground
Text description
  1. The app saves the order as one document: customer, address and items together.
  2. One read brings back the whole order. Fast and flexible.
  3. The customer moves. Their address is copied inside every old order.
  4. The app must fix each copy. Miss one and the data disagrees.
  5. Questions across many orders, like sales per item, are awkward to answer.
  • SQL gives strict tables, joins and transactions.
  • NoSQL trades some of that for flexible shapes and easy spreading.
  • Start with SQL unless you have a reason not to.

Reach for it when

Start with SQL for orders and money. Use NoSQL for key lookups at huge scale or data whose shape keeps changing.

The catch

A single SQL machine takes all writes; NoSQL spreads easily, but a changed address must be fixed in every copied order.

Say it in an interview“I would start with a SQL database for correctness and flexibility of queries, and move a workload to NoSQL only when scale or data shape clearly needs it.”