Bitemporal Loan Ledger With Backdated Payments and Reversals
Last updated: November 29, 2026
Quick Overview
Design and implement an append-only ledger for a daily simple interest loan that can answer both what the principal and accrued interest were on a given date and what the system believed about that date at an earlier point in time. Backdated payments and NSF reversals must be supported without mutating history.
Valon
November 29, 20260
0
0 solved
Design and implement an append-only ledger for a daily simple interest loan that can answer both what the principal and accrued interest were on a given date and what the system believed about that date at an earlier point in time. Backdated payments and NSF reversals must be supported without mutating history.
Servicing data is constantly corrected after the fact: a payment posted late is backdated to the day it was received, and a returned check reverses a payment already applied. A Valon onsite question in this style checks whether you separate effective time from recorded time, keep history immutable for audit, and recompute interest correctly when the past changes.
What the Interviewer Expects
- Distinguish effective date from recorded time
- Keep events append-only and model reversals as new events
- Replay visible events in effective-date order to derive state
- Accrue daily interest and apply payments interest first
- Answer as-of and as-known-at queries
- Discuss caching snapshots so replay stays fast
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make replay fast for a 30-year loan with thousands of events?
- How do you show a borrower why their payoff quote changed after a backdated correction?
- What happens to investor remittances already sent based on the old view?
- How would you store this in Postgres?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Loan: starting principal, annual rate, start date. Interest accrues daily at rate/365 on principal. Payments pay accrued interest first, rest to principal. Events: payment(id, effective, recorded, amo...
High-Level Design
Never update a row. Store every event with both timestamps. To answer a query: filter to events with recorded <= known_at, drop payments whose reversal is also visible, keep those with effective <= as...