A Simplified RPC Framework: Core Principles and Implementation

This article introduces a lightweight RPC framework that demonstrates the essential publishing and invocation processes, explains the underlying SPI mechanism, and details service registration, load balancing, fault‑tolerance strategies, and module structure, providing code references and visual diagrams for practical understanding.

JD Retail Technology
JD Retail Technology
JD Retail Technology
A Simplified RPC Framework: Core Principles and Implementation

The article presents a simplified RPC framework inspired by Dubbo, aiming to help readers grasp the core publishing and invocation workflow without relying on third‑party software. It outlines the classic RPC architecture, including service registration, discovery, routing, load balancing, and optional monitoring.

Implemented features include an SPI mechanism, support for Netty or HTTP protocols via SPI selection, a file‑based service registry, cluster fault‑tolerance (safe‑fail or retry), and weighted random or round‑robin load balancing.

The demo consists of three modules: Provider (service implementation and publishing), Consumer (client startup and invocation), and SDK (registry, protocol, and other shared components). Visual diagrams illustrate the module relationships and runtime behavior.

A detailed explanation of the SPI mechanism shows how extensions are loaded through getExtensionLoader, getAdaptiveExtension, and getExtension, with accompanying sequence diagrams and resource loading logic.

The service publishing flow is described step‑by‑step, from Spring initialization to exporting the service via the selected protocol, ultimately starting a Netty server and registering the service in a local file.

The service invocation flow covers how a consumer creates an invocation object, selects a load‑balancer via SPI, and executes the remote call through Netty, including the role of the cluster component for fault tolerance.

Consumer startup and call processes are illustrated with sequence diagrams, highlighting Spring context loading, reference configuration, dynamic proxy generation, and the final Netty client invocation.

Fault‑tolerance strategies such as Failfast, Failsafe, and Failover are discussed, with an emphasis on the retry mechanism that loops until a successful call or all providers have been tried.

Load‑balancing strategies include a weighted random algorithm and a round‑robin approach, both configurable via weights to influence provider selection.

In summary, the article explains SPI’s role in extending protocol, clustering, and load‑balancing components, walks through the provider and consumer lifecycles, and demonstrates concrete implementations of fault tolerance and load balancing, giving readers a clear understanding of RPC fundamentals.

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.

JavaBackend DevelopmentRPCSPIservice registry
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

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.