Skip to content

Databases

Scope

Persistent data storage systems, including relational (SQL) and NoSQL databases, and the strategies for scaling them.

Why This Topic Exists

The choice of a database and its scaling strategy are among the most critical decisions in system design. These choices fundamentally impact an application’s performance, scalability, consistency, and operational complexity.

Core Tradeoffs

  • Consistency vs. Availability: As captured in the CAP theorem and the ACID vs. BASE models.
  • Schema Rigidity vs. Flexibility: The strict schemas of SQL vs. the dynamic nature of NoSQL.
  • Read vs. Write Optimization: Different databases and indexing strategies are optimized for different access patterns.
  • Scaling Strategy: The tradeoffs between vertical scaling (scaling up) and horizontal scaling (scaling out) through techniques like replication, federation, and sharding.

Common Failure Modes

  • Replication Lag: Read replicas can have stale data, leading to inconsistent views for users.
  • Hot Partitions/Hot Spots: Uneven data distribution in a sharded database can overload specific shards.
  • Lock Contention: In transactional databases, excessive locks can lead to poor performance and deadlocks.
  • N+1 Query Problem: Inefficient data fetching in application code can lead to a storm of queries against the database.

Interview Signals

Strong candidates reason about database choices from the application’s access patterns and consistency requirements. They can articulate the tradeoffs between SQL and NoSQL, discuss various scaling strategies (sharding, replication), and explain concepts like consistent hashing and ACID vs. BASE.

  • Caching
  • CAP Theorem
  • Consistency
  • Scalability