Design and Implementation of a Custom RPC Framework

The article explains RPC fundamentals and why they are vital for distributed systems, then details the core components—service provider, consumer, and registry—along with extensions such as load‑balancing, circuit breaking, and serialization, and walks through a concrete Java implementation using Zookeeper, Netty, custom protocol, JSON/Protobuf, and Spring Boot SPI plugins.

DeWu Technology
DeWu Technology
DeWu Technology
Design and Implementation of a Custom RPC Framework

This article introduces the concept of Remote Procedure Call (RPC) frameworks, explaining why they are essential for modern distributed systems and micro‑service architectures.

It adopts the three‑question (What, Where, Why) approach: RPC is a mechanism that allows a client to invoke methods on a remote service as if they were local; it is used wherever services need to communicate across process or machine boundaries; and it is needed to handle service registration, discovery, load balancing, fault tolerance, and other cross‑cutting concerns.

The basic components of an RPC framework are described: Service Provider, Service Consumer, and Registry. Additional extensions such as load balancers, circuit breakers, communication and serialization protocols are also listed.

The article details the role of a Registry (e.g., Zookeeper, Nacos, Consul, Eurake) and compares their consistency models, avalanche protection, multi‑data‑center support, and automatic instance deregistration.

For the Service Provider, the article discusses interface‑based versus service‑based registration, noting the shift toward service‑oriented registration in cloud‑native environments.

The Service Consumer section explains how it retrieves and caches service lists, applies load‑balancing strategies, performs serialization/deserialization, and invokes remote methods via a chosen communication protocol.

The communication framework is built on Netty (Java NIO), and the custom communication protocol is defined with a magic number, version, request type, and length‑prefixed payload.

Serialization options include XML, JSON, and Protobuf, with emphasis on JSON and Protobuf for their compactness and performance.

Load‑balancing strategies covered are round‑robin, random, weighted round‑robin, and consistent hashing.

Implementation choices for the sample RPC framework are summarized: Zookeeper as the Registry, service‑oriented registration, Dubbo‑style proxy generation for the consumer, Netty for networking, a length‑prefixed custom protocol, JSON/Protobuf serialization, and round‑robin/random load balancing. The framework is designed as Spring Boot SPI plugins for extensibility.

Several architecture diagrams and code snippets (provider registration, consumer proxy generation, load‑balancer SPI, Netty client/server) are presented to illustrate the overall structure and workflow.

In conclusion, the article provides a comprehensive overview of RPC fundamentals, component design, and a practical implementation that can be extended for performance tuning and scalability.

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.

JavaRPCload balancingservice discoveryserializationNetty
DeWu Technology
Written by

DeWu Technology

A platform for sharing and discussing tech knowledge, guiding you toward the cloud of technology.

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.