Apache Thrift

In this article, we’ll have a look at another system Apache Thrift used to provide inter-service communication between microservices. In the previous articles, we have discussed the Google Remote Procedure Calls (gRPC) and REST.

Apache Thrift was originally developed by the Facebook development team and is currently maintained by Apache. It mainly focuses on the communication layer between the components of your system.

Apache Thrift defines data types and service interfaces by using a special Interface Description Language (IDL) and interfaces are stored as .thrift files. These interfaces are used later as input by the compiler for generating the source code of client and server software that communicate over different programming languages.

You can use the following maven dependency to use Apache Thrift in your project:

<dependency>
    <groupId> org.apache.thrift</groupId>
    <artifactId> libthrift </artifactId>
    <version> 0.12.0 </version>
</dependency>

Use of Apache Thrift

When designing a server, there are a lot of repetitive and tedious tasks that you usually have to do all by yourself. These include the following processes:

  • Designing a protocol
  • Serializing and deserializing messages on protocol with code
  • Dealing with sockets
  • Managing concurrency
  • Dealing with clients in different languages

Apache Thrift is here to get you rid of all these excessive tasks as it does all this automatically after you provide a description of all the functions you want to deliver from your server to the client. Simply providing the explanation of the required functions and their parameters will allow the Apache Thrift to generate a code in accordance in any choice of language.

Main works of the Apache Thrift framework includes:

  • Provide an Interface Definition Language that is free of any specific language and its restrictions.
  • With Interface Definition Language, a compiler will also be required to compile it and produce server and client codes.
  • Apache Thrift also provides a compiler generated client code and a compiler generated server code. In compiler generated client code the parameters passed over the functions are converted to binary format so that they can transport over the network. This process is commonly known as marshalling.
  • In compiler generated server code, the functions of client code are implemented. The parameters converted to binary in the client side code are received by the server side code which converts them back to their original language objects and passes through the function as they were meant to. This process is commonly known as unmarshalling.
  • The result of compiler generated server code is then converted to binary and sent through the wire over the network to compiler generated client code where it is converted back to the original language objects and then shown over the user interface.
Previous
Next