Problem statement
Design the object model and core APIs for an installment-plan (EMI) engine that splits a financed purchase into a schedule of periodic payments, tracks what has been paid, and handles early payoff and missed payments.
Operating context. A purchase of principal P is financed over N periods at an interest rate. The engine builds an amortization schedule where each installment is a principal portion plus an interest portion. Incoming payments are allocated across outstanding installments (oldest first) by a configurable policy. The engine also supports a prepayment (which either shortens the term or lowers future installments), a late fee when a due date passes unpaid, and a payoff quote for settling the remaining balance as of a date. The interest method is pluggable (flat versus reducing-balance). Everything runs in a single process.
Out of scope. Credit scoring and underwriting, payment collection or gateway integration, a persistence layer, regulatory disclosure documents, and multi-currency.
What to produce. The class hierarchy (LoanAccount, Installment, AmortizationSchedule, an interest method, a payment-allocation policy, a late-fee policy, a Clock), the public APIs each exposes, the amortization computation, and the installment state machine (scheduled, due, partially paid, paid, overdue). Be explicit about how the schedule conserves the exact principal despite rounding, and how a prepayment reshapes the remaining schedule.
Functional requirements
- Generate an amortization schedule of N installments from principal, rate, and term, splitting each into principal and interest.
- Apply a payment, allocating it across outstanding installments by the configured policy and updating balances.
- Produce a payoff quote to settle the entire remaining balance as of a given date.
- Apply a late fee and mark an installment overdue once its due date passes unpaid.
- Handle a prepayment by either shortening the term or lowering future installments per the account's configuration.
Non-functional requirements
- Schedule generation is O(N) and the sum of installment principal portions equals the original principal exactly, with no rounding drift.
- The interest method, allocation policy, and late-fee policy are pluggable strategies — adding a new interest method must not touch the schedule builder.
- Monetary amounts are exact minor units; the final installment absorbs any rounding remainder deterministically.
- Installment state transitions are total and guarded; an installment can never be paid twice.
- Concurrent payment application is serialized per loan account so allocation and balances stay consistent.
- The engine is unit-testable with an injected clock and no persistence.
Topics
- System Design LLD
- Oop Solid
- Patterns Strategy
- Patterns State
- Finance Lending