← Create New Paste

System Design Interview: A Loyalty Points and Rewards Program

13 views
"Design a loyalty points system for a retail or airline company" is a good system design prompt because it looks like simple counters but is really a financial ledger with rules, expiry and fraud concerns. Here is a structured answer. 1. Requirements Functional: members earn points on purchases (base rate plus promotions), view balances and history, redeem points for rewards or discounts at checkout, and see tier status (Silver, Gold, Platinum). Points expire after a period of inactivity or a fixed age. Partners (hotels, credit cards) can award points. Non-functional: balances must be exact (no double earning or double spending), redemption at checkout should respond within about 150 ms, history can be eventually consistent, and the system must be auditable. Scale: 50 million members, 20 million earning events per day, peak of a few thousand redemptions per second during sales. 2. Ledger first, balance second Do not store just a balance column. Store an append-only ledger of point transactions: txn_id, member_id, type (EARN, REDEEM, EXPIRE, ADJUST, REVERSE), amount, source (order_id, partner_id), created_at, expires_at. The balance is the sum of the ledger, cached in a member_balance row updated in the same transaction. This makes audits, customer-support disputes and reversals straightforward. Interviewers often look for exactly this choice. 3. Earning flow The order service publishes an OrderCompleted event. A rules engine computes points: base rate times eligible amount, plus active promotions (double points on a category, bonus for first purchase), multiplied by tier. The earn service writes the ledger entry using order_id as an idempotency key, so a replayed event cannot award points twice. Points may be "pending" until the return window closes, then become available; model this as a status on the ledger entry. 4. Redemption flow At checkout, the client asks to redeem N points. The redemption service runs a conditional update: decrement available balance only if balance >= N, and insert a HELD redemption tied to the cart. When payment succeeds, confirm; on failure or timeout, release. This is similar to inventory reservation and prevents double spending across two devices. 5. Expiry Track which earn entries are consumed by redemptions (FIFO allocation), so you know exactly which points expire when. A daily batch job finds lots past expires_at with remaining value, writes EXPIRE entries, and notifies members a few weeks in advance. Batch by member partition to spread load. 6. Tiers Tier status depends on qualifying activity over a rolling or calendar year. Maintain a qualifying_points counter separate from spendable points, recalculated by a nightly job and updated incrementally on each earn. Tier changes trigger notifications and benefit updates. 7. Returns and fraud When an order is refunded, write a REVERSE entry. If the member already spent the points, allow a negative balance or claw back from future earnings, depending on policy. Watch for fraud patterns: account takeover followed by fast redemption, points transfers between linked accounts, and partner feeds with abnormal volumes. Require step-up authentication for large redemptions. 8. Storage and scale A relational database sharded by member_id keeps each member's ledger and balance on one shard for transactional updates. History views come from a read replica or a search store fed by change data capture. Promotions and rules live in a configuration service with versioning so marketing can launch campaigns without deployments. 9. Wrap-up Summarize: append-only ledger, idempotent earning, conditional redemption holds, FIFO expiry, separate tier counters, and reversal handling. When an interviewer pushes on edge cases like partial refunds, it is easy to lose the thread. Linkjob AI (https://linkjob.ai) provides real-time help during live job interviews and technical interviews, prompting the next consideration so your design stays complete.
Created Nov 18, 2026 02:04 Expires Nov 18, 2027 02:04