00 Preface Don't Always Think About How to Use Rpc Framework Well, You Need to Spend Time Grinding the Principles

00 Preface - Don’t always think about how to use RPC framework well, you need to spend time grinding the principles #

Hello, I am He Xiaofeng. Welcome to join me in learning about RPC.

Before we start this column, let me briefly introduce myself. I graduated from Beihang University in 1998, and I have been coding in the front line ever since. In 2011, I officially joined JD.com and coincided with JD’s rapid development period. Along the way, I have reached the position of Chief Architect in the Technology Architecture Department. Looking back at the 9 years I have spent at JD, I have participated in 17 major promotions and witnessed the technological evolution of JD with my technical team. I have also led my team to overcome many technical challenges, including independently developing microservice frameworks, high-performance message middleware, intelligent monitoring, and container platforms.

In recent years, I have been focusing on distributed system architecture and design, which is also my area of expertise. In the process of building distributed systems, I have found that RPC always plays a critical role and its contribution to improving the performance of the entire distributed system is very important.

Through this column, I hope to share with you some practical experiences I have accumulated over the years regarding RPC.

Why Learn RPC? #

When it comes to learning RPC, we should start with why. To answer this question, we need to first consider the practical application scenarios of RPC.

RPC is often associated with “microservices”. The biggest advantage of RPC is that it allows us to make remote method calls as if they were local. This feature often leads people to think that RPC is specifically designed for “microservices” or SOA (Service-Oriented Architecture). Nowadays, as most application systems grow to a certain scale, they evolve towards “microservices”. Large-scale application systems are indeed composed of individual “microservices”.

We can say that RPC is the foundation of “microservices”, and this is beyond doubt. Now, let’s think about a question in reverse - does RPC only apply to “microservices”?

Certainly not, we may use RPC whenever there is a need for network communication. Here are two examples.

Example 1: Large-scale distributed application systems may depend on message queues, distributed caching, distributed databases, and centralized configuration services. RPC can be used for communication between applications and these middleware services. For example, etcd, as a centralized configuration service, communicates with clients using the gRPC framework.

Example 2: We often talk about the container orchestration engine Kubernetes, which is inherently distributed. The communication between Kubernetes’ kube-apiserver and each component in the distributed cluster is done through the gRPC framework.

Therefore, the application scenarios of RPC are still very broad. Since it has such a wide range of applications, where is its core value?

In my opinion, RPC is a powerful tool for solving communication problems in distributed systems.

Network communication in distributed systems generally uses the fourth layer TCP protocol or the seventh layer HTTP protocol. In my understanding, the former is more commonly used, mainly because of the stability and efficiency of the TCP protocol. Network communication may sound simple, but in reality, it is a very complex process. This process mainly includes searching for the target node, establishing network connections, encoding and decoding data transmission, and managing network connections, all of which are very complex.

Imagine this: in the process of building a complex distributed system, if developers have to deal with a series of complicated code for every logic related to network communication, it would be a terrifying task. Therefore, network communication is a major challenge in building distributed systems, and it deserves great attention.

RPC provides a complete package for the entire network communication process. When building a distributed system, RPC makes the development of network communication logic simpler and also makes network communication more secure and reliable.

Now, do you feel that it is necessary to learn RPC?

How to Learn RPC? #

So how should we go about learning RPC?

Actually, once we deeply understand the why, it is not difficult to find the answer to how to learn it. Based on my own experience, I believe that the learning process can be summarized in four words: “gradual in-depth exploration.”

It’s actually quite simple. When we realize that using RPC allows us to make remote calls as if calling local functions and can solve communication problems, then we definitely need to learn about serialization, encoding/decoding, and network transmission.

Once you have mastered these concepts, you will discover that these are just the basics of RPC. RPC has even more fascinating aspects. Its real power lies in its governance features, such as connection management, health checks, load balancing, graceful shutdown and startup, error retries, business grouping, and circuit breaking and flow control. Suddenly, you will feel like you have entered a new world, and these topics will become the focus and challenges of your future study of RPC.

This gradual in-depth exploration process certainly cannot be separated from real-world practice. Learning knowledge, solving problems, encountering new problems, continuing to learn, constantly solving problems—finally, you will find that your learning curve is roughly like this:

To summarize, when learning RPC, we need to first understand its basic principles and key parts of network communication, without blindly relying on existing frameworks. After that, we can focus on and learn about the challenging aspects of RPC, such as its governance and cluster management features within the RPC framework. At this point, you will already have a solid understanding, but this is not the end. We need to apply and utilize RPC in real-life scenarios, learn how to optimize its performance, and understand how to troubleshoot issues in a distributed environment, and so on.

What can you learn from this column? #

The contents mentioned above are what I want to share with you through this column. Now let me explain the design concept of this column.

I have divided the content of the entire column into three main parts: the basic part, the advanced part, and the advanced part.

Basic Part: Emphasis will be placed on explaining the basic knowledge of RPC, including the basic principles of RPC and its basic functional modules. After laying a solid foundation, we will apply the knowledge points through a practical case study of an RPC framework.

Advanced Part: The focus will be on explaining the architectural design of the RPC framework, as well as knowledge related to RPC framework clusters and governance. In this part, I will provide many practical problems encountered in operating an RPC framework along with their solutions.

Advanced Part: After studying the above two parts, you will have a relatively high-level understanding of RPC. In this part, I will mainly explain the application of RPC from the perspectives of performance optimization, troubleshooting online problems, and designing unique features.

By following this column, you will not only learn about RPC-related knowledge, but also come across numerous case studies and solutions. First of all, these examples and solutions will help you develop a higher understanding of RPC. Secondly, these knowledge and solutions will have universal application, which will greatly assist you in your future work as long as you can apply them flexibly.

Lastly, I am also eager to hear your thoughts. We can get to know each other in the comments section. I look forward to hearing about your work experience, your understanding of RPC, as well as the pain points and challenges you face in learning it. This will allow me to provide you with targeted explanations. Now, let us embark on this learning journey together!