Problem
Design the backend for a limited-time coupon抢购 (flash sale) system.
-
There are
K coupons
available during a sale window (e.g., 10:00:00–10:00:10 UTC).
-
Users are
globally distributed across multiple countries/regions
.
-
The key requirement:
each eligible user should have the same probability of winning a coupon
, regardless of geography/network latency.
Requirements
Functional
-
Users can attempt to claim during the sale window.
-
Each user can win at most
1
coupon (assume one account = one person).
-
Users should get a result:
WIN
(coupon assigned) or
LOSE
(not assigned), ideally within seconds.
Non-functional
-
Handle very high QPS during the window.
-
Prevent overselling (never assign > K coupons).
-
Be resilient to retries, duplicated requests, and partial failures.
-
Provide an auditable fairness story (how we ensure “equal odds”).
Deliverables
Explain:
-
APIs and data model
-
High-level architecture (global traffic, regional services)
-
The algorithm that ensures equal odds
-
Concurrency control, idempotency, and anti-abuse
-
Tradeoffs and failure handling