Skip to main content
PreparationZone Logo
PrepZone

SQL vs NoSQL

Relational rigour versus document, wide-column and key-value flexibility — and when each wins.

Pass checkpoint below

Read these first

Relational (SQL) strengths

When SQL wins

  • Complex joins — reports spanning users, orders, and products.
  • ACID transactions — multi-row updates must succeed or fail together.
  • Ad hoc queries — analysts run SQL without schema migrations.
  • Mature tooling — Postgres, MySQL, backups, ORMs, decades of ops knowledge.
Java
-- Natural fit for SQL: relational integrity
CREATE TABLE follows (
  follower_id  UUID NOT NULL REFERENCES users(id),
  following_id UUID NOT NULL REFERENCES users(id),
  created_at   TIMESTAMPTZ DEFAULT now(),
  PRIMARY KEY (follower_id, following_id)
);

SELECT u.username, COUNT(f.following_id) AS following_count
FROM users u
LEFT JOIN follows f ON f.follower_id = u.id
WHERE u.id = $1
GROUP BY u.username;

StreamHub stores accounts, billing, and follow relationships in Postgres — relationships and constraints matter.

Database selection on AWS

DATABASERDS / AuroraACID · joins
DATABASEDynamoDBkey-value scale
ANALYTICSOpenSearchfull-text · autocomplete
DATABASEElastiCachesessions · rate limits
Pick the store that matches access pattern — not the other way around.

NoSQL categories

TypeModelExamplesSweet spot
DocumentJSON documentsMongoDB, DynamoDBFlexible schema, nested objects
Key-valueOpaque key → blobRedis, DynamoDBSessions, cache, simple lookups
Wide-columnRow key + column familiesCassandra, HBaseHigh write throughput, time-series
GraphNodes and edgesNeo4jSocial graphs, recommendations
  • Document

    ModelJSON documents
    ExamplesMongoDB, DynamoDB
    Sweet spotFlexible schema, nested objects
  • Key-value

    ModelOpaque key → blob
    ExamplesRedis, DynamoDB
    Sweet spotSessions, cache, simple lookups
  • Wide-column

    ModelRow key + column families
    ExamplesCassandra, HBase
    Sweet spotHigh write throughput, time-series
  • Graph

    ModelNodes and edges
    ExamplesNeo4j
    Sweet spotSocial graphs, recommendations
Java
// Document store: video metadata as one document
{
  "video_id": "v_9182",
  "creator_id": "u_42",
  "title": "Sunset timelapse",
  "tags": ["nature", "4k"],
  "stats": { "views": 128400, "likes": 9201 }
}

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 5 sections

  • Side-by-side comparison
  • Polyglot persistence
  • Migration and schema evolution
  • Decision checklist
  • Common mistakes

Test yourself

Answer these before moving on — recall is what makes it stick.