Design an ecommerce offer system
viaLeetCode
Problem Design an offer/promotions system for an ecommerce site: define offers (discounts, coupons, promotions), apply eligible offers to a cart at checkout, and resolve conflicts when several offers match.
Functional requirements
- Offer authoring: percentage/flat discounts, coupon codes, buy-X-get-Y, category/user-segment targeting, validity windows, usage limits.
- Checkout evaluation: given a cart + user, return applicable offers and the final price.
- Conflict resolution: stacking rules, exclusivity, best-for-customer selection.
Non-functional requirements
- Evaluation on the hot checkout path: p99 < ~50 ms at, say, 5K checkout QPS.
- Offers change frequently (marketing-driven) without deploys; sale events cause 10x spikes.
Key components
- Offer definition service + store (rules as data: conditions + actions), rule-evaluation engine at checkout, offer cache (offers are small and read-heavy — replicate in memory, invalidate on publish), usage/redemption counter service (atomic limits), audit log of applied discounts.
Deep dives / trade-offs
- Data model for rules: normalized tables vs a JSON condition DSL; how to index for "which offers could apply to this cart" candidate selection before full evaluation.
- Correct global usage caps under concurrency (atomic counters / reserved redemptions).
- Best-offer selection when stacking is disallowed: evaluate all candidates and pick max savings vs priority ordering — cost of each at scale.
asked …