Comparison of cross-language communication frameworks: Apache thrift and Google protobuf

Source: Internet
Author: User

I want to share my opinion on Weibo two days ago: In the current technical system, there are many ways to describe communication protocols, such as XML, JSON, protobuf, and thrift, if, on the basis of so many options, when designing a system, you still create an agreement and design the protocol type and resolution method by yourself, then I can only say that you are really lagging behind, not technically, but ideologically. We do not describe XML or JSON too much. You can refer to the relevant documents. JSON, in particular, is widely used in front-and back-end communication of Web Systems and browser game systems.This article focuses on two communication frameworks that are widely used in large systems, thrift and protobuf.Why is it a communication framework instead of a communication protocol? If these two technologies are used only for protocol parsing, they will be greatly discounted for their powerful features.

ForThrift is the first tool.Because it not only processes protocol encapsulation and resolution, but also implements a complete communication framework, fully encapsulating the underlying communication.For the user, the processing logic is sufficient in the callback of the framework's client and server interfaces.. For its exact description, let's refer to the official statement. This is more accurate, so as not to affect your understanding due to my own ideas.

Thrift is a cross-language service deployment framework. It was initially developed by Facebook in 2007 and entered the Apache open-source project in 2008. Thrift defines the RPC interface and data type through an intermediate language (IDL, Interface Definition Language), and then generates code in different languages through a compiler (currently C ++, Java, python, PHP, Ruby, Erlang, Perl, Haskell, C #, cocoa, smalltalk, and ocaml), and the generated code is responsible for implementing the RPC protocol layer and transport layer.

Thrift actually implements the C/S mode. It uses the code generation tool to generate the interface definition file to generate the server and client code (which can be in different languages ), this provides cross-language support for servers and clients. Users declare their own services in the thirft description file. After these services are compiled, code files in the corresponding language are generated, and then the user implements the service (the client calls the service and the server initiates the service) you can. Protocol (protocol layer, which defines the data transmission format, which can be binary or XML) and transport (transport layer, which defines the data transmission mode, which can be TCP/IP transmission, is used as the Runtime Library.

Thrift supports binary, compression, and JSON format data serialization and deserialization.. This allows users to select more flexible protocol formats. More perfect,The Protocol is freely scalable. The new version of the protocol is fully compatible with the old version.!

So does thrift have any disadvantages? Yes, and it is very serious! But does not affect the use, becauseThe disadvantage of this framework lies not in the program itself, but in the lack of its documentation!Including Chinese and English documents. To thoroughly understand and master thrift, there is only one way to read thrift code and read it all! I am very happy to do this because reading code and high-quality code is a very interesting thing, which is nothing for a programmer. Of course, in line with the needs of popularization, the perfection of the document really needs to be greatly strengthened. Of course, I also believe that thrift's documentation will be improved gradually, because there are more and more enthusiastic program developers and open-source software enthusiasts in China. At the same time, I started to supplement thrift's documentation, many people are willing to do things that are also very fulfilling.

Compared with thrift,Protobuf documentation is well-known. In this regard, I think Google's open-source stuff is indeed better than Facebook in terms of user guides and documentation.

Protobuf is an open-source serialization framework provided by Google. It is similar to a data representation language such as XML and JSON,Its biggest feature is binary-based, so it is much more efficient and short than traditional XML Representation.. Although it is a binary data format, it is not complicated, so it can be easily extended based on the binary protocol, and it is easy to make the new version of the protocol compatible with the old version.If XML is too bloated and JSON is easy to parse, it is more efficient and scalable than XML, protobuf can be said to be more efficient and scalable than JSON, and the protocol is more confidential. Protobuf is cross-language and supports major languages such as C (C ++), Java, and python, making it easy to design large systems. Protobuf also claims to have a service. It can complete the logic of the client and server based on its service interfaces and callbacks. However, the current version of service only stays at the interface layer, and its underlying communication needs to be implemented by itself. This is indeed far from complete than thrift.

Protobuf is a core base library in Google and undertakes the communication protocol design between Google's massive servers.. In a multi-functional, cross-language massive system, such an efficient, concise, and freely scalable communication framework can be described as a classic.

If we talk about integration, there is such a good tool. When we design a large system, we should try our best to avoid wheel building. Let's give a suggestion that before you design a large system, let's take a look at Google Code and many open-source projects on the Internet. In many cases, the design is fast and good, and many of our peers have already done a good job.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.