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
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

3 years ago