hii
Prompt
Act as a Principal Software Engineer & Laravel Core Architect. I am building a high-throughput flash-sale e-commerce module in Laravel 11. I need a complete, production-ready implementation of a stock-reservation and checkout engine. ### Strict Business Requirements & Edge Cases: 1. High Concurrency & Zero Overselling: 10,000 concurrent requests attempting to claim the last 5 items in stock. Absolute zero tolerance for race conditions, deadlock traps, or phantom reads. 2. Two-Phase Reservation System: - Phase 1: Reserve stock for 10 minutes. If unpaid after 10 minutes, automatically release stock back to inventory without blocking worker queues or stalling database execution. - Phase 2: Checkout completion. Deduct inventory permanently and record transaction logs inside an isolated atomic database transaction. 3. High Read Throughput: The product detail page needs real-time remaining stock counts served under 5ms, while maintaining strict eventual consistency or real-time accuracy during high write pressure. 4. Resilience: If the primary Redis instance crashes or experiences high network latency during a reservation attempt, the system must degrade gracefully without leaving reserved inventory in an orphaned state. ### Technical Expectations for your Architecture & Code: - Concrete Laravel 11 implementation: Write clean, production-grade PHP 8.3+ code using idiomatic Laravel features (e.g., Cache::lock, DB transactions with pessimistic/optimistic locking strategies, Eloquent/Query Builder, Redis Lua scripts, or Custom Pipeline/Actions). - Do NOT provide pseudo-code or generic descriptions like "// add logic here". Provide full, compilable methods, service classes, and data migrations if necessary. - Explicitly explain: 1. How you handle race conditions at the database AND cache levels (Lua scripts vs SELECT ... FOR UPDATE vs Redis atomic counters). 2. The exact mechanism used to auto-expire unpaid reservations reliably. 3. How your database indexing and query strategy avoids table-level locks or index contention under ultra-high write loads. 4. Potential flaws or failure modes of your chosen architecture and how you mitigated them.
Response not available
Response not available