DATABASES
Home
SQL NoSQL Indexes Scaling

Databases

Interview-ready guide: modeling, indexing, transactions, performance, replication, partitioning — with real traps.

1. SQL vs NoSQL (choose by access patterns)

Senior answers start with: “What are the query patterns and consistency requirements?”

SQL (Relational)

  • Strong constraints, joins, transactions (ACID).
  • Best for: orders, payments, inventory, permissions.
  • Scaling: indexes → read replicas → partitioning → sharding.

NoSQL (Document / KV / Wide-column)

  • Flexible schema, high throughput, simpler horizontal scaling.
  • Best for: sessions, caches, feeds, event logs, user profiles.
  • Trade-off: joins/transactions are limited or more complex.

🚨 Trap: “NoSQL is faster”

The fastest database is the one that matches your access patterns and indexes. A bad data model is slow everywhere.

2. Data Modeling (normalize, then denormalize intentionally)

Normalize (3NF)

  • Reduces duplication, improves integrity.
  • Great for OLTP core data.
  • Trade-off: joins can cost performance at scale.

Denormalize (read models)

  • Faster reads, fewer joins.
  • Great for feeds/search/materialized views.
  • Trade-off: updates are harder (eventual consistency).