Design Checkout Promotion Codes with One Promotion per Checkout and a Get Coupons API
Company: Stripe
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Onsite
Design promotion codes for a checkout page. Merchants create promotions, and customers redeem them by entering a code on the checkout page. Only one promotion can apply to a checkout at a time. Part of the round is writing pseudocode for a `get coupons` API.
Assume the checkout page and its backend already exist: each purchase has a checkout session with line items, a currency and an optional signed-in customer, followed by a payment step that charges the customer. Your design adds promotions to it.
### Clarifying Questions
- Which restrictions can a promotion carry: an expiry time, a total redemption limit, a per-customer limit, a minimum order amount, eligible products, first-purchase customers only?
- Which discount types are needed: a percentage off, a fixed amount off in one currency, or both?
- When a customer enters a second code, does it replace the applied promotion or get rejected?
- When does a redemption count against a limit: when the code is applied, or when the payment succeeds?
- What does `get coupons` return: the coupons a customer can apply to a given checkout, or the details of one code the customer typed?
- How many merchants, codes and checkouts per second should the design handle?
### Part 1: Data model and promotion rules
Define the entities and storage for promotions and their codes, how a discount is computed, and how each promotion's restrictions are represented and checked.
```hint Start from one checkout
List everything that must be true for a given code to apply to a given checkout, then decide which entity stores each fact.
```
#### What This Part Should Cover
- Entities, fields and the representation of money and percentages.
- How restrictions and limits are stored.
- Code uniqueness, case handling and the one-promotion rule in the schema.
### Part 2: The get coupons API
Write pseudocode for the `get coupons` API: its request, its response and every check it performs.
```hint Order the checks
Some checks need only the promotion, some need this checkout, and some need another read about this customer. Their order affects latency and what an error message reveals.
```
#### Clarifying Questions for this Part
- Is the API called from the customer's browser, from the merchant's server, or both?
- Should a typed code that does not apply come back with a reason the customer can act on?
#### What This Part Should Cover
- A request and response contract, including failure reasons.
- Eligibility checks in a deliberate order.
- Discount arithmetic in integer minor units with rounding and caps.
- Authorization and what the response may reveal.
### Part 3: Applying a code and redeeming it at payment
Design how a code is applied to a checkout and how its use is recorded when the customer pays. Keep the one-promotion rule and the redemption limits correct when two browser tabs apply codes to the same checkout, when many customers redeem the last uses of one code at once, and when a payment fails or is retried.
```hint Find the races
Two requests can race on one checkout, and many checkouts can race on one code. Decide which row settles each race.
```
#### What This Part Should Cover
- Enforcement of one promotion per checkout on the server.
- When a use is consumed, and how concurrent redemptions are serialized.
- Re-validation at payment time and the release of uses from failed or abandoned payments.
- Idempotent retries.
### What a Strong Answer Covers
- How the schema enforces the one-promotion rule and per-merchant code uniqueness.
- Exact money arithmetic across currencies.
- Limit accounting under concurrency, payment failure and retries.
- Pseudocode complete enough to implement, written within the round's tight time limit.
- Scaling for hot codes during a sale, caching of promotion definitions, and which reads may be stale.
### Follow-up Questions
- A popular code spreads on social media and gets thousands of apply attempts per second. What breaks first, and how do you protect it?
- A merchant changes a promotion's discount while customers have it applied to open checkouts. What do those customers pay?
- How would you allow two promotions on one checkout later without rewriting the model?
- How do you stop someone from guessing valid codes?
Overview: Design promotion codes for a checkout page where each checkout can carry only one promotion, and write pseudocode for a get coupons API. It tests modeling discounts and restrictions, exact money arithmetic, and keeping redemption limits correct when many checkouts use the same code or a payment fails.
Read the full Stripe Software Engineer interview experience this question came from