System Design Visualized
Module C2 · about 50 minutes

Databases in Depth

"Which database would you use, and why?" is in almost every interview. A strong answer talks about the data model, the access patterns, the consistency you need and how it scales, not brand names. This chapter gives you those tools.

Start the interactive chapter
  1. C2.1Choosing a database by access patternRelational (PostgreSQL, MySQL) Key-value / wide-column (DynamoDB, Cassandra) Document (MongoDB) Data model Tables, schemas, joins Key →…
  2. C2.2Indexes: why lookups are fast (and writes slower)Without an index, SELECT * FROM users WHERE email = ? scans every row: O(n). An index is a separate sorted structure (usually a B-tree)…
  3. C2.3Transactions and isolationACID: a transaction is Atomic (all or nothing), keeps data Consistent (constraints hold), is Isolated from concurrent transactions, and…
  4. C2.4Replication lag and read-your-writesWith leader-follower replication (Chapter 1), writes go to the leader and are copied to followers asynchronously, usually within…
  5. C2.5Partitioning strategiesStrategy How Good Watch out Range Rows with keys A–F on shard 1, G–M on shard 2… Range scans ("orders in March") are efficient Hotspots:…