Understanding the Basic Structure and Technical Stack of RPC Architecture
This article explains the fundamental components of RPC architecture, details the client‑server roles, communication protocols, serialization methods, transport protocols, and synchronous versus asynchronous invocation patterns, providing a comprehensive guide for building a custom RPC framework.
When building a distributed system, service‑to‑service communication is essential, and while frameworks like Dubbo or Spring Cloud can simplify this, implementing remote calls without such frameworks requires a custom RPC solution.
Basic Structure of RPC Architecture
The RPC model involves a Provider (service) and a Consumer (client), where the consumer initiates remote calls to obtain results. Key components include RpcChannel and RpcProtocol for network communication, RpcAcceptor on the provider side, and RpcConnector on the consumer side.
Both sides share a contract called Remote API, distinguishing it from local APIs. The provider implements the Remote API via RpcServer , while the consumer accesses it through RpcClient . The request flow involves RpcCaller encoding the request, RpcInvoker executing it on the server, and RpcProxy offering a local‑method‑like entry point.
Server‑side processing is managed by RpcProcessor , which handles threading, timeouts, and other controls.
Technical Stack of RPC Architecture
Network Communication
Performance considerations favor TCP long connections and non‑blocking I/O (NIO) over blocking I/O (BIO). Reliability is addressed through link health checks and reconnection logic.
Serialization
Data transmitted over the network must be serialized; common choices include text‑based formats like XML/JSON and binary formats such as Protocol Buffers and Thrift. Performance metrics (time, space, CPU/memory) guide the selection, with fastjson excelling in speed and Protocol Buffers offering compact size.
Transport Protocol
RPC implementations typically build on TCP (transport layer) or HTTP (application layer), adding custom headers and payload structures to create private protocols that improve performance and extensibility, as exemplified by Dubbo’s custom protocol.
Remote Invocation
RPC supports synchronous (request‑response) and asynchronous (one‑way) invocation modes. Synchronous calls block the caller thread, while asynchronous calls use Java Futures, either via a blocking Future.get() or a callback FutureListener . Other patterns like parallel or generic calls exist but are less common.
Summary
RPC is a foundational technology for inter‑service communication in distributed systems. Understanding its components, communication protocols, serialization choices, and invocation models equips developers to design and implement custom RPC frameworks or evaluate existing solutions.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
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.