How We Built a Scalable Reverse Transaction System for E‑Commerce

This article details the motivation, design goals, architecture, and implementation steps of a reverse transaction microservice that handles cash and promotional refunds, reduces technical debt, and improves operational efficiency for a fast‑moving e‑commerce platform.

NetEase Yanxuan Technology Product Team
NetEase Yanxuan Technology Product Team
NetEase Yanxuan Technology Product Team
How We Built a Scalable Reverse Transaction System for E‑Commerce

Background and Motivation

E‑commerce platforms generate many reverse‑transaction scenarios (order cancellation, after‑sale refunds, etc.). The original implementation bundled all reverse‑transaction logic in a shared JAR used by both C‑end and B‑end systems, causing documentation gaps, duplicated and tightly‑coupled code, and high coordination cost across teams.

Design Goals

Create a dedicated reverse‑transaction microservice to decouple refund logic from customer‑service, after‑sale, four‑end and payment systems, and expose its APIs via an interface platform.

Extract common cash‑and‑promotion reversal capabilities into a reusable domain service and use a workflow engine to make refund approval extensible.

Definition

A reverse transaction orchestrates the refund of cash and all promotional incentives for an already‑paid order.

Construction Approach

Boundary Governance: Analyse existing reverse‑transaction processes, code, and online issues; then encapsulate the domain in a microservice to improve reuse and reduce complexity.

Minimum Viable Delivery Unit: Split the project into phased deliveries, prioritising high‑value units such as the core refund capability.

Architecture Design

Modeling Phase: Conduct event‑storming workshops to agree on a shared domain model. Define domain capabilities (refund, refund query, refund calculation, order cancel, package cancel) and corresponding events (refund approved, refund succeeded, refund failed).

Implementation Phase: Adopt a classic four‑layer architecture (presentation, application, domain, infrastructure) within the defined business boundaries.

Key Application Scenarios:

Pre‑shipment customer cancel

Post‑shipment direct refund

Post‑shipment receipt‑then‑refund

Customer‑initiated direct refund

Pre‑shipment package cancel

Pre‑shipment user cancel

Post‑shipment refusal refund

Price protection

Return shipping fee

Customer‑service compensation refund

Channel refund

Channel compensation refund

Reward‑fund debt refund

Points debt refund

Core Process Design

Refund Approval (Extensible)

Manual approval reduces complaints and financial loss while providing a safety net for automated decisions. The workflow engine Activiti was chosen because it is open‑source, decouples refund creation from execution, matches the team’s expertise, and offers sufficient node granularity.

Refund Processing Flow

Two execution paths are defined:

Refund Execution: Handles regular refunds such as order cancel, package cancel, and after‑sale returns.

Compensation Refund Execution: Handles exceptional refunds like price protection and after‑sale compensation.

Both paths are orchestrated by Activiti without further node splitting to keep the design lightweight.

Maximum Refundable Amount Model

The system calculates the maximum refundable amount per order item; any request exceeding this amount is rejected, protecting against cash loss.

Special Refund Flows

For exchange orders, a new order is created for the replacement item while cash and promotions remain linked to the original order. Deposit‑purchase orders consist of a deposit order and a tail‑payment order; refunds must reverse cash and promotions across multiple payment records.

Message Handling

Non‑critical calls are decoupled via MQ. To further isolate business logic from message production, Guava EventBus is used, allowing observers to handle side‑effects independently.

Results

After migration to the microservice, refund, order cancel, and package cancel capabilities reduced operational effort by over 80% and lowered new‑feature integration cost by more than 50%. Ongoing work includes implementing refund query and calculation services to further improve efficiency.

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.

e‑commercemicroservicesworkflowSystem DesignRefund
NetEase Yanxuan Technology Product Team
Written by

NetEase Yanxuan Technology Product Team

The NetEase Yanxuan Technology Product Team shares practical tech insights for the e‑commerce ecosystem. This official channel periodically publishes technical articles, team events, recruitment information, and more.

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.