Skip to content

Databases

Every system keeps its data somewhere, and the choice of database sets what the rest of the system finds cheap. A data model decides which questions are quick to ask. A storage engine decides how often the disk is written and what a crash can lose. An index decides whether a query reads five pages or a hundred thousand. A copy of a fact decides how many places must change together. A connection pool decides how many queries can run at once. This module takes those one at a time, and asks the same question of each: what does it make cheap, and what do you pay for that.

You will compare five kinds of database in a trade-off explorer, sort workloads, storage ideas, queries and values into the categories they belong to, count page reads by hand, and run a connection pool as a queue to see what slower queries and a leaked connection do to it. Every lesson has a “what happens if” moment.

  1. Choosing a data model by access pattern (20 min). Relational, document, key-value, wide-column and graph stores, what each makes cheap, and why no model meets every requirement.
  2. Storage engines: B-trees, LSM-trees and the write-ahead log (20 min). How a database lays data out on disk, why it writes a log first, and what a commit promises.
  3. Indexing and query plans (20 min). How few pages an index needs, what it costs every write, why the planner sometimes ignores it, and how to read a plan.
  4. Normalisation and denormalisation (16 min). One copy of each fact or a copy where it is read, what each costs, and the values that only look like copies.
  5. Connection pools (18 min). A pool as a queue, what slow queries and leaks do to it, why more connections is not more capacity, and how to budget them.
  6. Recap and quiz (12 min). The module in one page, a checklist for the data layer, and a quiz.
  • Describe a workload by its access pattern, and choose a data model for it while naming the cost you accept.
  • Say what a B-tree, an LSM-tree and a write-ahead log each do, and what a commit does and does not promise.
  • Work out how many pages a scan and an index lookup read, decide whether an index will help, and read a query plan.
  • Decide which copies of a fact to keep and which values are different facts, and say what each copy costs.
  • Size a connection pool and a fleet’s connection budget, and say what to check first when a pool runs out.

All the numbers in the labs are illustrative. They are for comparing choices, not for forecasting any real product.

Built by GhaziAlibi.

© ShardCraft. All rights reserved.