01
Multi-Vendor Payment System and Arrears Recovery
Owned the service from initial design to implementation
Led the end-to-end architecture and implementation of VoltUp's payment platform, evolving a single-provider system into a multi-provider module featuring DLQ-based recovery and atomic database approval locks to eliminate duplicate charges. Connected stranded READY and AUTHORIZED states to automated recovery and operator-review paths so indeterminate outcomes remain traceable.
Design Context
Beyond supporting multiple providers through one extension point, the service needed a final safety boundary that prevents reapproval across Redis-lock expiry, lost payment-gateway responses, database rollbacks, and provider changes, with clear recovery ownership.
Key Point
A project that demonstrates multi-provider extensibility, payment state machines, atomic approval ownership, and recovery boundaries for indeterminate outcomes.
Core Implementation
- Built a payment-gateway integration architecture using an abstract-class-based provider strategy.
- Implemented a GCP Pub/Sub dead-letter-queue pattern that isolates failed events and keeps failed-payment recovery traceable.
- Used a conditional MySQL update to set `payments.status` to `AUTHORIZED` before calling the payment gateway. Only the request that updated the row could submit the charge.
- Separated unpaid-balance bookkeeping from payment confirmation so ledger-lock contention cannot roll back an approval, while correcting duplicate point deductions and preventing current settings from being applied retroactively during retries.
- Split payment failures by cause. Only definitive gateway declines, such as card declines or insufficient funds, become failed payments with an unpaid balance, and their messages are acknowledged so the same decline is not retried against the gateway. Unknown outcomes caused by our side or the network, such as lost responses and timeouts, stay AUTHORIZED without an unpaid balance, so customers are not blocked from charging or sent overdue notices.
- When an AUTHORIZED payment re-enters, it first queries the gateway: approved payments are backfilled to PAID, confirmed non-approvals release ownership and approve normally, and undetermined ones are blocked with a Slack alert and can only be released through a manual API that requires a reason. Orphaned READY orders are recovered through state sync and event republishing.
- For customer-support cases, added an exclusion flag across billing, the app server, and the operations console that lifts the charging block while keeping the unpaid balance, and reclassified per-provider log levels so everyday declines no longer raise ERROR alerts and only real system errors do.
- Traced a reported pricing error through logs, audit records, and production data, confirmed the cause was zone-assignment master data rather than code, and classified every order in the affected period to quantify 220 mischarged sessions totaling KRW 893,812.
- Queried payment providers to reconcile unpaid orders after a lost response, without submitting another charge
Engineering Lens
- Centered request orchestration, point hold/confirm, and success/failure transitions around PaymentProcessor so state changes remain traceable in one place.
- Kept Redis locks as a first-line concurrency control, while making a conditional DB update the final serialization boundary immediately before money moves.
- I treated "payment failure" as two different things: customer-side and system-side. Counting unknown outcomes as unpaid would block customers and send overdue notices for our own problems, so an unpaid balance is created only when the gateway definitively declines; everything else keeps ownership while the system verifies the outcome.
- Used a fail-closed model: transition to PAID/FAILED only for definitive outcomes and retain AUTHORIZED when uncertain, prioritizing duplicate-charge prevention over automatic availability.
- Ran eight concurrent requests for the same order against MySQL and verified that only one could proceed to the gateway.
Architecture Snapshot
Mermaid View
Multi-vendor orchestration: lock, hold, and state transitions
Shows request data, lock keys, point holds, READY-state creation, provider approval, and success or failure transitions in one integrated diagram.
flowchart TD
Req["pay / rePay<br/>order=ORD-240915-001<br/>user=421 method=17 point=2000"] --> Lock["distributed lock<br/>payment-user-process:421"]
Lock --> Hold["PointUpdater.hold()<br/>wallet -> HOLD 2000P"]
Hold --> Ready["createWithReady()<br/>payment READY"]
Ready --> Sub["resolve subscription<br/>methodId=17 or primary"]
Sub --> Vendor["Payment Provider Router<br/>Kakao Pay / Toss Payments / Kakao T<br/>selected: Kakao T"]
subgraph PGV["Payment Provider Layer"]
direction TD
Vendor --> Keys["read vendor keys<br/>pgPayKey + token"]
Keys --> Api["vendor client.pay(...)"]
Api --> Tx["save pgTransactionId<br/>paymentId / tid / paymentKey"]
end
Tx --> Result{"approval result"}
Result -->|success| Done["updateSuccess<br/>payment PAID<br/>point HOLD->CONFIRM"]
Result -->|fail| Fail["updateFailed<br/>releaseHold(order)"]
Fail --> Recovery["repair / retry / failover"]
classDef vendor fill:#dff2ff,stroke:#0f4c81,stroke-width:2px,color:#0f172a;
class Vendor,Keys,Api,Tx vendor;
style PGV fill:#eef7fb,stroke:#0f4c81,stroke-width:2px,color:#0f172a; Mermaid View
Multi-vendor system: mandatory contracts and optional extensions
Places `VendorChecker.select()` on top of the `VendorType` extension point, separates contracts required for every vendor from features needed by only some vendors, and uses `@RequiredVendor` plus `VendorRequirementsValidator` to catch missing mandatory implementations at startup.
flowchart TD
Vendors["VendorType<br/>Kakao Pay / Toss Payments / Kakao T"] --> Select["VendorChecker.select(vendorType)"]
Select --> Required["Required on all vendors<br/>VendorPaymentProcessor<br/>VendorMethodProcessor"]
Select --> Partial["Required on some vendors<br/>VendorPaymentOnceProcessor<br/>(KakaoPay only)"]
Select --> Optional["Optional extensions<br/>RepairService / vendor hooks"]
Required --> Validate["@RequiredVendor<br/>+ VendorRequirementsValidator"]
Partial --> Validate
Validate --> Boot{"startup validation"}
Boot -->|missing| Error["application start fail"]
Boot -->|ok| Route["route to concrete impl"]
classDef core fill:#dff2ff,stroke:#0f4c81,stroke-width:2px,color:#0f172a;
classDef optional fill:#edf9f3,stroke:#2f6f57,stroke-width:2px,color:#0f172a;
classDef error fill:#fff1f2,stroke:#be123c,stroke-width:2px,color:#0f172a;
class Vendors,Select,Required,Partial,Validate,Route core;
class Optional optional;
class Error error; Mermaid View
Failure routing: customer-side declines become unpaid, system-side unknowns stay AUTHORIZED
Only definitive gateway declines become unpaid balances; unknown outcomes keep approval ownership and are settled by a gateway lookup on the next entry.
flowchart TD
Call["Payment-gateway approval call<br/>(after claiming AUTHORIZED)"] --> Result{"Gateway response"}
Result -->|"approved"| Paid["PAID"]
Result -->|"definitive decline<br/>card declined, insufficient funds"| Denied["FAILED + unpaid balance<br/>release ownership, ACK message<br/>(no repeated calls for the same decline)"]
Result -->|"unknown outcome<br/>lost response, timeout"| Held["Keep AUTHORIZED<br/>no unpaid balance<br/>→ no charging block or overdue notice"]
Held --> Recheck{"On re-entry: query gateway first"}
Recheck -->|"approved there"| Backfill["Backfill to PAID"]
Recheck -->|"confirmed not approved"| Release["Release ownership, approve normally"]
Recheck -->|"undetermined"| Manual["Block + Slack alert<br/>manual release API with reason"]
classDef held fill:#dff2ff,stroke:#0f4c81,stroke-width:2px,color:#0f172a;
class Held,Recheck held; Operational Outcomes
- Built a payment architecture that integrates multiple payment providers behind one interface and remains extensible as providers are added.
- Applied dead-letter-queue handling and state-specific recovery paths for READY and AUTHORIZED payments, making each failure either automatically recoverable or explicitly reviewable by an operator.
- Kept system-side failures such as lost responses and timeouts from turning into customer unpaid balances or charging blocks, and resolved indeterminate payments automatically through gateway lookups or surfaced them for operator decisions.
- Blocked paths where post-approval database contention, lost responses, or retries through a different payment provider could lead to duplicate charges.