Design an End-to-End Loan Origination Platform
System DesignModel answerLast updated
Architect a durable, compliant loan origination system covering product selection, application intake, automated underwriting, third-party data pulls, decisioning, and disbursement.
The Scenario
You are the founding engineer at a small lending startup. The business offers two products: term loans and merchant cash advances to small businesses. Leadership wants a platform that handles everything from a borrower viewing loan options to money hitting their bank account.
What to Design
Walk through the full origination lifecycle:
- Product browsing — borrowers see available products and indicative eligibility based on their business profile.
- Application intake — collecting business details, KYC/KYB information, requested amount, and explicit consent to pull third-party data.
- Data acquisition — integrating with a credit bureau and a bank-data aggregator (think Plaid-style) to pull credit reports and transaction history.
- Underwriting — automated scoring and policy rules, with a fallback path to a human review queue for borderline cases.
- Decisioning and offer — generating an offer (amount, fee, repayment schedule) and presenting it to the borrower for acceptance.
- Document signing and disbursement — routing to an e-sign vendor, then funding via ACH, RTP, or wire, recorded in a ledger.
Assumptions to State Up Front
Make explicit assumptions about scale before designing. As a reference point, a small lender might process tens of thousands of applications per month, disburse tens of millions of dollars, and see roughly 10–20% of applications require manual review.
What a Strong Answer Covers
- Requirements clarification — functional scope, non-functional priorities, scale assumptions.
- API design — key endpoints with idempotency handling.
- Data model — tables for applications, events, external requests, underwriting results, offers, loans, payments, and a ledger.
- Architecture diagram — services, async communication, external integrations.
- Application state machine — all valid states and transitions.
- At least two deep dives, chosen from: durable workflow orchestration, external integration reliability, underwriting pipeline, exactly-once disbursement, PII handling, or audit/compliance.
You are not expected to design for massive internet-scale throughput. The hard problems here are workflow correctness, third-party reliability, and regulatory compliance.
Hints
Hint 1
Before touching architecture, nail down the non-functional priorities. At a small lender's volume, the bottlenecks are slow third parties and correctness guarantees, not raw throughput. State this explicitly — it shapes every design choice that follows.
Hint 2
Model the application as a state machine first. List every state (including terminal ones like DECLINED, WITHDRAWN, EXPIRED) and every valid transition before drawing any service boxes. Transitions should update status, append an audit event, and emit an outbox message atomically in a single DB transaction.
Hint 3
For disbursement, the core constraint is exactly-once execution — you must never fund the same loan twice. Think about how an idempotency key on the payments table, combined with a double-entry ledger, gives you both the safety guarantee and the audit trail regulators expect.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify Requirements First
The first thing to say out loud: at a small lender's volume, the hard problems are workflow correctness and third-party reliability, not horizontal sharding. Frame this early — it shows you understand the actual risk surface.
Functional scope:
- Borrowers browse products, see indicative terms, and submit an application with business info and consent.
- The system pulls a credit report and bank transaction history from third-party providers.
- Automated underwriting scores the application; borderline cases route to a human review queue.
- Approved applications generate an offer; accepted offers proceed to e-signing and then disbursement.
- Both borrowers and internal ops staff can check status at any point.
Quantified assumptions (state these, do not wait to be asked):
- ~50K applications/month, ~2K/day, peak ~10/min.
- ~20% go to manual review.
- ~$50M disbursed/month.
- Read traffic (status polling) is roughly 100× writes — comfortably handled by one Postgres primary with read replicas.
Non-functional priorities, in order:
- Durability — no application, decision, or payment is ever lost.
- Exactly-once disbursement — a loan is funded exactly once.
- Auditability — every decision must be reconstructable for ECOA adverse-action notices and fair-lending audits.
- Security — SSNs and bank data are PII; encrypt at rest, enforce access controls, log all reads.
- Latency — product pages under 300 ms; automated decisions within minutes; manual review within hours.
2. API Sketch
GET /products?business_id=...
-> eligible products with indicative terms
POST /applications (Idempotency-Key: <uuid> header required)
{ business_id, product_id, amount, consent_ids, kyc_payload }
-> { application_id, status: "SUBMITTED" }
GET /applications/{id}
-> current status, required actions, offer if available
POST /applications/{id}/documents
-> upload PDF bank statements (fallback when aggregator fails)
POST /applications/{id}/offers/{offer_id}/accept
POST /webhooks/{provider}
-> handles callbacks from bureau, aggregator, e-sign, and payment processor
# Internal (ops)
GET /review-queue?assignee=...
POST /applications/{id}/manual-decision { decision, reason_codes, notes }
All mutating endpoints require an idempotency key because clients and partner systems will retry on network errors. The server stores (idempotency_key, response) and returns the cached response on duplicates.
3. Data Model (Postgres)
Key tables and their purpose:
| Table | Purpose |
|---|---|
products | Versioned product definitions; approved loans reference the exact version they were priced under |
applications | Core record with status and an optimistic-concurrency version column |
application_events | Append-only; every state transition writes a row — this is the audit log |
external_requests | Tracks one row per provider call with dedup key (application_id, provider, request_hash); raw responses go to encrypted S3 |
underwriting_results | Records model version, policy version, feature snapshot reference, score, decision, and reason codes |
review_tasks | One row per case sent to manual review, with SLA due timestamp |
offers | Terms attached to an approved application, with expiry |
loans | Created from an accepted offer |
payments | One row per money movement; idempotency_key UNIQUE enforces at-most-once insertion |
ledger_entries | Double-entry ledger; all entries for a transaction must net to zero |
PII (SSNs, bank account numbers) lives in a separate tokenized vault. All other tables store tokens, never raw values.
4. Application State Machine
DRAFT → SUBMITTED → DATA_PENDING → UNDERWRITING
|
MANUAL_REVIEW (optional)
|
APPROVED ──────── DECLINED
|
OFFER_ACCEPTED
|
DOCS_SIGNED
|
DISBURSING → FUNDED
Any state can also transition to WITHDRAWN (borrower-initiated) or EXPIRED (offer timeout, SLA breach). Every transition runs as a single DB transaction: update status with optimistic locking on version, insert an application_events row, and write an outbox message for async consumers.
5. Architecture
Borrower UI / Partner API
|
API Gateway (auth, rate limiting, idempotency cache)
|
Application Service ── Postgres ── Outbox ──> Event Bus (Kafka / SQS)
|
Workflow Orchestrator (Temporal or Step Functions)
├─ Data Pull Activity ──> Integration Service ──> Credit Bureau, Bank Aggregator
├─ Underwriting Service (feature builder → rules engine → ML model)
├─ Manual Review (ops console + task queue)
├─ Offer & Docs Service ──> e-sign vendor
└─ Disbursement Service ──> Payment Processor ──> Ledger Service
Notification Service PII Vault S3 (raw reports, signed docs)
6. Deep Dives
Durable Workflow Orchestration
Underwriting is inherently long-running: it waits on bureau webhooks (seconds to minutes), document uploads (minutes to hours), and human reviewers (hours). A simple job queue is not enough.
Use a durable workflow engine like Temporal, or implement a DB-backed state machine with an outbox and polling workers. Either approach gives you: retries with exponential backoff, timers ("expire offer after 14 days", "escalate if SLA breached after 4 hours"), and crash recovery. Activities must be idempotent because the engine delivers at-least-once.
If the bureau is down, the application parks in DATA_PENDING — you never make a credit decision on missing data. When the aggregator connection fails, fall back to PDF upload with OCR parsing.
External Integration Reliability
Wrap every vendor behind an Integration Service with a provider-agnostic interface (so you can swap bureaus or fail over), and deduplicate requests by (application_id, provider, request_hash) — a repeated credit pull may cost money and create a hard inquiry. Apply timeouts, circuit breakers, and capped retries. Persist the raw response to S3 before parsing; this makes every past decision fully reproducible for audits and allows reprocessing when your parsing logic changes.
Exactly-Once Disbursement
The risk is funding a loan twice. Defense-in-depth:
- The
paymentstable has aUNIQUEconstraint onidempotency_key. Any duplicate insert fails at the DB level before money moves. - The Disbursement Service checks
loan.statusinside a transaction before submitting to the payment rail. If status is alreadyDISBURSINGorFUNDED, it aborts. - The payment processor callback is deduplicated by the provider's event ID before updating the loan record.
- Every funding event writes balanced double-entry rows to
ledger_entries. A daily reconciliation job validates that the ledger balances and cross-checks against the payment processor's settlement reports.
Common Mistakes to Avoid
- Skipping the state machine. Jumping straight to services without enumerating states and transitions leads to gaps that show up as bugs (or worse, incorrect decisions) in production.
- Ignoring versioning on products and underwriting models. Without it you cannot explain a past decision — which is a regulatory requirement, not a nice-to-have.
- Treating external webhooks as reliable. Bureaus and aggregators drop or duplicate callbacks. Always deduplicate on the provider's event ID and design for the case where the webhook never arrives.
- Storing PII in the main application tables. Co-mingling sensitive fields with operational data makes access control, encryption rotation, and compliance audits much harder than they need to be.
- Over-engineering for scale. Proposing Cassandra or global sharding for a 50K/month lender signals poor judgment. The right answer here is Postgres with replicas and a workflow engine.