Skip to content

Architecture Decision Records (ADR Log) ​

This log records every major design decision made in 18-flash-sale-inventory.

ADR IDDecision MadeChosen OptionAlternatives ConsideredDeciding FactorsTrade-Off AcceptedRevisit When
ADR-01High-Concurrency Stock ReservationAtomic Conditional SQL (WHERE available >= :q)Redis Lua, SELECT FOR UPDATE, Optimistic LockingDirect ACID durability, database kernel-enforced check constraints.Lower single-row throughput ceiling than pure in-memory Redis.Single SKU traffic exceeds 20,000 writes/sec.
ADR-02Traffic Surge LevelingVirtual Waiting Room (flow/waiting_room.py)Direct HTTP 429 Rate Limiting, Unbounded QueuePreserves customer fairness and prevents payment gateway connection collapse.Adds asynchronous polling round-trips for the client.Traffic is distributed over hours rather than sudden drops.
ADR-03Currency PrecisionInteger Minor Units (Cents)Floating-point numbers, Decimal objectsEliminates IEEE 754 precision rounding errors and optimizes memory.Requires frontend multiplication/division by 100 for display.Multi-currency conversions with 4 decimal places are required.
ADR-04Distributed Lock Stale Write DefenseMonotonic Fencing Tokens (transactions/distributed_lock.py)Simple Redis lock, RedlockEliminates Martin Kleppmann stale-write hazards caused by GC pauses.Storage layer must record highest observed fencing token.All writes are handled by a single leader database.
ADR-05API FrameworkFastAPI (Python 3.13)Express.js, Django, Go GinHigh-performance async ASGI loop, native Pydantic v2 validation, auto-generated OpenAPI docs.Python global interpreter lock (mitigated by multi-process Uvicorn).Microsecond-level network proxying is needed (migrate to Go/Rust).
ADR-06Observability ArchitecturePrometheus Gauges + Invariant AuditorPassive log scanning, ELK stack aloneContinuous autonomous audit detects mathematical drift before customers notice.Small background query overhead on database.Database CPU exceeds 80% during peak flash sales.