Understanding Remote Procedure Call (RPC) and Its Implementation in Java
This article explains the concept of Remote Procedure Call (RPC), why distributed systems need remote invocation, the roles of provider, consumer and registry, essential technologies such as dynamic proxies, serialization and NIO, and introduces popular open‑source Java RPC frameworks.
RPC (Remote Procedure Call) is a computer communication protocol that allows a process on machine A to invoke a process on machine B as if it were a local call.
The need for remote calls is illustrated with a restaurant analogy: as a kitchen grows and tasks are split among chefs, assistants, and prep cooks, the head chef must coordinate with others, similar to services coordinating in a distributed system.
制作番茄炒蛋{<br/> 厨师->洗菜->切菜->炒菜<br/>}When multiple roles are involved, the chef depends on others to complete preparatory steps before cooking, mirroring remote procedure calls where a service depends on other services.
制作番茄炒蛋{<br/> 备菜师->洗菜<br/> 切菜师->切菜<br/> 厨师->炒菜<br/>}In a typical e‑commerce order flow, services such as inventory, payment, coupons, and logistics must be invoked remotely to complete the order.
下单{<br/> 库存->减少库存<br/> 支付->扣款<br/> 红包->红包抵用<br/> 物流->生成物流信息<br/>}RPC abstracts the network communication so that developers can call remote services like local methods, e.g., orderService.buy("HHKB键盘"), without handling low‑level networking.
An RPC framework provides three main roles: Provider (service host), Consumer (service client), and Registry (service discovery). The registry acts like a kitchen manager, keeping track of available service instances and enabling load balancing.
Key technologies required to build an RPC framework include:
Dynamic proxy generation (JDK proxy, CGLib, Javassist) to create client and server stubs.
Serialization (Java native, protobuf, Thrift, Hessian, Kryo, Msgpack) to transmit objects over the network efficiently.
Network I/O (Netty or other NIO libraries) for high‑performance communication.
Service registry solutions (Redis, Zookeeper, Consul, Etcd) for registration and discovery.
Several open‑source Java RPC frameworks are mentioned:
Dubbo : Alibaba’s high‑performance RPC framework, now an Apache incubating project.
Motan : Sina Weibo’s RPC framework used for billions of daily calls.
gRPC : Google’s cross‑language RPC framework based on HTTP/2 and Protocol Buffers.
Thrift : Apache’s cross‑language service framework.
The article concludes with references and visual diagrams illustrating the concepts.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
