Course map

Part 05

Database and Data Architecture

Choose, model, scale and protect a data store, and manage data through its whole life.

Prerequisites Parts 2–4.
Part context

Cross-references: schema changes without downtime → 189; disaster recovery → 195; consistency guarantees → 129.

Reading track

5.1 Data Modeling and Relational Databases

Chapter outcomes and context

Topics covered: 58 Database fundamentals (Core) · 59 Data modeling and entity relationships (Core) · 60 SQL and relational databases (Core) · 63 Normalization and denormalization (Core)

Learning outcomes

  • Model a domain as entities, attributes, and relationships (1:1, 1:N, M:N) and translate the model into tables with keys and constraints — including history and audit tables where the domain changes over time (Project 1).
  • Write competent SQL: joins, aggregation, subqueries, window-function awareness.
  • Normalize to third normal form to eliminate update anomalies; denormalize deliberately for read performance, accepting the write-side cost of keeping copies consistent.

Key concepts: primary and foreign keys, constraints, ER diagrams, 1NF–3NF, views and materialized views.

058Database fundamentalsCore059Data modeling and entity relationshipsCore060SQL and relational databasesCore063Normalization and denormalizationCore

5.2 NoSQL and Database Selection

Chapter outcomes and context

Topics covered: 61 NoSQL databases: key-value, document, wide-column, graph (Core) · 62 Choosing SQL vs NoSQL (Core)

Learning outcomes

  • Know the four NoSQL families and their shapes: key-value (Redis, DynamoDB as examples — O(1) access by key, no query flexibility), document (MongoDB — nested documents, flexible schema), wide-column (Cassandra — partition-key-driven, write-optimized, tunable consistency), graph (Neo4j — relationship-first queries).
  • Select by access pattern, consistency need, and scale — not fashion. Relational is the default; NoSQL earns its place when the access pattern is known, key-driven, and must scale horizontally, or the data is genuinely schemaless.

When not to use NoSQL: choosing it "for scale" at a hundred writes per second, then rebuilding joins and transactions by hand in application code.

061NoSQL databases: key-value, document, wide-column, graphCore062Choosing SQL vs NoSQLCore

5.3 Indexing, Search, and Query Performance

Chapter outcomes and context

Topics covered: 64 Indexing: B-tree, hash and LSM-tree; composite, covering and partial indexes (Core) · 65 Full-text search basics: database full-text search, when a search engine is needed (Core — large scale → 209) · 66 Query execution and optimization (Core)

Learning outcomes

  • Explain how a B-tree index works (sorted, balanced, O(log n), range scans and prefix matches) vs. a hash index (O(1), exact match only) vs. an LSM-tree (append- optimized, compaction — the write-optimized shape behind Cassandra and RocksDB; engine view → 67).
  • Design composite indexes around the leftmost-prefix rule; use covering indexes (the index answers the query alone) and partial indexes (index only the rows that matter).
  • Use database full-text search (primary home of search basics): tokenization, stemming, relevance ranking as the built-in engines provide them — adequate for catalogs and content at moderate scale (Project 5's baseline). Know the signals that a dedicated search engine is needed — index size, faceting depth, relevance tuning, query volume (→ 209).
  • Read a query plan (EXPLAIN): sequential vs. index scan, join strategies, why the optimizer's row estimates matter.
  • State the cost of indexes: every write maintains every index; indexes consume memory.
064Indexing: B-tree, hash and LSM-tree; composite, covering and partial indexesCore065Full-text search basics: database full-text search, when a search engine is needed (large scale → 209)Core066Query execution and optimizationCore

5.4 Engines, Durability, Transactions, and Concurrency

Chapter outcomes and context

Topics covered: 67 Storage engine fundamentals: pages, compaction, checkpoints (Advanced) · 68 Write-ahead logging and durability (Advanced) · 69 ACID properties (Core) · 70 Transactions and isolation levels: transaction boundaries, isolation anomalies (Core) · 71 Concurrency control: MVCC, optimistic and pessimistic locking (Advanced)

Learning outcomes

  • (Advanced) Contrast B-tree engines (read-optimized, in-place pages, periodic checkpoints) with LSM engines (write-optimized, append plus compaction), and explain write-ahead logging: the change is logged durably before it is applied — the basis of crash recovery and replication.
  • Define ACID precisely; draw transaction boundaries consciously (one business operation = one transaction — not one statement, not one request); map the isolation levels (read uncommitted → read committed → repeatable read → serializable) to the anomalies each prevents (dirty read, non-repeatable read, phantom, lost update, write skew).
  • (Advanced) Apply concurrency control: MVCC (readers see a snapshot without blocking writers), pessimistic locking (SELECT … FOR UPDATE), optimistic concurrency (version column, retry on conflict) — the heart of Projects 1 and 7.
067Storage engine fundamentals: pages, compaction, checkpointsAdvanced068Write-ahead logging and durabilityAdvanced069ACID propertiesCore070Transactions and isolation levels: transaction boundaries, isolation anomaliesCore071Concurrency control: MVCC, optimistic and pessimistic lockingAdvanced

5.5 Distributing Data

Chapter outcomes and context

Topics covered: 72 Replication: leader–follower, multi-leader, leaderless, replication lag (Core) · 73 Partitioning and sharding: shard keys, hot partitions, resharding, rebalancing (Core) · 74 Consistent hashing (Core) · 75 Unique ID generation (Core) · 76 Distributed database fundamentals (Advanced)

Learning outcomes

  • Design replication (primary home): leader–follower (sync vs. async, replication lag and read-your-own-writes), multi-leader (write conflicts must be resolved), leaderless (quorum-based → 130). Failover risks: lost writes, split brain.
  • Shard deliberately: choose a shard key for even load and single-shard queries; know the failure modes — hot partitions, celebrity keys, cross-shard queries — and the operational reality of resharding and rebalancing.
  • Apply consistent hashing (primary home): keys and nodes on a hash ring, virtual nodes for balance; membership change moves only ~1/N of keys — the mechanism behind distributed caches and Dynamo-style stores (Capstone).
  • Design unique ID generation: auto-increment (single point, no cross-shard ordering), UUIDv4 (random, index-unfriendly), snowflake-style (timestamp + node + sequence: sortable, decentralized — Projects 2 and 13).
  • (Advanced) Know what distributed SQL gives up and buys back (global transactions at latency cost — Spanner and CockroachDB as examples).

Decision rule: scale up and add read replicas first; shard only when a single writer is truly exhausted. Sharding is a one-way door.

072Replication: leader–follower, multi-leader, leaderless, replication lagCore073Partitioning and sharding: shard keys, hot partitions, resharding, rebalancingCore074Consistent hashingCore075Unique ID generationCore076Distributed database fundamentalsAdvanced

5.6 Operational Storage and the Data Lifecycle

Chapter outcomes and context

Topics covered: 77 Connection pooling: pool sizing, pool saturation, connection limits (Core) · 78 Time-series databases (Advanced) · 79 Object storage and file storage: multipart and resumable uploads, checksums (Core) · 80 Backup and restore: point-in-time recovery, restore testing (Core) · 81 Data lifecycle: source of truth, retention, archival, deletion, integrity constraints, reconciliation (Core)

Learning outcomes

  • Explain why connection pooling is mandatory (connections are expensive; databases enforce hard limits); size pools from concurrency math (→ 101) and recognize pool saturation as a classic hidden bottleneck (→ 103).
  • (Advanced) Recognize the time-series workload — append-heavy, time-ordered, range-scanned, downsampled and expired by age — and why dedicated stores handle it better than a general table (Project 19; metrics → 201).
  • Use object storage (S3-style: HTTP API, flat namespace, very high durability, low cost, higher latency) for blobs, with multipart and resumable uploads and checksums for integrity (Projects 17–18); keep only metadata in the database.
  • Design backups: full plus incremental, point-in-time recovery from WAL archives (→ 68), and restore testing — an untested backup is not a backup.
  • Manage the data lifecycle (primary home): name the source of truth for every piece of data and make every copy derived; set retention and archival rules; implement deletion that actually deletes (including derived copies); enforce integrity constraints; run reconciliation — periodic comparison between systems that must agree (inventory vs. ledger vs. provider reports; Projects 7, 8, 9).
077Connection pooling: pool sizing, pool saturation, connection limitsCore078Time-series databasesAdvanced079Object storage and file storage: multipart and resumable uploads, checksumsCore080Backup and restore: point-in-time recovery, restore testingCore081Data lifecycle: source of truth, retention, archival, deletion, integrity constraints, reconciliationCore

Done when you can

  • Design a schema, index it from the query patterns, and read the plans that prove it.
  • Add adequate full-text search without reaching for a search cluster.
  • Pick isolation and locking strategies for concurrent money or inventory updates.
  • Explain exactly what breaks when you add replicas, and then when you shard.
  • Name the source of truth, retention rule, and reconciliation check for every store.
Open revision sheet and self-quiz

Projects after Part 5

Search the guide