How a New Tech Lead Crafted an Elegant Payment System Architecture

The article breaks down the complexities of payment processing by outlining business background, decomposing the workflow into modular steps, illustrating sequence diagrams, designing data structures, and addressing related domains such as product and coupon management, while highlighting key technical challenges like TCC transactions, locking, and retry mechanisms.

SpringMeng
SpringMeng
SpringMeng
How a New Tech Lead Crafted an Elegant Payment System Architecture

Business Background

Payment functionality appears in most business systems. Inexperienced developers feel pressure because any detail error can cause reconciliation anomalies. Fixing errors later is time‑consuming, requires data correction, and may lead to chaotic accounts that need manual intervention.

Diagram
Diagram

Payment Business

Process Decomposition

Complex business is split into modules, each managed separately and then connected.

Account management: manage available balance, frozen amount, bills.

Transaction ledger: record all fund movements, including purchases, top‑ups, withdrawals, refunds.

Payment integration: record request and response messages when interfacing third‑party platforms.

Order structure: manage order models, split strategies, product specifications.

Diagram
Diagram

Process Sequence

Sequence diagram shows three core stages:

Pre‑payment: build order model, validate inventory and product status, freeze user funds, generate transaction record; status “pending payment”.

Payment integration: construct third‑party payment request, initiate flow, record request parameters, wait for notification.

Post‑payment: based on payment result, update transaction records, frozen funds, order structures, inventory.

Diagram
Diagram

Structure Design

Based on analysis, a basic structural design includes:

Account management: total amount, available balance, frozen amount.

Transaction record: may generate multiple transaction details per order (e.g., shopping cart).

Transaction detail: order splitting may produce multiple rows, directing funds to different merchants.

Payment integration: store request parameters and third‑party callback messages.

Order record: a single order may contain multiple sub‑orders with split strategies (warehouse, merchant, category).

Order detail: manage product, specification, buyer/seller, unit price, quantity, amount for each sub‑order.

Diagram
Diagram

Related Business

Additional e‑commerce concerns:

Product management: maintain product dimensions, specifications, pricing tiers, and build product detail descriptions.

Coupon rules: support full‑reduction, discount rates, price ladders, validity periods, and issuance rules for operations, user‑lifecycle, and channel conversion.

Diagram
Diagram
Diagram
Diagram

Practice Summary

Business model: clear understanding, split core nodes, design corresponding sequence and data structures.

Transaction management: use TCC (Try‑Confirm‑Cancel) pattern for distributed transactions.

Locking and retry: after payment success, lock order ID before downstream updates to avoid issues from message retries.

Fund settlement: ensure precise amount calculations; each transaction must pass reconciliation checks.

Process maintenance: provide visual workflow tools and manual maintenance mechanisms to keep the process reliable.

Source: blog.csdn.net/cicada_smile/article/details/125586542

Code example

👏2025 最新,钻石VIP学习
😉2025私活联盟整起!
backend architectureorder processingTCCpayment systemTransaction Managementcoupon rules
SpringMeng
Written by

SpringMeng

Focused on software development, sharing source code and tutorials for various systems.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.