How JD’s 京麦 Platform Achieves High‑Performance API Gateways and Reliable Messaging

This article explains how JD’s 京麦 open platform evolved from a simple Nginx‑Tomcat deployment to a decentralized, high‑performance API gateway and robust TCP‑based messaging system, detailing architectural choices such as OAuth2, ZooKeeper‑driven metadata, multi‑level rate limiting, Protobuf, and Netty‑powered push services.

21CTO
21CTO
21CTO
How JD’s 京麦 Platform Achieves High‑Performance API Gateways and Reliable Messaging

High‑Performance API Gateway

JD’s internal data is distributed across independent business systems (order, product, merchant centers) and exchanged via the Jingdong Service Framework (JSF). The API gateway, built on OAuth2, exposes these services to ISVs using HTTP JSON.

The gateway intercepts requests at an access layer, performing defense checks (degradation, rate limiting, multi‑level caching) and then dispatches calls based on a registration center, dynamically constructing service instances for generic invocation.

To handle 618 high‑traffic scenarios, the gateway optimizes service scheduling, authentication, payload transformation, load balancing, caching, monitoring, and logging.

Unified API Metadata Configuration

Metadata such as field definitions, flow‑control rules, app keys, IP whitelists, and permissions are critical for performance; reading directly from a database is insufficient. Instead, a ZooKeeper‑based configuration with multi‑level caches (ZooKeeper, memory, local files) provides instant updates and automatic disaster recovery.

When reading metadata, the gateway first checks memory, falls back to ZooKeeper, syncs to memory, and saves a snapshot. Changes are propagated via ZooKeeper watchers; if ZooKeeper fails, local snapshots enable recovery.

TCP Full‑Duplex Long‑Connection Channel

Beyond the HTTP gateway, a TCP gateway establishes bidirectional long‑lived connections using Netty, encapsulating each TCP connection into a Session object stored in a container, enabling decoupled service calls and finer control.

Sessions abstract the transport layer, simplifying connection management compared to raw TCP programming.

Reconnection Handling

In unstable networks, clients may lose connectivity without closing the channel. The server detects inactive channels every five minutes, reuses existing Session IDs when possible, and ensures seamless reconnection across cluster nodes.

Protobuf Data Exchange

To reduce payload size compared to JSON, the TCP gateway adopts Protobuf, supporting Java, Objective‑C, and C++ clients across desktop, iOS, and Android platforms.

Multi‑Dimensional Traffic Control

Different APIs have varying capacities; the gateway employs token‑bucket rate limiting via Guava RateLimiter and dynamic thresholds from a unified configuration center, as well as per‑method concurrency limits using JDK Semaphores.

Highly Reliable Message Service

Instead of polling, the platform provides an asynchronous, real‑time push channel. AnyCall aggregates messages from various business centers, stores them in Elasticsearch and HBase, and the push system built on Netty delivers them via silent long‑connections.

The system supports a “half‑push‑half‑pull” model where only notifications are pushed, and clients fetch full content on demand, reducing bandwidth and storage on weak devices.

Message confirmation is ensured by assigning a sequence ID to each outbound notification and waiting for client acknowledgment; unacknowledged messages are retransmitted after a 10‑second timeout.

APNs Push Refactoring

iOS push is reimplemented using Netty with HTTP/2, providing synchronous and asynchronous modes, handling channel exceptions, reconnections, and heartbeat maintenance via IdleStateHandler.

Conclusion

The evolution of the 京麦 platform highlights service governance challenges—organizing call relationships and building an ecosystem rather than isolated systems—to continuously improve operational capability, summarized by the principle “精打细算,大道至简”.

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.

TCPhigh concurrencyOAuth2
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

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.