awesome-everything RU
↑ Back to the climb

Databases

Database track: design and tune a production schema

Crux Capstone: design and tune a production PostgreSQL schema end to end — model, index, read a plan, pick isolation, size the pool, plan a zero-downtime migration, and decide if and when to shard, each with evidence.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 240 min

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.

Goal

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.

Project
0 of 8
Objective

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.

Requirements
Acceptance criteria
  • 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.
Senior stretch
  • 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.
Recap

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.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.