Components

Database Decision Tree

🌳 Quick Decision Flow

Do you need ACID transactions?

YES → SQL Database (PostgreSQL, MySQL)
NO → Continue to next question

Is your data highly structured with relationships?

YES → SQL Database
NO → Consider NoSQL

What's your access pattern?

Key-Value → Redis, DynamoDB
Document → MongoDB
Wide-column → Cassandra

Need full-text search?

YES → Elasticsearch / OpenSearch
BASIC → PostgreSQL full-text

Database Comparison Matrix

DatabaseTypeScalingConsistencyBest For
PostgreSQLSQLVerticalStrongComplex queries, ACID
MySQLSQLVerticalStrongGeneral purpose, mature
MongoDBDocumentHorizontalTunableFlexible schema, documents
CassandraWide-colHorizontalEventualWrite-heavy, time-series
DynamoDBKey-ValueHorizontalEventualServerless, simple access
RedisKey-ValueClusterStrongCaching, sessions, queues
ElasticsearchSearchHorizontalEventualFull-text search, logs

Use Case Quick Reference

🏦 Financial / E-commerce

Need: ACID, consistency, complex queries

→ PostgreSQL / MySQL

📱 User Profiles / Content

Need: Flexible schema, embedded data

→ MongoDB

📊 Analytics / Time-Series

Need: High write throughput, append-only

→ Cassandra / InfluxDB

⚡ Caching / Sessions

Need: Low latency, simple key access

→ Redis

🔍 Search / Logs

Need: Full-text search, aggregations

→ Elasticsearch

🌐 Social Graph

Need: Relationships, graph traversal

→ Neo4j / Amazon Neptune

🎯 Interview Template

"I would choose [database] for this use case because [1-2 key reasons]. The main trade-off is [limitation], but that's acceptable for [this scenario] because [justification]."