Part 05 · Revision sheet
Database and Data Architecture
Key Terms
- Database — stores data durably, lets concurrent clients read/write without corrupting it, answers queries faster than a raw scan (→ 58)
- Normalization / denormalization — one fact, one place (eliminates update anomalies) vs. deliberate duplication for one measured read, with what stays in sync named explicitly (→ 63)
- NoSQL families — key-value (O(1) by key), document (nested, flexible schema), wide-column (partition-key-driven), graph (relationship-first traversal) (→ 61)
- Index (B-tree / hash / LSM) — B-tree: sorted, O(log n), supports range scans; hash: O(1) exact match only; LSM: append-optimized with background compaction (→ 64)
- Write-ahead log (WAL) — a write is logged and fsynced before it is acknowledged or applied — the basis of crash recovery and replication (→ 68)
- ACID — Atomicity, Consistency, Isolation, Durability: the transaction's all-or-nothing, invariant-respecting, non-interfering, crash-surviving contract (→ 69)
- Isolation anomaly — dirty read, non-repeatable read, phantom read, lost update, write skew — each ruled out by a specific isolation level, whose exact guarantees are engine-dependent (→ 70)
- MVCC — readers see a consistent snapshot as of transaction start; writers create new row versions instead of overwriting (→ 71)
- Replication lag — a follower is always some time behind the leader; a client can see stale data unless read-your-own-writes is provided (→ 72)
- Hot partition — one shard absorbing disproportionate load because of a poorly chosen shard key (→ 73)
- Consistent hashing — keys and nodes placed on one hash ring; a membership change moves only the keys near the changed node (→ 74)
- Source of truth — the one authoritative home for a fact; every cache, denormalized column, and replica is a derived copy (→ 81)
Decision Rules
- Model entities and relationship cardinalities before writing any
CREATE TABLE— cardinality mistakes become anomalies or awkward joins later (→ 59) - SQL is declarative — state the result and let the engine find the plan (→ 60)
- Default to relational; move to NoSQL only when access pattern, consistency need, or scale clearly points away from it (→ 62)
- Denormalize only one measured, named slow query at a time — never speculatively (→ 63)
- Read the query plan before changing anything; fix the most expensive node, then re-measure (→ 66)
- Reach for a dedicated search engine only once faceting, relevance tuning, or query volume outgrow database full-text search (→ 65)
- Diagnose storage-engine behavior from its shape: B-tree engines pay write cost in place (checkpoint spikes), LSM engines defer it to compaction (write stalls) (→ 67)
- Pick the weakest isolation level that is still correct for the operation, not the strongest by default (→ 70)
- Choose pessimistic locking for short, high-contention critical sections; optimistic concurrency for low-contention updates (→ 71)
- Scale up and add read replicas first; shard only once a single writer is measured, truly exhausted — sharding is a one-way door (→ 72, → 73)
- A distributed database buys back a familiar transactional model across nodes, but never the coordination cost itself — budget the extra latency and failure modes (→ 76)
- Size connection pools from measured concurrency and query time, checked against the database's real connection limit across every instance (→ 77)
- Reach for a time-series database when retention and downsampling would otherwise be hand-rolled on a general table (→ 78)
- Keep blobs in object storage and metadata in the database — never the reverse (→ 79)
- Treat an untested backup as not a backup — verify by restoring to a specific point in time (→ 80)
Numbers & Formulas
- Little's Law for pool sizing: concurrency ≈ arrival rate × service time — e.g. 200 req/s × 0.02s ≈ 4 in-flight connections (→ 77)
- Consistent hashing bounds key movement on a membership change to roughly 1/N of the keyspace, not nearly all of it (→ 74)
- Snowflake-style id: 41 bits timestamp + 10 bits node id + 12 bits sequence ⇒ up to 4,096 ids/ms per node (→ 75)
- B-tree search is O(log n); a hash index is O(1) exact-match only; an unindexed scan is O(n) (→ 64, → 58)
Traps
- Choosing NoSQL "for scale" at a few hundred writes/sec, then hand-building joins and multi-record consistency in application code (→ 62)
LIKE '%term%'on a large table — a full scan, no stemming, no ranking (→ 65)- Disabling or delaying fsync to improve throughput — an outage silently wipes writes the application believed were acknowledged (→ 68)
- Lost update: two transactions each read-modify-write the same row and one update is silently clobbered (→ 70)
- A denormalized or cached copy drifting from its source with no reconciliation process to catch it (→ 81)
Self-Quiz
Mark the questions you can explain and choose which topics to revisit.
Answers are available for this page visit. Browser storage is unavailable.
-
Can you justify a denormalization with a specific, measured slow query, not a hunch? (no → revisit 63)
-
Can you defend a SQL-vs-NoSQL choice for a new workload in under a minute using the access-pattern/consistency/scale checklist? (no → revisit 62)
-
Can you read an
EXPLAIN ANALYZEoutput and name the single most expensive step? (no → revisit 66) -
Can you name the anomaly in a given concurrent interleaving and the weakest isolation level that rules it out? (no → revisit 70)
-
Can you write a one-line lifecycle statement (source, retention, deletion, reconciliation) for any data category? (no → revisit 81)