×
Community Blog Major Upgrade of Dubbo Triple Protocol: Support for Connecting the Web and Backend Microservices Over HTTP

Major Upgrade of Dubbo Triple Protocol: Support for Connecting the Web and Backend Microservices Over HTTP

The Dubbo Triple Protocol has undergone a major upgrade, allowing for seamless connectivity between web and backend microservices over HTTP.

By Jun Liu

Newly Upgraded Triple Protocol

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.

1

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).

Design Objectives and Applicable Scenarios of Triple Protocol

You can achieve the following objectives based on the Triple protocol:

When Dubbo Is Used as the Client

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.

When Dubbo Is Used as the Server

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:

  • Requests from gRPC clients with Content-type set to standard gRPC: application/grpc, application/grpc + proto, application/grpc + json
  • Requests from Dubbo clients with Content-type set to Triple: application/json, application/proto, application/grpc + wrapper
  • Requests from cURL and browsers with Content-type set to Triple: application/json, application/proto, application/grpc + wrapper

Scenario Example

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.

2

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.

3

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.

4

Protocol Specification

For more details about Triple protocol specification, please refer to Triple Specification [1].

Detailed Description of the Relationship with the gRPC Protocol

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:

  1. Protocol Design: Dubbo has designed its own custom Triple protocol, taking inspiration from gRPC and gRPC-Web. Triple is an RPC protocol built on top of the HTTP transport layer, which allows it to fully support gRPC and operate on both HTTP/1 and HTTP/2 simultaneously.
  2. Framework Design Philosophy: Dubbo follows a framework design philosophy that aligns with the objectives of the framework in each language implementation. Compared to framework libraries such as grpc-java and grpc-go, the implementation of the Dubbo protocol is simpler, more focused, and attempts to address issues encountered in the official gRPC library implementation.

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.

Simpler Implementation

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.

Large-scale Production Environment Inspection

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.

Native Multi-protocol Support

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

All-in-one Service Governance Access

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.

Multi-language Implementation

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.

Java Language Implementation

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

Go Language Implementation

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/

Rust

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

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/

Web

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/

Reference

[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

0 1 0
Share on

You may also like

Comments

Related Products