Cross‑Platform Refactoring of WeChat Pay: Architecture, Performance, and Lessons Learned
This article describes how the WeChat Pay team rebuilt the client‑side payment flow using a C++ cross‑platform framework, detailing the architectural redesign, performance improvements, routing mechanism, network request handling, and data‑flow safeguards that unified iOS and Android implementations while reducing code size and enhancing reliability.
The WeChat Pay client faced major issues due to separate iOS and Android implementations, including inconsistent bugs, poor scalability, weak quality assurance, and divergent user experiences.
To address these problems, the team created a unified C++ cross‑platform framework that abstracts the payment flow into reusable UseCase and UIPage components, reducing the core payment code from 6,328 lines on iOS to 3,512 lines across platforms—a 45% reduction.
Performance metrics show stable crash rates after rollout and a 45% decrease in code size for core payment logic. Development effort for new features dropped from a week of work per platform to a combined 3‑5 person‑days.
A routing mechanism was introduced, where payment‑related data is modeled as a domain‑specific protocol (Proto). The router parses this data and triggers actions such as opening a UseCase, launching a UI page, or invoking a webview, thereby centralising special‑case handling and eliminating duplicated logic.
Network requests were refactored by encapsulating each CGI call into an independent object with a clear lifecycle tied to its UseCase, replacing the previous singleton‑based approach. This solved one‑to‑many communication bugs and lifecycle issues.
Data transmission was normalised by removing shared mutable models, adopting immutable value types, enforcing unidirectional data flow, and using delegate patterns for necessary callbacks. This eliminated data‑pollution bugs that previously caused UI anomalies.
Overall, the new architecture unifies process flow, improves maintainability, and provides a solid foundation for future feature development, automated reporting, and security enhancements.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.