By Jun Liu
In terms of microservice protocol selection, we have observed a growing trend of applications transitioning from the Dubbo 2 TCP binary protocol to the Dubbo 3 Triple protocol (compatible with gRPC). This shift enables the exploitation of Triple's capabilities, such as high efficiency, full duplex, and streaming communication models. The combination of Triple and HTTP/2 effectively addresses the issue of backend service penetration. However, in the practical experiences, microservices built on the Triple protocol still impose high access costs for frontend devices. Users are required to access Triple backend services through gateway protocol conversion (similar to the previous Dubbo2 generic calls), which is expensive for development, testing, and O&M.
Given this context, we have upgraded the Triple protocol in Dubbo 3. The Triple protocol is an HTTP-based RPC communication protocol specification designed by Dubbo 3. It is fully compatible with gRPC and supports communication models such as Request-Response and Streaming. It is capable of running concurrently on HTTP/1 and HTTP/2.
You can use standard HTTP tools such as cURL to access services published by the Triple protocol.
curl \
--header "Content-Type: application/json" \
--data '{"sentence": "Hello Dubbo."}' \
https://host:port/org.apache.dubbo.sample.GreetService/sayHello
Based on the Triple protocol, you can easily build a Dubbo backend microservice system. Due to Triple's easy-to-use design for HTTP protocol, frontend devices such as Web, Mobile, and standard HTTP can easily access the backend system. Triple is also fully compatible with the gRPC protocol to realize interworking with the gRPC system.
The Dubbo framework offers various language implementations of the Triple protocol, which facilitate the development of browsers and gRPC-compatible HTTP API interfaces. All you need to do is define a service in the standard Protocol Buffer format and implement the business logic. Dubbo takes care of generating language-specific Server Stubs and Client Stubs, seamlessly integrating the entire calling process into the Dubbo system, including routing and service discovery. For certain language versions, the Dubbo framework also provides programming modes that better align with language features. This means you can define Dubbo services and publish them as microservices based on the Triple protocol communication using Java Interface and Pojo classes in Dubbo Java, without being bound by an Interface Definition Language (IDL).
You can achieve the following objectives based on the Triple protocol:
The Dubbo client can access Triple protocol services released by the Dubbo server and access the standard gRPC server.
• Call a standard gRPC server and send requests whose Content-type is standard gRPC: application/grpc, application/grpc + proto, and application/grpc + json
• Call the Dubbo server and send requests whose Content-type is Triple: application/json, application/proto, application/triple + wrapper.
The Dubbo server provides built-in support for both HTTP and gRPC protocols. The Triple protocol is capable of functioning on both HTTP/1 and HTTP/2. As a result, the Dubbo server can handle requests from the Dubbo client using the Triple protocol, standard gRPC protocol requests, as well as HTTP requests sent by cURL and browsers. These requests can be differentiated based on the Content-type header:
The Triple protocol fully supports communication using the Content-Type: application/grpc protocol. This means that the Triple client can interact with any gRPC server, and vice versa.
The Triple protocol supports exposing any service to the outside world using the widely-used JSON format. Clients that support the standard HTTP protocol, such as cURL, browsers, and terminals, can directly initiate calls without the need for any protocol conversion.
The Triple protocol allows for the encapsulation of Java-friendly serialization protocols like Hessian and Kryo on top of the HTTP protocol. From a network layer perspective, this results in a standard HTTP protocol message. The Triple protocol is naturally compatible with any Web Application Firewall (WAF) and Gateway that supports the HTTP protocol. It can effectively leverage existing network layer infrastructure.
For more details about Triple protocol specification, please refer to Triple Specification [1].
As mentioned earlier, Triple is fully compatible with the gRPC protocol. However, Dubbo chooses to implement Triple instead of relying solely on gRPC for two main reasons:
The native gRPC library implementation poses several challenges in real-world usage, including complex implementation, IDL binding, and difficulties in debugging. Dubbo tackles these problems through its protocol design and implementation practices:
• The native gRPC implementation is limited by the HTTP/2 interaction specification and cannot directly interact with browsers and HTTP APIs. Additional proxy components like grpc-web and grpc-gateway are required to enable such interactions. In contrast, Dubbo allows direct access to Triple protocol services using tools like cURL and browsers.
• The gRPC official library enforces Protocol Buffers as the only option for service definition and management through IDL. This can be a burden for users who do not have strong multi-language requirements. In contrast, Dubbo not only supports IDL but also provides language-specific service definitions and development methods for Java and Go.
• Debugging services released under the gRPC protocol can be challenging, as it requires the use of gRPC-specific tools, which often lack maturity and advanced debugging features. Starting from Dubbo 3, debugging becomes easier with tools like curl | jq or Chrome developer tools. Services can be called directly by passing JSON structures.
• The gRPC library has over 100,000 lines of code, whereas Dubbo's protocol implementation (including Go, Java, Rust, and Node.js) consists of only a few thousand lines. This makes code maintenance and troubleshooting much simpler.
• Google's gRPC implementation library maintains its own set of implementations instead of utilizing mainstream third-party or language official protocol libraries. This adds complexity to maintenance and ecosystem expansion. For example, grpc-go maintains its HTTP/2 library instead of using the official Go library. In contrast, Dubbo leverages the official libraries and maintains the same performance level as the HTTP protocol library maintained by gRPC.
• The gRPC library focuses solely on RPC protocol implementation and requires additional effort to introduce service governance capabilities. Dubbo, being a microservice development framework, does not bind to specific protocols. Its built-in HTTP/2 protocol implementation seamlessly integrates with Dubbo's service governance capabilities.
The implementation of the Dubbo framework focuses on the Triple protocol itself, while the choice of underlying network communication and HTTP/2 protocol parsing relies on well-tested network libraries. For example, Dubbo Java is built on Netty, while Dubbo Go directly utilizes the official HTTP library of Go.
The Triple protocol implementation provided by Dubbo is extremely simple. By comparing it to the implementation of the Protocol component in Dubbo, one can easily understand the code implementation of the Dubbo protocol in just one afternoon.
Since the release of Dubbo 3, the Triple protocol has been widely adopted in Alibaba and many community benchmarking enterprises, particularly in proxy and gateway interworking scenarios. This is because the Triple protocol has proven to be reliable and stable through extensive production practice. Additionally, its advantages, such as simplicity, easy debugging, and the design that does not bind IDL, have contributed to its popularity.
When using the Dubbo framework as the server to expose services to the outside world, Triple, gRPC, and HTTP/1 protocols can be natively supported on the same port. This means that services published by the Dubbo server can be accessed in multiple forms, and all request forms will ultimately be forwarded to the same business logic implementation, providing greater flexibility.
Dubbo is fully compatible with the gRPC protocol and its related features, including streaming, trailers, and error details. If you choose to use the Triple protocol in the Dubbo framework (you can also opt for the native gRPC protocol), you can directly use the Dubbo client, curl, and browser to access your published services. In terms of interoperability with the gRPC ecosystem, any standard gRPC client can access Dubbo services, and the Dubbo client can also invoke any standard gRPC services. Here are some examples of interoperability [2].
The following is an example of using the cURL client to access the Triple protocol service on the Dubbo server:
curl \
--header "Content-Type: application/json" \
--data '{"sentence": "Hello Dubbo."}' \
https://host:port/org.apache.dubbo.sample.GreetService/sayHello
We are all aware that Dubbo offers extensive microservice governance capabilities, such as service discovery, load balancing, and traffic control. These capabilities are the key advantages of using the Dubbo framework for application development. There are two methods to enable gRPC protocol communication in the Dubbo system. One is to directly integrate the official gRPC binary packages into the Dubbo framework, while the other is to provide native source code implementation in Dubbo that is compatible with the gRPC protocol.
Compared to the first approach which involves introducing binary dependencies, the Dubbo framework natively supports the gRPC protocol using its built-in Triple protocol. The advantage of this method is that the Dubbo framework has complete control over the source code. As a result, the protocol implementation is more tightly integrated with the Dubbo framework, allowing for more flexible connectivity to the Dubbo service governance system.
Based on the Triple protocol design, our plan is to provide lightweight RPC protocol implementations for as many languages as possible. This will ensure that the Triple protocol covers multiple language stacks, is compatible with gRPC, and is easier to use. Additionally, Dubbo will continue to provide comprehensive microservice governance capabilities for widely used languages like Java and Go, making Dubbo a powerful microservice development system that can seamlessly connect the frontend and backend.
The Java language implementation of the Dubbo library has achieved the initial goal of upgrading the Triple protocol in version 3.3.0-triple-SNAPSHOT. For more information, see samples/dubbo-samples-triple-unary.
Other languages being synchronously implemented using the Triple protocol include Go, Node.js, Rust, and JavaScript for web development.
In the implementation of the Dubbo Java library, besides the IDL mode, you can use the Java Interface mode to define services. This option greatly reduces the cost of using the gRPC protocol for Java users who are already familiar with the Dubbo system.
Furthermore, the Java version of the protocol implementation has performance comparable to the grpc-java library and even performs better in some scenarios. However, this is primarily due to the fact that the Dubbo version of the protocol is much simpler to implement compared to the grpc version, as grpc-java maintains a set of customized HTTP/2 protocol implementations.
Library address: https://github.com/apache/dubbo
Dubbo Go recommends the IDL development mode. The stub code is generated through the protoc plug-in provided by Dubbo. You only need to provide the corresponding business logic implementation. You can access the gRPC service released by Dubbo Go through cURL and a browser.
Library address: https://github.com/apache/dubbo-go/
Dubbo Rust has fully implemented gRPC protocol compatibility and is working towards supporting unary RPC calls in HTTP/1 and other modes.
Library address: https://github.com/apache/dubbo-rust/
Node.js has fully implemented gRPC protocol compatibility and is currently working on supporting unary RPC calls in HTTP/1 and other modes.
Library address: https://github.com/apache/dubbo-js/
The JavaScript client library provided by Dubbo enables you to write frontend pages that run in the browser and directly initiate requests to call backend Dubbo services.
Library address: https://github.com/apache/dubbo-js/
[1] Triple Specification (In Chinese)
https://cn.dubbo.apache.org/zh-cn/overview/reference/protocols/triple-spec/
[2] Interoperability Example
https://github.com/apache/dubbo-samples/tree/triple-protocol-sample-0719/2-advanced/dubbo-samples-triple-grpc
An Exploration and Improvement of Dubbo in Proxyless Mesh Mode
506 posts | 48 followers
FollowAlibaba Cloud Native Community - January 26, 2024
Alibaba Cloud Native Community - August 1, 2024
Alibaba Cloud Native Community - December 19, 2023
Alibaba Cloud Native Community - December 1, 2023
Alibaba Cloud Native Community - January 26, 2024
Alibaba Cloud Native Community - December 7, 2023
506 posts | 48 followers
FollowMSE provides a fully managed registration and configuration center, and gateway and microservices governance capabilities.
Learn MoreAccelerate and secure the development, deployment, and management of containerized applications cost-effectively.
Learn MoreHTTPDNS is a domain name resolution service for mobile clients. It features anti-hijacking, high accuracy, and low latency.
Learn MoreEMAS HTTPDNS is a domain name resolution service for mobile clients. It features anti-hijacking, high accuracy, and low latency.
Learn MoreMore Posts by Alibaba Cloud Native Community