Design Loan Repayment and Investor Distribution
Design an auditable loan-servicing path that takes borrower payments through a third-party money mover and turns them into exactly-once investor payouts.
Problem statement
For this exercise, assume a platform services already-originated loans. A borrower submits a payment, sees whether it is pending, cleared, failed or reversed, and sees the resulting loan balance.
A payment is a single amount that reduces the loan balance; interest, fees and payment waterfalls (splitting a payment among principal, interest and fees) are outside scope.
Each loan has a fixed set of investor shares, and the platform supplies the split rule: when a payment clears, each investor's amount is the payment times that investor's share, rounded down to whole cents, and any remaining cents go one each to investors in a fixed order.
The resulting investor payables are paid out in one daily distribution per investor.
For this exercise, assume both the borrower debit and the investor payouts go through one third-party money-movement provider. The provider accepts a client idempotency key, may time out or answer late, and reports outcomes by callback and by lookup.
An unknown outcome must stay reserved until reconciliation establishes a terminal result. Retries must never move one logical payment or payout twice, every money movement must be auditable, and corrections append new linked records instead of rewriting history.
Loan origination, underwriting, secondary-market trading, tax reporting, foreign exchange and changes to investor shares are outside scope.
What to build
- A borrower can submit a payment that is debited through the third-party provider, see it move through pending, cleared, failed or reversed, and see the loan balance; one logical payment produces at most one debit.
- Each cleared payment creates the investors' payable entries exactly once, using the supplied split, and they sum exactly to the payment.
- The platform forms at most one daily distribution per eligible investor from undistributed payable entries and exposes its current outcome.
- Operators can reconcile uncertain provider outcomes, and a reversed payment appends linked negative payable entries that reference the originals instead of rewriting history.
At scale
- For this exercise, assume 10 million active loans, 1 million investors and peaks of 2,000 borrower payments per second.
- For this exercise, assume a submitted payment is durably recorded as pending and acknowledged within 500 milliseconds at p95, before the provider has answered; balance reads return within 300 milliseconds at p95.
- For this exercise, assume the provider accepts up to 3,000 debit requests per second and, separately, up to 500 payout requests per second; work above a limit waits in a durable queue. A healthy daily distribution cycle finishes within six hours.
- For this exercise, assume financial history is kept for seven years, acknowledged money movements survive a single-zone failure, and balance views can be rebuilt from durable records.