One-liner: SQL databases store data in structured tables with strict schemas; NoSQL databases trade strict consistency for flexibility and horizontal scalability.
π SQL (Relational Databases)
Core Properties
- Structured β Data in tables with rows and columns
- Schema β Fixed structure, must be defined upfront
- ACID β Atomicity, Consistency, Isolation, Durability
- Relations β Foreign keys, JOINs across tables
- Query Language β SQL (standardized)
Examples
| Database | Best For |
|---|---|
| PostgreSQL | Complex queries, JSONB support, general purpose |
| MySQL | Web apps, e-commerce |
| SQLite | Local/embedded, mobile apps |
| Oracle | Enterprise, banking |
| MS SQL Server | Microsoft ecosystem |
When to Use SQL
- β Complex queries with JOINs
- β Strong consistency required (banking, payments)
- β Data is relational by nature (users β orders β products)
- β ACID transactions needed
- β Data structure is well-known and unlikely to change
π NoSQL (Non-Relational Databases)
Core Properties
- Flexible schema β Add/remove fields without migrations
- Horizontally scalable β Designed to scale out
- Eventual consistency β Usually (some offer strong consistency)
- Optimized for specific access patterns
Types of NoSQL
1. Document Store
// MongoDB, CouchDB, Firestore
{
"_id": "user_123",
"name": "Rahul",
"address": { "city": "Delhi", "pin": "110001" },
"tags": ["premium", "verified"]
}
Best for: User profiles, product catalogs, CMS
2. Key-Value Store
Redis, DynamoDB, Memcached
"session:abc123" β { userId: 42, expiry: ... }
"counter:pageviews" β 1000000
Best for: Sessions, caching, real-time counters, leaderboards
3. Column-Family Store
Cassandra, HBase
Row key β { column1: val, column2: val, column3: val }
Best for: Time-series data, IoT, write-heavy workloads, Netflix viewing history
4. Graph Database
Neo4j, Amazon Neptune
Nodes (Person) β Edges (FOLLOWS) β Nodes (Person)
Best for: Social networks, fraud detection, recommendation engines
βοΈ The Comparison
| Dimension | SQL | NoSQL |
|---|---|---|
| Schema | Fixed | Flexible |
| Horizontal scaling | Hard | Easy |
| Transactions | Full ACID | Often eventual consistency |
| JOINs | Easy | Avoid (denormalize) |
| Query flexibility | High (SQL) | Limited to access patterns |
| Learning curve | Moderate | Varies by type |
| Maturity | 50+ years | 15β20 years |
π ACID vs BASE
ACID (SQL)
| Property | Meaning |
|---|---|
| Atomicity | All or nothing β transaction either fully succeeds or fully fails |
| Consistency | DB always goes from one valid state to another |
| Isolation | Concurrent transactions don't interfere |
| Durability | Once committed, data survives crashes |
BASE (NoSQL)
| Property | Meaning |
|---|---|
| Basically Available | System always responds (maybe stale data) |
| Soft state | State can change over time, even without input |
| Eventually consistent | System will eventually be consistent |
ποΈ Choosing Between SQL and NoSQL
Decision Tree:
Is the data relational?
βββ Yes β SQL (start here)
βββ No β
Do you need flexible schema?
βββ Yes β Document (MongoDB)
βββ No β
Is it write-heavy time-series?
βββ Yes β Column (Cassandra)
βββ No β
Is it graph-traversal heavy?
βββ Yes β Graph (Neo4j)
βββ No β Key-Value (Redis/DynamoDB)
π Real-World Usage Patterns
| Company | SQL | NoSQL |
|---|---|---|
| Uber | PostgreSQL (trips) | Cassandra (location updates) |
| Netflix | MySQL (billing) | Cassandra (viewing history) |
| PostgreSQL (user data) | Redis (feed cache) | |
| MySQL | Redis (timeline), Cassandra (tweets) | |
| Airbnb | MySQL | ElasticSearch (search) |
Most large systems use both β polyglot persistence!
π Key Takeaways
- Default to SQL for new projects β better tooling, stronger guarantees
- Move to NoSQL when you hit specific scale/flexibility walls
- Most production systems use both (polyglot persistence)
- NoSQL doesn't mean "no schema" β you still have implicit structure








![[System Design] GraphHopper Distance Matrix: Self-Host OSRM vs Haversine for Route Optimization](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyoo5j6x1kubw2zbx6ayz.png)




