NoSQL Data Models and When to Use Them

Compare key-value, document, wide-column, graph and time-series stores, and learn to pick a data store from access patterns rather than hype.

Intermediate · about 4 hours · difficulty 3/5

Learn first: Relational Databases and SQL for Design

"NoSQL" covers several very different families. Each trades some relational features for scale, flexibility or speed on a particular access pattern.

The families

  • Key-value (Redis, DynamoDB, etcd): get and put by key. Extremely fast and easy to scale. Sessions, carts, feature flags, counters.
  • Document (MongoDB, Couchbase): JSON-like documents with flexible fields. Good for product catalogues and user profiles that vary in shape.
  • Wide-column (Cassandra, ScyllaDB, HBase, Bigtable): rows grouped by a partition key, sorted by clustering key. Built for huge write volumes: chat messages, IoT data, activity logs. Discord moved billions of messages to this model.
  • Graph (Neo4j, Neptune): nodes and edges with fast traversals. Friend-of-friend recommendations, fraud rings.
  • Time-series (InfluxDB, TimescaleDB, Prometheus): append-heavy metrics with time-based queries and downsampling.
  • Search engines (Elasticsearch, OpenSearch): inverted indexes for full-text search and filters.

Design from access patterns

In relational design you model entities first and query later. In most NoSQL stores you list the queries first and shape tables to answer each one with a single key lookup or partition scan. Joins usually move into the application or are avoided by duplicating data.

Choosing in practice

Start with: Do I need multi-row transactions and ad hoc queries? (Relational.) Is the write volume massive and the query pattern fixed? (Wide-column.) Is it a simple lookup by ID at very high QPS? (Key-value.) Many real systems use polyglot persistence: Postgres for orders, Redis for sessions, Elasticsearch for search, S3 for images.

Pitfalls

  • Choosing MongoDB to avoid "designing a schema"; the schema just moves into code.
  • Picking a bad partition key in Cassandra or DynamoDB and creating hot partitions.

You are ready to move on when you can map five features of a food delivery app to a store type and justify each choice from its access pattern.

Key concepts

  • Key-value stores
  • Document databases
  • Wide-column stores
  • Graph databases
  • Time-series databases
  • Search engines (inverted index)
  • Access-pattern driven modelling
  • Polyglot persistence

Mini project

Design the tables for a chat app's messages in both PostgreSQL and Cassandra (or DynamoDB). For each, write the three main queries and explain which store handles 1 lakh writes per second more easily and why.

Check yourself

Why do wide-column databases ask you to design tables around queries instead of entities?

Free resources