Backend Development 6 min read

Asynchronous Refactoring of the Shopping Cart to Boost Performance

The article outlines the growing challenges of a high‑traffic shopping cart caused by numerous RPC dependencies, proposes a full asynchronous redesign—including parallel RPC calls, batch pagination, and JSF CompletableFuture usage—addresses retry, monitoring, and timeout issues, and reports a 30% latency reduction.

JD Retail Technology
JD Retail Technology
JD Retail Technology
Asynchronous Refactoring of the Shopping Cart to Boost Performance

Background: The shopping cart faces challenges as new business scenarios increase the number of external RPC interfaces, some calls are moved to the cart middle‑platform, pre‑processing steps like coupons are placed before checkout, and the cart must handle a growing number of items, leading to more RPC calls and pagination requests.

Asynchronous Refactoring Plan: Instead of adding server resources, the solution is to transform the cart to a fully asynchronous architecture. Key steps include:

Parallelizing different RPC calls by analyzing dependencies and splitting code into asynchronous request and result‑handling parts.

Parallel batch pagination: wrapping batch RPCs with an asynchronous pagination tool that automatically splits data into multiple pages and calls them concurrently.

Using JSF asynchronous calls (Jingdong RPC framework) with CompletableFuture support (version 1.7.5+).

Problems and Solutions:

Fine‑grained retry: After switching to async, retries must be performed on timeout during result processing, and only the failed page should be retried. Exceptions like rate‑limit should not be retried; the tool filters them automatically.

Complex async RPC monitoring: Separate timing for request start, async result arrival, and Get timeout, recording failures and distinguishing normal and retry calls.

Preserving async results per page: Results must be wrapped and returned unchanged to retain Provider information for timeout diagnostics, avoiding merging of async results.

Per‑page timeout control: Each page’s Get timeout is calculated as timeout = RPC_timeout > (now - async_start) ? RPC_timeout - (now - async_start) : 0 , ensuring total wait does not exceed the page limit.

Pagination balancing: Data is evenly distributed across pages to avoid skew on the last page.

Benefits: After refactoring, core cart interface latency decreased by about 30%, improving user experience while saving significant server resources. Adding new RPCs on non‑critical paths has minimal impact, and capacity growth effects are reduced.

backendPerformanceRPCasynchronouspaginationshopping cart
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

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.