Technical Interview Questions

Distributed Transaction Design for WeChat Pay

"WeChat Pay processes millions of transactions per minute. How would you ensure data consistency across distributed services for a payment flow involving balance deduction, order update, and merchant settlement?"

Why Interviewers Ask This

WeChat Pay is a critical financial service handling massive transaction volumes. This question tests your understanding of distributed transaction patterns, data consistency guarantees, and fault-tolerant system design — essential skills for Tencent's fintech engineering teams.

How to Answer

  1. 1

    Outline the payment flow: user initiates payment → balance check → balance deduction → order status update → merchant account credit, involving multiple microservices and databases.

  2. 2

    Explain why traditional 2PC (two-phase commit) is unsuitable at this scale due to blocking and availability issues.

  3. 3

    Describe the Saga pattern with compensating transactions: each step has a corresponding rollback action if a downstream step fails.

  4. 4

    Discuss idempotency keys, transaction state machines, and asynchronous reconciliation as additional safety nets.

Sample Answer

For a WeChat Pay-scale system, I would use a Saga-based eventual consistency model rather than distributed 2PC. The payment flow is orchestrated by a transaction coordinator: Step 1 — reserve the user's balance (soft lock, not deducted yet); Step 2 — update the order status to "paying"; Step 3 — confirm the balance deduction; Step 4 — asynchronously credit the merchant's settlement account. Each step records its state in a transaction log. If Step 3 fails, compensating transactions execute in reverse: the order reverts to "unpaid" and the balance reservation is released. Every API call is idempotent using a unique transaction ID — retries produce the same result. A reconciliation service runs every few minutes, comparing the transaction log against each service's local state and flagging discrepancies for automated or manual resolution. For the balance service specifically, I would use optimistic locking with version numbers to handle concurrent deductions safely.

Pro Tips

  • Emphasize idempotency as non-negotiable in payment systems — interviewers will look for this specifically.

  • Mention reconciliation as the ultimate safety net, not just the happy-path Saga flow.

  • Discuss the difference between at-least-once and exactly-once semantics and why at-least-once plus idempotency is the practical choice.

Frequently Asked Questions

Why not use a distributed database with strong consistency instead of Saga?

Strong consistency across services requires coordination protocols (2PC/3PC) that reduce availability under network partitions. At WeChat Pay's scale, temporary inconsistency with guaranteed eventual reconciliation provides better availability and throughput while still ensuring correctness.

How do you handle the case where the user is charged but the order is not updated?

The transaction log records that the balance was deducted but the order update failed. The reconciliation service detects this inconsistency and either retries the order update or initiates a refund. Users can also trigger a manual check via the payment status inquiry API.

Worried About Going Blank in Your Interview?

HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.

Try HireMe AI Free