KatInterview

Build a Loyalty Points Engine with an Immutable Ledger

System DesignModel answer
MediumModel answerSystem Designsystem-designledgeridempotency

Last updated

Design a service that turns settled payments into loyalty points using versioned earning rules, an append-only ledger, safe redemptions, and daily reconciliation.

Context

A payments and rewards platform lets members earn loyalty points on card spend and on rent payments. Earning depends on rules that change over time, for example a higher multiplier for dining, a lower one for rent, a temporary boost during a promotional window, and limits on how many points a category can yield per period.

You are asked to design the points service that receives payment events, decides how many points each one is worth, records the result, and lets members spend those points on travel, rent credits, or partner transfers.

Because points have monetary value, every credit and debit must be explainable after the fact, safe against repeated deliveries, and never lost.

Requirements

Functional

  1. Accept settled-payment events and evaluate them against configurable, versioned earning rules.
  2. Store earnings and spends in an append-only ledger that records which rule version, multiplier, and cap produced each amount.
  3. Let a member read their spendable balance and redeem points, never allowing the balance to go below zero.
  4. Run a daily reconciliation that finds and repairs differences between source payments and ledger credits.

Non-functional

  1. Upstream systems may redeliver the same event; duplicates must never produce extra points.
  2. Balance changes must be strongly consistent so the same points cannot be spent twice.
  3. Publishing a new rule version must never change past credits, and re-processing an event must give the same answer.

Scale

  • 5 million active members.
  • 10 million transactions per day (about 120 TPS average, 1,500 TPS on promotion peaks).
  • Balance read p95 under 50 ms; an event should be reflected in the ledger within 5 seconds of arrival.
  • Roughly 15-20 million ledger rows per day, kept for several years for compliance.

What to deliver

  • The main APIs (event ingestion, balance, redemption).
  • A data model separating rule definitions, ledger records, and balances.
  • A high-level architecture covering ingestion, rule evaluation, and reconciliation.
  • A discussion of relational vs. non-relational storage for the ledger, and where caching fits.

Hints

Hint 1

Start with the numbers: about 3,000 inserts per second at peak is modest for a partitioned relational store, so the difficult parts are correctness and idempotency rather than raw throughput.

Hint 2

Make duplicates harmless at the database level with a unique key on (source transaction id, event type), and update the balance in the same transaction as the ledger rows.

Hint 3

Never evaluate rules using the current clock. Select the rule version by the event's own settlement time and store a resolved explanation with each ledger entry, so replays are deterministic.

Hint 4

Treat the cache as a read accelerator only. Spend decisions should run against the authoritative balance row with a lock or a version check.