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.
- 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.
- Run
python capstone.py --reconcile. Compare. - If you were wrong, identify which of three things it was: a transcription error, an arithmetic slip, or a rule you did not apply.
- 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 · 🧪
- Change
RULE_GIFT_CARDS_CENTSby one cent. Run--self-check. How many assertions fail, and which ones? - Change
TARGET_LINESby 1,000. Which assertions fail now? Note that the ratio assertions fail before the total ones do. - Change the Black Friday multiplier from 4.6195 to 6.28 — the mistake §38.3 describes. Does the reconciliation still close? Why?
- §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.
- Name three more rules a real e-commerce reconciliation would need. Candidates: shipping revenue, taxes, currency conversion, employee discounts, partial shipments, chargebacks.
- For each: does it filter rows or revalue them? (§38.5's 📐.)
- For each: who owns it? If the answer is "the data team," check that answer twice.
- 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.
- Write the order-count reconciliation for the capstone month, and confirm it gives 289,389.
- Write the SCD Type 2 assertion: exactly one current row per customer.
- Construct a defect that the money reconciliation misses and the count catches. (Hint: fan-out at half price.)
- Construct one that the count misses and the money catches.
- §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.
- Rebuild your platform from raw into a scratch schema.
- Diff every gold table row by row, not just the reconciliation total. Case Study 2's cause 3 was invisible to the total.
- Record every difference. Expect at least one.
- For each: is it a non-deterministic tie-break, an undeclared input, or an impure model?
- 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.
- Write
purity.py. A model may not userequests,urllib,socket, a cloud SDK,now(),current_timestamp,random, or read a relation outside the project. - Run it against your models. How many violations?
- 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).
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.
- Price your nightly build on your own rate card, component by component.
- Compute cost per unit and cost as a share of the revenue it reports.
- Draw the critical path and compute your slack against your SLA.
- Now compute it for your peak day. Which component does not scale? Kestrel's quality register goes from 8% to 13% of the path.
- §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%.
- Pull a month of your own assertion fires. Classify each: real defect, correct-and-not-a-defect, or false positive.
- Compute your rate. §38.11 argues 52% is roughly right and that a much higher rate is a warning. Do you agree?
- Which of your categories produced no defects? Are they doing their job (freshness) or are they noise?
- 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.
- Answer all five for your platform, using only artifacts — no people.
- How many required a person? Kestrel's needed one for the fourth.
- Hand your README to someone who has not seen the project. Watch them and do not help. Record every point at which they stop.
- Fix the top three stopping points.
Exercise 38.10 — The "not done" list
Difficulty: ★★☆ · Time: 40 minutes
§38.12's 📐.
- Write yours. Every deferred item, with a why.
- For each, mark whether the why is a decision ("nobody has asked") or a shortfall ("we ran out of time"). Label them differently.
- Cite the chapter that justifies each decision.
- §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:
- The order and customer reconciliations (§38.8), asserting 289,389.
- A second month — December 2026 — and the R4 restatement of November it produces.
- A materiality report: which rules would change the answer by more than 0.1%?
- A shape assertion suite (§38.13): peak on the right day, weekends lighter, the two ratios agreeing.
- A
--as-offlag, so the November figures can be computed as of any date and the convergence shown. - 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.
- Pick a reported number. Reconcile it to its source, for one month, to the cent.
- Write down every rule that makes them differ, before you run the comparison.
- Run it. How many rules did you miss? Kestrel missed four of four on the first attempt.
- For each missed rule: who owns it, and was that ever asked?
- 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.
- Write the case for stopping, as strongly as you can.
- Write the rebuttal. §"Design Decision" gives three parts; find a fourth.
- Where is the line? Write your organization's rule for when a reconciliation difference is chased.
- 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.
- Assemble every component (§38.2), running from nothing.
- Run all five verification steps before the reconciliation.
- Reconcile one month to the cent, with every difference expressed as a documented, owned, tested rule.
- Reconcile a second property — orders or customers (§38.8).
- Rebuild from raw and diff row by row (§38.9). Record what it finds.
- Price it and time it (§38.10), including peak-day slack.
- Produce the six handover artifacts (§38.12), including the "not done" list.
- Schedule the reconciliation so it runs monthly and fails loudly.
- 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.