Apache Thrift - Introduction

What is Thrift

According to Apache Thrift,

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

It’s originated from Facebook, and there’s a paper about it. According to the Abstract of the paper,


"Thrift is a software library and set of code-generation tools developed at Facebook to expedite development and implementation of efficient and scalable backend services.

Its primary goal is to ###enable efficient and reliable communication across programming languages### by abstracting the portions of each language that tend to require the most customization into a common library that is implemented in each language.

Specifically, Thrift allows developers to define `datatypes` and `service interfaces` in a single language-neutral file and generate all the necessary code to build RPC clients and servers."


As far as I understand, Thrift is a high-performant RPC framework with the following characteristics:

  1. A high-performant encode and decode framework based on bytes
  2. Bottom communication based on NIO
  3. Relative easy service call model
  4. Use Interface Description Language (IDL) to support cross-platform calls
  5. A high performant binary encoding/decoding framework

Thrift Network Stack

According to the model, Thrift is composed of the following core components:

  • TServer and Client
  • TProcessor - a generic object which operates upon an input stream and writes to some output stream.
  • TProtocol - protocol interface that encode/decode data
  • TTransport - encapsulates the I/O layer. Basically a thin wrapper around the combined functionality of Java input/output streams.
  • The Thrift Interface Definition Language (IDL) - describes the service, and generates cross-platform clients

Here’s a simple representation of the Apache Thrift networking stack from https://thrift.apache.org/docs/concepts

| Transport |
| (raw TCP, HTTP etc) |
| Protocol |
| (JSON, compact etc) |
| Processor |
| (compiler generated) |
| Server |
| (single-threaded, event-driven etc) |

Reference: RPC framework basic components

RPC framework basic components