Frontend Development 18 min read

Cross-Platform Order Discount Calculation Framework: Design and Implementation

The Youzan retail team built a cross‑platform order discount calculation framework, evolving from JavaScript to a TypeScript‑based design that unifies online and offline scenarios, employs domain models, activity‑mutual‑exclusion graphs, and performance optimizations, delivering up to four‑fold productivity gains and consistent, high‑accuracy discount processing across all client platforms.

Youzan Coder
Youzan Coder
Youzan Coder
Cross-Platform Order Discount Calculation Framework: Design and Implementation

This article details the design and implementation of a cross-platform order discount calculation framework developed by the Youzan retail team. The framework addresses the challenges of order discount calculation in both online and offline retail scenarios, providing a unified solution across multiple client platforms.

The article begins by explaining the background and business scenarios of order discount calculation, highlighting the difficulties and pain points in offline retail scenarios, including the need for high accuracy, complex marketing activities, redundant development across multiple platforms, and potential inconsistencies in implementation.

The framework's evolution is described, from an initial JavaScript-based cross-platform solution to a complete TypeScript rewrite. The new design features static typing, domain models, activity mutual exclusion handling, and improved performance. Key design principles include domain models owning their own capabilities, high code reusability through cohesive models, and using composition over inheritance.

The article provides detailed technical insights into the framework's architecture, including input layer, core calculation layer, and result export layer. It explains the domain model design for both marketing activities and products, the processor abstraction template for handling different activity types, and the activity mutual exclusion model using undirected graphs.

Performance optimization strategies are discussed, including simplified data structures, avoiding deep copying, and using appropriate algorithms. The framework's testing coverage and quality assurance measures are also highlighted.

The article concludes with implementation details for backend calculation scenarios using Nashorn JavaScript engine, hot update mechanisms, version management, and memory optimization techniques. It also addresses challenges encountered during development, including version management, risk mitigation, and memory pressure optimization.

Overall, the framework has significantly improved development efficiency, achieving at least 4x productivity gains in order discount calculation scenarios across Youzan's retail platforms.

cross-platformperformance optimizationTypeScriptJavaScript EngineHot UpdateDomain Modelingorder discount calculationRetail Technology
Youzan Coder
Written by

Youzan Coder

Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.

0 followers
Reader feedback

How this landed with the community

login 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.