Beyond Tables
NoSQL (Not Only SQL) databases are designed for specific use cases where relational databases aren't ideal โ massive scale, flexible schemas, or specialized data structures. They don't use SQL as their primary query language.
NoSQL Database Types
Document Store Key-Value Store
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโโโ
โ { โ โ "user:1"โ{name:Alice}โ
โ "_id": "123", โ โโโโโโโโโโโผโโโโโโโโโโโโค
โ "name": "Alice", โ โ "user:2"โ{name:Bob} โ
โ "age": 25, โ โโโโโโโโโโโผโโโโโโโโโโโโค
โ "courses": โ โ "sess:5"โ"abc123" โ
โ ["DB", "Net"] โ โโโโโโโโโโโดโโโโโโโโโโโโ
โ } โ Redis, DynamoDB
MongoDB, CouchDB
Column-Family Graph Database
โโโโโโโฌโโโโโโโโฌโโโโโโโ (Alice)โโknowsโโโ(Bob)
โ Row โ Col1 โ Col2 โ โ โ
โโโโโโโผโโโโโโโโผโโโโโโโค โ โ
โ 1 โ Alice โ 25 โ knows knows
โ 2 โ Bob โ 30 โ โ โ
โ 3 โ Carol โ 28 โ (Carol)โknowsโโ(Dave)
โโโโโโโดโโโโโโโโดโโโโโโโ
Cassandra, HBase Neo4j, ArangoDB
When to Use NoSQL
Use NoSQL when: Use SQL when:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Schema is evolving rapidly โ Data is highly structured
โ Massive horizontal scale โ Complex queries & JOINs
โ Real-time analytics โ ACID transactions needed
โ Simple key-value lookups โ Data consistency critical
โ Unstructured data โ Reporting & analytics
CAP Theorem
You can only guarantee TWO of three:
Consistency
/\
/ \
/ \
/ CA \
/________\
CP AP
CA: Consistency + Availability (traditional RDBMS)
CP: Consistency + Partition tolerance (MongoDB, HBase)
AP: Availability + Partition tolerance (Cassandra, DynamoDB)
In distributed systems, partition tolerance is required,
so you choose between consistency and availability.