# NoSQL Databases

> Compare document, key-value, wide-column and graph databases with relational ones, and learn how to choose between SQL and NoSQL for a given workload. Free...

Canonical: https://www.internhack.in/roadmaps/tracks/cs-fundamentals/nosql-databases
Last updated: 2026-11-28

Compare document, key-value, wide-column and graph databases with relational ones, and learn how to choose between SQL and NoSQL for a given workload.

Intermediate · about 4 hours · difficulty 2/5

Learn first: [Indexing and Query Performance](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/indexing-and-query-optimization)

"SQL or NoSQL?" appears in almost every system design interview. The right answer is always "it depends on the access pattern", followed by a concrete justification.

### The main families

- **Key-value** (Redis, DynamoDB): get and put by key, extremely fast. Great for caches, sessions and counters.
- **Document** (MongoDB): JSON-like documents with flexible schemas; good when data is read as a whole unit, like a product with nested attributes.
- **Wide-column** (Cassandra, HBase): rows partitioned by key and optimised for massive write throughput and time-series style access.
- **Graph** (Neo4j): nodes and edges for highly connected data like social graphs and recommendations.

### How they differ from relational databases

- Schemas are flexible or per-record instead of fixed.
- Most are built to **scale horizontally** by partitioning data across nodes.
- Joins are limited or absent, so data is often **denormalised** and modelled around queries rather than entities.
- Many favour availability with **eventual consistency** (you will study CAP in system design), though many now offer tunable or strong consistency.

### Choosing

- Strong consistency, complex queries and relationships, transactions (payments, inventory): relational.
- Huge write volume, simple access by key, flexible or evolving data: NoSQL.
- Many real systems use both: PostgreSQL as the source of truth, Redis as a cache, Elasticsearch for search.

### Pitfalls

Choosing MongoDB because "it is web scale" without an access-pattern reason, and assuming NoSQL means no schema design (bad partition keys create hot spots).

Good enough to move on: for a given feature you can name a suitable database type, explain the trade-off, and sketch how the data would be modelled.

## Key concepts

- **Key-value stores**
- **Document databases**
- **Wide-column stores**
- **Graph databases**
- **Schema flexibility and denormalization**
- **SQL vs NoSQL decision making**
- **Partition keys and hot spots**

## Mini project

Model a URL shortener and a blog with comments twice, once in PostgreSQL and once in MongoDB or Redis, implement the three most common queries in each, and write a one-page comparison of the trade-offs you noticed.

## Check yourself

For a chat application's message history, would you pick a relational database or a wide-column store, and what partition key would you use?

## Free resources

- [MongoDB: Data modeling introduction](https://www.mongodb.com/docs/manual/data-modeling/) (MongoDB)
- [Redis documentation](https://redis.io/docs/latest/) (Redis)
- [System Design Primer: SQL or NoSQL](https://github.com/donnemartin/system-design-primer) (System Design Primer)

Previous: [Indexing and Query Performance](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/indexing-and-query-optimization) · Next: [Number Representation and Digital Logic](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/number-systems-digital-logic)

## More in Database Management Systems

- [Relational Model and ER Design](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/relational-model-er)
- [SQL for Interviews](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/sql-for-interviews)
- [Normalization and Functional Dependencies](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/normalization)
- [Transactions, ACID and Concurrency Control](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/transactions-and-concurrency)
- [Indexing and Query Performance](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/indexing-and-query-optimization)
- [NoSQL Databases](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/nosql-databases)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [CS Fundamentals and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/cs-fundamentals)
