Polarized Evaluation: The Pros and Cons of gRPC in Internal Service Communication

2024-05-14 10:41:11

What is the real opinion of developers on gRPC? It’s no secret that gRPC is widely used in large software companies. Google initially developed Stubby as an internal RPC protocol in 2010. In 2015, Google decided to open source Stubby and renamed it to gRPC. Both Uber and Netflix place great value on microservices, and

What is the real opinion of developers on gRPC? It’s no secret that gRPC is widely used in large software companies. Google initially developed Stubby as an internal RPC protocol in 2010. In 2015, Google decided to open source Stubby and renamed it to gRPC. Both Uber and Netflix place great value on microservices, and have widely adopted gRPC. Although I personally have never used gRPC, my colleagues quite like it.
So, what is the real opinion of developers on gRPC? To figure this out, I visited developer hubs: Reddit, Twitter, Hacker News, and YouTube. In this article, I analyzed 1000 discussions and summarized them, trying to provide only some thought-provoking views.
Next, I noted these discussions on a whiteboard and categorized them into three groups: in favor of gRPC, against gRPC, or neutral, then aggregated them into different viewpoints. Each section of this article introduces one viewpoint and cites related discussions.
gRPC tools are very suited for inter-service communication The most commendable aspect of gRPC is its excellent code generation tools and efficient data exchange formats, which significantly improve the experience and performance of service interaction development.
“Well-defined error codes… not to mention cross-platform support and code generation…”
“I like using gRPC for inter-service communication.”
“…for internal services, code generation is a must…”
“…generate client and server side code using the programming language you use… for features with a high volume of API calls, it can save about 30% of development time…”
“gRPC is superior in cross-language capabilities than many other formats…”
“…its massive code generation ecosystem can generate anything for you, from standard gRPC servers to traditional JSON APIs. This ecosystem supports almost all popular languages…”
Typically, engineering teams are responsible for managing multiple services while also interacting with services managed by other teams. Code generation tools help developers shorten the development process and make the services they create more reliable. Protocol Buffers encourage engineers to focus on the interfaces and data models they expose to other teams, promoting uniformity in the workflow between different groups. The main benefits of gRPC mentioned above are as follows:

  • Client and server-side stub code generation tools
  • Data governance framework
  • Language-independent runtime performance
  • Well-defined error codes

If your organization is developing a large number of internal microservices, then gRPC might be a good choice.

Comparison of gRPC and REST

When building applications, developers often need to decide which technology to use. gRPC offers a straightforward method; due to its abstraction of the complexity of the HTTP protocol, it is easier for beginners to understand and use. It spurs on the development process, aiding developers in constructing applications more efficiently. The convenience of gRPC lies in its ability to establish clear contracts between server and client, allowing all parties to develop according to their own understanding and needs.

Limitations of REST

In contrast, REST requires developers to have a deeper understanding of the HTTP protocol. Defining and consuming APIs with REST is more error-prone as it is a web service architectural style built upon the underlying protocol. It is mainly oriented toward code generation and data governance and does not naturally accommodate the complexity of software systems as gRPC does. Furthermore, the use of REST standards like OpenAPI (formerly known as Swagger), despite being widely used, lacks strict requirements on the underlying protocol, which can lead to API consumers not accessing the expected data model. This loosely coupled relationship may become a source of confusion for developers.

Practical Challenges of gRPC

Despite gRPC being theoretically a better choice for high-quality APIs, it also comes with its challenges in practice. For instance, it complicates key functionalities such as load balancing, caching, debugging, authentication, and browser support. The ensuing questions are: How to implement load balancing for gRPC services? How to cache? How to debug? How to handle authentication? How to offer support in browsers? These are doubts that must be addressed when using gRPC.

Standard-Based REST

Facing these practical issues of gRPC, some developers might return to building REST APIs. After all, REST is constructed based on Internet standards, and its rules and enforcement are globalized and standardized. Sometimes, adhering to standard technology is a wiser choice than trying emerging technologies. Nonetheless, every project has different requirements, so the decision between gRPC or REST should be made based on the specifics of the case.

Even though REST is a widely applied and battle-tested standard, some still explore alternative solutions. Some argue that REST already meets the needs of most projects, so there might not be a necessity to look for an alternative solution. Indeed, by using REST, developers can enjoy the convenience of tools and infrastructure while avoiding the maintenance burden that new technologies might bring.

Of course, there’s a viewpoint that the emergence of gRPC is based on specific scenario needs; for example, Google introduced gRPC to create a high-performance inter-service communication protocol. gRPC indeed offers a good experience and performance boost in the development of internal services. However, we also need to realize that gRPC is not designed for use in all situations, especially since browser support is not its main focus.

And gRPC and REST are not irreconcilable contradictions. gRPC is very suitable for communication between internal services, facilitating collaboration among developers and enhancing data transmission efficiency. To support browser-side applications, additional components like grpc-web emerged for compatibility adaptations. In contrast, REST or GraphQL are more suitable as communication protocols for external service edges. External services often involve specific requirements such as caching and load balancing, which gRPC cannot directly satisfy.

Hence, choosing the right technological approach requires consideration of its own strengths and weaknesses, as well as long-term maintenance costs and technical compatibility. In most cases, REST will be a safe choice, but in specific scenarios like efficient communication between internal services, gRPC can also be very useful. In this way, developers can focus on how to optimally combine these two technologies, rather than blindly pursuing either the novel or the traditional extreme.

Selecting the right tools for the job is crucial. Although gRPC was open-sourced by Google in 2015, it is still maturing, which means many open-source tools are yet to be developed. Effective gRPC native tools still require further supplementation and improvement.

In different programming language environments, gRPC’s performance varies significantly. For example, in Python, gRPC may be relatively slow, but if implemented in C++, it could be up to 100 times faster.

Key Points

From cURL to Postman, REST APIs have been supported by many mature tools, and users can refer to detailed documentation to use these tools. On the contrary, although gRPC also has some tools, they still lag behind the maturity and documentation completeness of REST tools. However, with the increasing popularity of gRPC, its ecosystem is also developing rapidly. The emergence of open-source tools such as Grpcurl and grpcui is a testament to the growing momentum of gRPC. Companies like Buf are actively contributing to the ecosystem by building advanced tools to enhance the gRPC development experience.

gRPC is a technology that has sparked much discussion. It has shown excellent development experience and performance in the communication between internal services, but a portion of developers remain reserved in comparison with REST. For us, we choose to use REST for external APIs and combine REST/GraphQL for internal service communication. Although at present we don’t have an urgent need to integrate gRPC into our workflow, the enthusiastic support and recognition of gRPC within the community still make a deep impression. Observing the evolution and expansion of the gRPC ecosystem over the next few years will undoubtedly be an exciting journey.