CRUCIBLE
MODULE:M01M02M03M04M05M06M07M08M09M10M11M12
5-STAGE MISSION GAUNTLET · M01 · L4–L5

M01 · Python Core, Clean Arch & DevSecOps

Ship typed async FastAPI services with strict idempotency, structured logs, and 6-gate CI security.

GAUNTLET COMPLETION
0 / 5
LAB: lab1-core-engine
STAGE 01 · BOOK I · MENTAL MODELS · CH 01 (8 MIN READ)

Trade-offs & The Hidden Ledger

Every engineering gain writes a bill somewhere else in the system.

THE CORE INVARIANT

You never eliminate complexity or cost — you move it from a dimension you cannot afford to one you can control.

PHYSICAL MENTAL MODEL

Putting a mini-fridge beside your desk (a cache) saves the walk to the kitchen (database), but now you pay for freshness: milk expires, restocking causes a rush, and two fridges can disagree.

INTERACTIVE MECHANISM · CACHE STAMPEDE VS. SINGLE-FLIGHT REFILL
500 ReadersHot key expiredRedis CacheMISS + LockPostgres PrimaryProtected by 1 refill
1. Hot TTL expires: 500 concurrent requests miss the exact same hot key within 10ms.
Redis L1 hit
~0.3–1 ms
Same-AZ TCP round trip
Postgres indexed read
~2–10 ms
Hot buffer pool page
Stampede fan-in
500× DB load
Without single-flight or TTL jitter
LEVEL LADDER · “How would you speed up our slow product catalog endpoint?”
L4 SIGNAL

Put Redis in front of the database so repeated reads are faster.

L5 SIGNAL

Add cache-aside in Redis with a 5-minute TTL and invalidate keys on product writes.

L6 SIGNAL

Confirm read/write ratio and staleness budget first. Add Redis cache-aside with TTL jitter and single-flight coalescing to stop stampedes, and monitor hit ratio + DB p99.

L7 SIGNAL

Measure whether the bottleneck is query plan, connection pooling, or payload size before adding a new stateful tier. If caching is justified, define the exact staleness SLA, bound cache memory with LRU + hot-key mitigation, and design graceful degradation if Redis goes dark.

QUICK RECALL CHECK (2 CARDS · CLICK TO REVEAL)
Open Full 14-Chapter Field Manual ↗