Exercises: Capstone

This chapter's exercises are the capstone. They are longer than any other chapter's and they are meant to be done in order. Exercises marked 🧪 use code/capstone.py.

Do Exercise 38.1 before reading §38.7.


The Reconciliation

Exercise 38.1 — Predict, then compute

Difficulty: ★★☆ · Time: 45 minutes · 🧪

Do this before reading §38.7.

  1. From §38.4's source figures and §38.5's four rules, compute on paper: gold line count, gold gross revenue, and gold net revenue.
  2. Run python capstone.py --reconcile. Compare.
  3. If you were wrong, identify which of three things it was: a transcription error, an arithmetic slip, or a rule you did not apply.
  4. Run python capstone.py --self-check. 38 assertions. Read the ones about internal consistency (§38.7's 🔎) and say what each is protecting against.

Exercise 38.2 — Break the fixture

Difficulty: ★★☆ · Time: 40 minutes · 🧪

  1. Change RULE_GIFT_CARDS_CENTS by one cent. Run --self-check. How many assertions fail, and which ones?
  2. Change TARGET_LINES by 1,000. Which assertions fail now? Note that the ratio assertions fail before the total ones do.
  3. Change the Black Friday multiplier from 4.6195 to 6.28 — the mistake §38.3 describes. Does the reconciliation still close? Why?
  4. §38.13 says a correct total concealed a distribution error for the whole build. Which assertion catches #3, and what class of check does it belong to?

Exercise 38.3 — Write the fifth rule

Difficulty: ★★☆ · Time: 45 minutes

Kestrel has four rules. Most real platforms have six to ten.

  1. Name three more rules a real e-commerce reconciliation would need. Candidates: shipping revenue, taxes, currency conversion, employee discounts, partial shipments, chargebacks.
  2. For each: does it filter rows or revalue them? (§38.5's 📐.)
  3. For each: who owns it? If the answer is "the data team," check that answer twice.
  4. Which of your three makes a closed month mutable? Those are the ones that change your architecture.

Verification

Exercise 38.4 — Reconcile more than money

Difficulty: ★★☆ · Time: 60 minutes

§38.8: four reconciliations, four blind spots.

  1. Write the order-count reconciliation for the capstone month, and confirm it gives 289,389.
  2. Write the SCD Type 2 assertion: exactly one current row per customer.
  3. Construct a defect that the money reconciliation misses and the count catches. (Hint: fan-out at half price.)
  4. Construct one that the count misses and the money catches.
  5. §38.8 says "add the row count" is an hour of work that roughly doubles coverage. Do it for one reconciliation you own.

Exercise 38.5 — Rebuild it

Difficulty: ★★★ · Time: 2–3 hours

§38.9 and Case Study 2.

  1. Rebuild your platform from raw into a scratch schema.
  2. Diff every gold table row by row, not just the reconciliation total. Case Study 2's cause 3 was invisible to the total.
  3. Record every difference. Expect at least one.
  4. For each: is it a non-deterministic tie-break, an undeclared input, or an impure model?
  5. Write the project-wide audit for whichever class you found. Case Study 2's found 4 of 31 window functions.

Exercise 38.6 — The purity check

Difficulty: ★★★ · Time: 60 minutes

Case Study 2's durable fix.

  1. Write purity.py. A model may not use requests, urllib, socket, a cloud SDK, now(), current_timestamp, random, or read a relation outside the project.
  2. Run it against your models. How many violations?
  3. For each violation, decide: remove it, declare it as an input, or suppress it with a reason and a date (§34.13's expiring suppression).
  4. now() is the interesting one. What legitimate use does banning it block, and what is the correct replacement?

The Platform

Exercise 38.7 — Price it and time it

Difficulty: ★★☆ · Time: 45 minutes

§38.10.

  1. Price your nightly build on your own rate card, component by component.
  2. Compute cost per unit and cost as a share of the revenue it reports.
  3. Draw the critical path and compute your slack against your SLA.
  4. Now compute it for your peak day. Which component does not scale? Kestrel's quality register goes from 8% to 13% of the path.
  5. §38.10 warns against quoting the pipeline cost as the platform cost. Compute both, and note the ratio.

Exercise 38.8 — Read your register

Difficulty: ★★☆ · Time: 40 minutes

§38.11: 29 fires, 15 defects, 52%.

  1. Pull a month of your own assertion fires. Classify each: real defect, correct-and-not-a-defect, or false positive.
  2. Compute your rate. §38.11 argues 52% is roughly right and that a much higher rate is a warning. Do you agree?
  3. Which of your categories produced no defects? Are they doing their job (freshness) or are they noise?
  4. Kestrel's volume band was set from ordinary days and fired five times on Black Friday. Check your seasonal bands.

Exercise 38.9 — The five questions

Difficulty: ★★☆ · Time: 60 minutes

§38.12's 🎓: how do I run it · which table · is this number right · what if I break it · who do I ask.

  1. Answer all five for your platform, using only artifacts — no people.
  2. How many required a person? Kestrel's needed one for the fourth.
  3. Hand your README to someone who has not seen the project. Watch them and do not help. Record every point at which they stop.
  4. Fix the top three stopping points.

Exercise 38.10 — The "not done" list

Difficulty: ★★☆ · Time: 40 minutes

§38.12's 📐.

  1. Write yours. Every deferred item, with a why.
  2. For each, mark whether the why is a decision ("nobody has asked") or a shortfall ("we ran out of time"). Label them differently.
  3. Cite the chapter that justifies each decision.
  4. §38.12 says the list prevents a new engineer spending three weeks on a deliberate choice. Which item on your list is most likely to be mistaken for an oversight?

Advanced

Exercise 38.11 — Extend the capstone

Difficulty: ★★★ · Time: 90 minutes · 🧪

Add three to capstone.py, with self-checks:

  1. The order and customer reconciliations (§38.8), asserting 289,389.
  2. A second month — December 2026 — and the R4 restatement of November it produces.
  3. A materiality report: which rules would change the answer by more than 0.1%?
  4. A shape assertion suite (§38.13): peak on the right day, weekends lighter, the two ratios agreeing.
  5. A --as-of flag, so the November figures can be computed as of any date and the convergence shown.
  6. A deliberate defect injector, so a reader can practise diagnosing a gap.

Then: #5 is the one that teaches the most. Plot November's net revenue as of each date from 1 December to 1 March and describe the curve.


Exercise 38.12 — Reconcile a real system

Difficulty: ★★★ · Time: 3–4 hours

The exercise that matters most in this chapter, if you have access to a real platform.

  1. Pick a reported number. Reconcile it to its source, for one month, to the cent.
  2. Write down every rule that makes them differ, before you run the comparison.
  3. Run it. How many rules did you miss? Kestrel missed four of four on the first attempt.
  4. For each missed rule: who owns it, and was that ever asked?
  5. Add the pull-request question from Case Study 1's 📐 to your repository.

Exercise 38.13 — Argue about materiality

Difficulty: ★★★ · Time: 45 minutes

Case Study 2's team spent twelve days on $741.18.

  1. Write the case for stopping, as strongly as you can.
  2. Write the rebuttal. §"Design Decision" gives three parts; find a fourth.
  3. Where is the line? Write your organization's rule for when a reconciliation difference is chased.
  4. Case Study 2 claims a reproducibility failure has no materiality threshold. Construct the exception — a case where you would accept a non-zero rebuild difference — and decide whether it survives.

The Capstone Itself

Exercise 38.14 — Finish the platform

Difficulty: ★★★ · Time: 8–12 hours

This is the deliverable for the whole book.

  1. Assemble every component (§38.2), running from nothing.
  2. Run all five verification steps before the reconciliation.
  3. Reconcile one month to the cent, with every difference expressed as a documented, owned, tested rule.
  4. Reconcile a second property — orders or customers (§38.8).
  5. Rebuild from raw and diff row by row (§38.9). Record what it finds.
  6. Price it and time it (§38.10), including peak-day slack.
  7. Produce the six handover artifacts (§38.12), including the "not done" list.
  8. Schedule the reconciliation so it runs monthly and fails loudly.
  9. Write the retrospective (§38.14): what you would do differently, in four items.

Deliverable: a repository someone else can clone and run, whose gold layer reconciles to its source, with a rebuild log, a cost model, a runbook, a catalog, and an honest list of what is not done.

The acceptance criterion has not changed since Chapter 1 §1.7, and it is the only thing being graded:

For any calendar month, total net revenue computed from the gold layer equals total net revenue computed directly from the source database, to the cent — and every difference is explained by a documented, tested rule rather than discovered after the fact.

Two things distinguish a finished capstone from a working one. The rebuild log — which should contain a failure, because a rebuild that succeeds first time usually means you rebuilt from something already materialized. And the "not done" list, which should not be empty, because a platform whose author claims nothing was deferred has not looked.