Neural Sync Active
NoSQL Databases
Registry Synced
NoSQL Databases
319 words
2 min read
Reading compass
Now · 🎯 Learning Objectives
NoSQL Databases
🎯 Learning Objectives
- Compare SQL and NoSQL databases
- Understand the CAP theorem and its implications
- Choose the right NoSQL database for a use case
- Design documents for MongoDB
📖 Core Content
5.1 SQL vs NoSQL
| Aspect | SQL (Relational) | NoSQL |
|---|---|---|
| Data model | Tables, rows, columns | Document, key-value, graph, column |
| Schema | Fixed (requires migration) | Flexible (schema-on-read) |
| Scalability | Vertical (scale up) | Horizontal (scale out) |
| ACID | Yes | Often BASE (eventual consistency) |
| Joins | Yes | No (denormalized) |
| Best for | Complex queries, consistency | High volume, flexible schema |
5.2 CAP Theorem
A distributed database can only guarantee two of three:
- Consistency: Every read gets the most recent write
- Availability: Every request gets a response (even if outdated)
- Partition tolerance: System works despite network failures (Diagram)
5.3 NoSQL Types
| Type | Example | Use Case | Data Model |
|---|---|---|---|
| Document | MongoDB | Content management, catalogs | JSON documents |
| Key-Value | Redis | Caching, session store | Key → value pairs |
| Column-Family | Cassandra | Time-series, IoT | Row key → columns |
| Graph | Neo4j | Social networks, recommendations | Nodes and edges |
📝 Practice Questions
Q1: When would you choose MongoDB over PostgreSQL?Choose MongoDB when: (1) data has varying schemas (product catalog where different products have different attributes), (2) you need fast prototyping without migrations, (3) you're scaling horizontally across many servers. Choose PostgreSQL when: (1) data is highly relational, (2) you need ACID transactions, (3) complex queries with JOINs are common. Q2: What does "eventual consistency" mean?In distributed systems, updates propagate asynchronously. After a write, reads may see old data for a brief period, but all replicas will eventually converge to the same value. Typical in AP systems (Cassandra, DNS). Tradeoff: higher availability and partition tolerance at the cost of temporary inconsistency. Q3: When is a graph database the right choice?When the relationships between data are as important as the data itself. Examples: social network (users + friendships), recommendation engine (customers + products + purchases), fraud detection (accounts + transactions). Graph DBs excel at traversal queries like "find all friends of friends within 3 degrees." Join Discord PreviousBig Data: Hadoop & SparkNextData Governance