cat ~/systems --hard-parts
How the hard parts work.
Four load-bearing decisions, pulled out of shipped code and drawn as schematics — the edge cases where data sync, money, and real-time state go wrong, and the single invariant that keeps each one correct.
Every exhibit below is read from production code. Each carries one highlighted invariant — the property the system is built to never violate.
trace
erp-sync --keyset-drain
§V · FIG.01failure modewatermark = MINUTE-resolution timestamp
>1000 rows in one minute → overflow stranded silently fix →- composite keyset cursor(timestamp, primary-key)
- drain a saturated minutepage-by-page
- restart at a 1-minute overlap floorre-reads in-place edits
- idempotent upsert
INVARIANTNever advance the watermark unless accepted + rejected == rows_sent — silent drops are caught, not skipped.
trace
payouts --exactly-once
§V · FIG.02transfer.execute()
HTTP 400provably rejectedDEFINITIVE failuremoney never moved
RELEASE fundssafe to re-claim
timeout · 409 · 429 · 5xxmight have succeededAMBIGUOUSkeep PENDING
reconcilewebhook · status-check · admin
resolvepaid|failed
INVARIANTRelease funds only on a provable failure — a maybe-succeeded transfer is never double-paid.
trace
realtime --server-authoritative
§V · FIG.03FIG. 03Cheat-resistant real-time6 → 100+ players
The hard part: in a live multiplayer round, the client can’t be trusted — so the correct answer can never reach it, and the score can’t be set by it.
$token- client requests join
- gateauth + payment + room membership
- scoped tokensubscribe / presence only
⊘ the correct answer is never sent to clients during a live question
$answer- answer submit
- atomic compare-and-setfirst-answer-wins guard
- server-authoritative scoring
- broadcast6 → 100+ subscribers
$round- round advance
- coordinator electiondeterministic leader + liveness takeover
- idempotent phase claim
INVARIANTScoring is server-authoritative and answers aren’t leaked — you can’t fake a correct answer. Scales 6-player rooms → 100+ broadcast.
trace
locks --one-global-order
§V · FIG.04AB–BA cycleflow Abillswaits for ↓payments
flow Bpaymentswaits for ↓bills
each holds what the other wants → 40P01 fix →one global order- billssorted by bill number
- then the payment row
data-dependent lock setunlocked discovery read→lock in global order→revalidate under lock
INVARIANTA single global lock ordering across every money path — the cycle that caused 40P01 can’t form.
These are the load-bearing parts, drawn small. The full case studies — context, stack, and what shipped — live in ~/work.