Databases
Database track: design and tune a production schema
The track taught seven moments of database failure in isolation. This capstone makes you live through all of them on one product: a multi-tenant order system that grows from an MVP table to a sharding decision. You will design the schema, prove the indexes, read the plans, defend the bound, and migrate it — with measurements at every gate.
Turn the whole track into one reproducible engineering loop on a single schema: model for integrity, index for the real access pattern, diagnose plans from statistics, choose isolation against actual anomalies, size the pool from concurrency math, sequence a breaking change with expand-contract, and make an evidence-backed shard-or-not call.
Design, load, and tune a production-shaped multi-tenant PostgreSQL schema for an order/ledger system, then carry it through one breaking migration and a documented shard-or-not decision — proving every step with EXPLAIN ANALYZE output and before/after numbers, not assertions.
- A schema DDL file plus a one-paragraph rationale per non-obvious modeling choice (key type, each constraint, the one denormalization/JSONB tradeoff and its new owner).
- For every index: paired EXPLAIN ANALYZE output (before/after) showing the scan change and actual time, not estimated cost alone.
- The forced bad plan captured with its estimated-vs-actual row gap, and the post-fix plan showing the join flip and the lower runtime.
- A reproducible two-session demo of the concurrency anomaly and its fix, with the isolation-or-locking decision and its tradeoff written down.
- Pool-sizing math written out, plus evidence (logs or metrics) that PgBouncer transaction mode absorbed the connection storm that direct connections could not.
- The migration runbook with each expand-contract phase, the batched-backfill approach, and proof (lock_timeout settings + pg_locks observation) that no phase queued behind a long table lock.
- A shard decision memo: the measured single-node ceiling, the lever-exhaustion order, the chosen shard key with co-location reasoning, and the hot-shard mitigation.
- Add a triage runbook that maps each of the track's seven failure modes (schema, index, statistics, bloat, pooling, migration, sharding) to its first diagnostic query and first fix — your on-call cheat sheet.
- Reproduce the long-transaction bloat scenario: hold one transaction open, run heavy updates, show the table growing and VACUUM failing to reclaim, then prove the fix by ending the transaction and re-running VACUUM.
- Add a CI gate that runs EXPLAIN on the top queries against a seeded database and fails the build if any plan regresses to a seq scan or the estimated/actual row ratio exceeds a threshold.
- Stand up a 2-node Citus (or partitioned) version of the largest table and re-run the write load test, comparing throughput and cross-shard query cost against the single node.
This is the loop you run for the lifetime of a real database: model for integrity and bend only with a named tradeoff, index for the access pattern and prove it with EXPLAIN, treat row estimates as the planner’s load-bearing input, choose isolation against the specific anomaly you can demonstrate, size the pool from concurrency math and multiplex heavy backends, migrate breaking changes through expand-contract so versions coexist, and reach for sharding last — on a high-cardinality co-locating key, only after the single-node ceiling is measured and cheaper levers are spent. Doing all seven on one schema turns the track from facts into judgment.