Overview

Modern software is increasingly polyglot, distributed, and performance conscious, which makes fast, language-agnostic communication essential. Apache Thrift addresses this need by unifying data serialization and remote procedure calls behind a single, open, vendor-neutral framework. Developers describe types and services once in a concise Interface Definition Language, then generate client and server code for many languages. With built-in support for interface evolution, small-footprint servers, and pluggable protocols and transports, Thrift helps teams build efficient microservices that scale across embedded devices, containers, and enterprise backends while minimizing cross-language friction.

Thrift’s core mechanics are straightforward: define data and service contracts in IDL, compile them into language-specific stubs, pick a serialization protocol (binary, compact, or JSON) and a transport (such as TCP sockets, pipes, or in-memory buffers), and assemble a prebuilt server with a thin handler implementation. Layered transports enable capabilities like compression and encryption without changing the service contract. A simple “Hello” microservice illustrates the workflow: one IDL produces a Python server and matching clients in Python, C++, and Java with only a few lines of glue code, demonstrating consistent cross-language semantics (handler, processor, client) and rapid, boilerplate-free service construction.

Positioned among SOAP, REST, Protocol Buffers, and Avro, Thrift balances performance, reach, and flexibility. Compared with HTTP-centric SOAP/REST, Thrift’s binary protocols and TCP transports avoid web-stack overhead while retaining optional JSON and HTTP when needed; against Protocol Buffers, Thrift offers similar speed with broader in-tree language and server support plus modular transports/protocols; and unlike Avro’s schema-with-data model geared to storage, Thrift targets real-time RPC. Empirical results in the chapter show substantial latency and footprint gains—especially with TCP-based servers. The net takeaway: if you want one package that delivers fast serialization, lightweight cross-language RPC, pluggable protocols/transports, rich IDL with evolution, and wide platform coverage, Apache Thrift is a strong default choice for polyglot systems.

The Tiobe Index uses web search results to track programming language popularity (http://www.tiobe.com).
Figure1.2 Efficient translators are a core asset of any multi-language assembly.
Apache Thrift can be used to serialize data in cross-platform messaging scenarios.
The Apache Thrift RPC framework enables cross-platform services.
Time to complete 1 million service requests for various Java servers
Apache Thrift balances performance with reach and flexibility.
Apache Thrift is an effective solution in embedded, enterprise, and web technology environments.

      Summary

Here are the most important points to take away from this chapter:

  • Apache Thrift is a cross-language serialization and service implementation framework.
  • Apache Thrift supports a wide array of languages and platforms.
  • Apache Thrift makes it easy to build high performance services.
  • Apache Thrift is a good fit for service-oriented and microservice architectures.
  • Apache Thrift is an Interface Definition Language (IDL)-based framework.
  • IDLs allow you to describe interfaces and generate code to support the interfaces automatically.
  • IDLs allow you to describe types used in messaging, long-term storage, and service calls.
  • Apache Thrift includes a modular serialization system, providing several built-in serialization protocols and support for custom serialization solutions.
  • Apache Thrift includes a modular transport system, providing built-in memory and disk and network transports, yet makes it easy to add additional transports.
  • Apache Thrift supports interface evolution empowering CI/CD environments and Agile teams.

FAQ

What is Apache Thrift and why was it created?Apache Thrift is an open source framework for building high‑performance, cross‑language services. It combines an interface definition language (IDL), code generation, serialization protocols, transports, and lightweight servers so components written in many languages can communicate efficiently. It was created to give REST-like interoperability with significantly better speed and a smaller footprint.
How does Thrift help unify polyglot systems?Thrift lets you define data types and service interfaces once in an IDL, then generate idiomatic client/server stubs for 20+ languages. The generated code handles serialization, deserialization, and RPC details, ensuring a Python service can talk to Java, C++, Go, JavaScript, and more—consistently and reliably.
What is the role of Thrift’s IDL, and why prefer it to schemaless approaches?The IDL is the single source of truth for types and services. It: - Encourages interface‑first design, independent of implementation - Generates cross‑language, correct-by-construction serialization code - Makes schemas explicit, avoiding brittle, implicit “code-as-schema” - Works alongside schemaless stores (for documenting and sharing types)
How does Thrift support interface evolution without breaking clients?Thrift’s IDL includes versioning-friendly features (like stable field IDs and optional/required semantics), which allow you to add or remove fields and evolve types. Multiple interface versions can coexist, enabling incremental, CI/CD-friendly rollouts without forcing a “big bang” redeploy.
What are Thrift protocols, and when should I use Binary, Compact, or JSON?Protocols define how data is serialized on the wire. Common choices: - Binary: fast, general-purpose default - Compact: smaller payloads for bandwidth/latency sensitive paths - JSON: human-readable for debugging or interoperating with web tools You can switch protocols without changing the IDL, and you can add custom protocols if needed.
What are Thrift transports, and how can they be layered?Transports move serialized bytes. Built-ins include TSocket (TCP/IP), domain sockets, named pipes, and in‑memory/disk options. Transports can be layered to add behaviors like compression (e.g., TZlib), encryption, logging, or request forking—without changing application logic.
Why are Thrift’s prebuilt servers useful for microservices and embedded systems?Thrift ships lightweight server shells in most supported languages (for example, TSimpleServer and other variants). They avoid the overhead of full web/app servers, use an order of magnitude less memory than typical servlet containers, and are easy to assemble—ideal for containers and constrained environments.
How do I build a minimal cross-language “Hello” service with Thrift?Typical steps: - Write the IDL (define the service and functions) - Run the Thrift compiler to generate stubs for each target language - Implement the server handler (business logic) - Choose protocol (e.g., Binary) and transport (e.g., TSocket) - Start a Thrift server shell with your handler - Write clients in any supported language using matching protocol/transport
How does Thrift compare to REST, SOAP, Protocol Buffers, and Avro?High-level contrasts: - REST: broad reach and simplicity over HTTP/JSON, but more overhead and less direct fit for function‑style APIs - SOAP: XML/HTTP with rich specs, but heavier and slower; less common for new services - Protocol Buffers: similar serialization; gRPC adds RPC over HTTP/2. Thrift emphasizes in‑tree language/server support and pluggable protocols/transports - Avro: focuses on bundling schema with data; widely used for storage/streaming; less common for RPC
When should I choose Thrift?Choose Thrift when you want: - Integrated RPC + serialization with strong performance - A modular stack (swappable protocols/transports) - Broad language and platform support (embedded, enterprise, cloud, mobile) - An expressive IDL with evolution features - Lightweight server shells suitable for microservices and containers If public, browser-centric APIs are your priority, REST may fit better; for on-disk serialization, consider Avro; for HTTP/2-centric stacks, consider Protocol Buffers + gRPC.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Programmer’s Guide to Apache Thrift ebook for free
choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Programmer’s Guide to Apache Thrift ebook for free
choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Programmer’s Guide to Apache Thrift ebook for free