Coupon service inspired by Amazon and Swiggy promo codes: a code can be redeemed only as many times as allowed, checks are cached, and usage counts are updated in the background.
See why checking and redeeming codes in one place does not scale.
What was missing: No protection against two shoppers using the last redemption of a code at the same instant.
Why that's risky: Check-then-update has a race: two requests can both read 'one use left' and both redeem, so a single-use code works twice.
What gets added: One server that reads a code's rules to check it and updates the same row to redeem it.
Trade-offs: Simple, but correctness depends on request timing.
Make redemption safe under many simultaneous attempts.
What was missing: Checks and redemptions shared one path and redemption was racy.
Why that's risky: Checks still read the database directly, and a hot code serializes redemptions on one row.
What gets added: A redeem service that uses one atomic conditional update ('use a code only while uses remain') and a separate check service.
Trade-offs: Atomic updates serialize attempts on one hot code, which is the price of never over-using it. Redeem when payment succeeds, or reserve the use with a timeout, so an abandoned checkout does not burn a use.
Serve checks from memory and move usage tracking off the request path.
What was missing: Every check hits the database and usage tracking slows redemption.
Why that's risky: A cached rule can show a code that was just used up, so the cache only speeds up checks; redemption always decides in the database.
What gets added: A cache of code rules and expiry for fast checks, and a usage queue with workers that update per-user counts and expire codes.
Trade-offs: Checks may be a moment stale, redemption never is.
Stop code guessing and watch the system.
What was missing: Scripts can guess codes and nothing shows system health.
Why that's risky: Without limits a script can try millions of short codes and find valid ones.
What gets added: A rate limiter per account and IP, and monitoring of redemption rate, rejected guesses and queue depth.
Trade-offs: Strict limits may block a real user who mistypes, so limits are per account as well as per IP.
You're in the middle of an interview session. Leaving now will end your current attempt.
Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.
You've conquered this phase. These are the skills you now own: