Skip to content
Elegant Payment System Design: From Business Decomposition to TCC Transactions

Elegant Payment System Design: From Business Decomposition to TCC Transactions

This article breaks down payment system design into business decomposition, sequence modeling, data structure design, and key technical patterns like TCC transactions, locking, and fund settlement, using e-commerce scenarios to illustrate each layer.

macrozheng
macrozheng
macrozheng

Business Background

Payment functionality appears in most business systems. For inexperienced developers, payment settlement logic is the most stressful because any detail flaw can cause reconciliation anomalies. Fixing errors after they occur incurs high time costs, involves data correction, and often leads to messy accounts requiring manual intervention.

Payment scenarios involve complex business rules, settlement logic, long workflows, third-party integrations, and technical details such as transaction management, asynchronous processing, retry mechanisms, and locking.

Payment Business

1. Process Decomposition

When facing complex business, the fundamental skill is decomposing the flow into modules, managing each module, and then considering how to connect them into a complete solution.

A typical transaction scenario decomposes into four modules:

Account Management : For users with payment enabled, clearly manage fund information such as available balance, frozen balance, and statements.

Transaction Records : Complete fund flow records, not limited to transactions but also including recharge, withdrawal, and refund.

Payment Integration : Payment functions usually integrate third-party payment platforms, so request and message logging must be handled.

Order Structure : In e-commerce, manage order models, splitting strategies, and payment product specifications.

Although actual details are far more complex than the illustration, the handling approach remains consistent. After module analysis, design sequence diagrams to plan node connections and collaboration.

2. Sequence Design

Sequence diagrams analyze how nodes should handle collaboration. Payment business typically divides into three core phases:

Pre-payment : On order placement, build the order model, validate inventory and product status per splitting rules, freeze account funds, generate transaction records — all in pending-payment state.

Payment Integration : After pre-payment model initialization succeeds, construct third-party payment request, initiate payment flow, record request actions and parameters, and await payment result notification.

Post-payment : Based on payment success or failure, execute corresponding business model state updates. On success, update transaction records, frozen funds, order structure, inventory, and more.

With clear business understanding and decomposition, plus well-designed sequence flows, a complex scenario becomes much simpler. The next step is designing data structures for each node.

3. Structure Design

Based on the above analysis and sequence diagrams, a basic structural design can be produced. The reference design includes six core tables:

Account Management : Three core dimensions — account amount, available balance, frozen amount.

Transaction Records : Store user transaction actions; may generate multiple transaction details, typical in shopping cart checkout.

Transaction Details : Orders often split into multiple details due to splitting, directing funds to different merchants.

Payment Integration : Record request parameters when calling third-party payment platforms, and callback notification payloads.

Order Records : An order may contain multiple split sub-orders; splitting strategies vary by warehouse, merchant, category, etc.

Order Details : Manage each sub-order's information — products, specifications, buyer/seller, unit price, quantity, amount.

Even this simplified design reveals payment complexity, which multiplies when overlaying coupon or discount rules. With clear development standards requiring decomposition, sequence, and structure designs to pass unified review before coding, even complex business achieves strong quality assurance.

Related Business

Beyond the main payment flow, e-commerce scenarios involve product management, inventory management, logistics management, and coupon rule embedding in payment integration.

Product Management

Product Core : Maintain multi-dimensional product information, provide specification options, basic pricing tiers, and build product detail descriptions.

Warehouse Management : After order splitting, validate warehouse info by product ID, perform inventory freezing, and handle warehouse shipping after payment.

Coupon Rules

Coupon Core : To fit more scenarios, design diverse rules — threshold discounts, discount ratios, tiered pricing by price, validity periods.

Distribution Rules : Support daily operations, user lifecycle maintenance, channel traffic conversion, providing user-group marketing capabilities.

Product and coupon businesses tightly couple with payment flow: e.g., insufficient inventory after splitting requires item removal; coupon usage strategy in payment and handling during refunds.

Practice Summary

From a technical implementation perspective, key issues in payment flow:

Business Model : Clear business understanding, decompose core nodes, design corresponding sequence flows and data structures.

Transaction Management : TCC (Try-Confirm-Cancel) pattern is commonly used — Try (pre-processing), Confirm (confirmation), Cancel (cancellation).

Locking and Retry : After payment success, a message is emitted and business updates follow. Typically lock the processed order ID to prevent data issues from message retry mechanisms.

Fund Settlement : Amount calculations must avoid precision loss; every fund movement in a transaction must be verifiable via reconciliation.

Process Maintenance : Flows inevitably encounter errors. During development, provide visual flow interfaces and support manual maintenance mechanisms.

Managing complex business scenarios requires long-term iteration, but the prerequisite is firmly grasping core logic. Business cognition moves from complexity to simplicity; business implementation moves from shallow to deep — analysis and understanding, to landing implementation, to exploration and innovation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backend developmentsystem designpayment systemorder managementtransaction processinge-commerce architecturefund settlementTCC transaction
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.