Skip to content

Apache Thrift Architecture

Apache Thrift is a software framework for scalable cross-language services development, originally developed at Facebook.^[600-developer__big-data__java-serializable.md]

Core Concepts

Thrift operates as a Remote Procedure Call (RPC) framework designed to facilitate cross-language communication.^[600-developer__big-data__java-serializable.md] It allows different programming languages to communicate seamlessly by abstracting the underlying transport and data serialization layers.^[600-developer__big-data__java-serializable.md]

Architecture Components

The architecture of Apache Thrift is defined by three primary layers that dictate how data is formatted, moved, and processed.^[600-developer__big-data__java-serializable.md]

1. Protocols (Serialization Formats)

The protocol layer determines how data is encoded for transport. Thrift supports multiple protocols to balance between speed, readability, and efficiency.^[600-developer__big-data__java-serializable.md]

Available protocols include:

  • TBinaryProtocol: Uses a binary encoding format.
  • TCompactProtocol: A more efficient binary format that typically results in smaller message sizes.
  • TJsonProtocol: Encodes data using JSON.
  • TSimpleJsonProtocol: A variant of JSON encoding.
  • TDebugProtocol: A human-readable format typically used for debugging.^[600-developer__big-data__java-serializable.md]

2. Transports (I/O Methods)

The transport layer handles the reading and writing of data from the network or other I/O sources.^[600-developer__big-data__java-serializable.md]

Available transport implementations include:

  • TSocket: Standard socket blocking I/O.
  • TFramedTransport: Sends data in chunks (frames), useful for non-blocking servers.
  • TFileTransport: Writing data to a file.
  • TMemoryTransport: Uses memory for I/O (e.g., using a byte array or buffer).^[600-developer__big-data__java-serializable.md]

3. Servers (Service Models)

The server layer defines how the service handles incoming connections and requests.^[600-developer__big-data__java-serializable.md]

Thrift provides several server models to suit different concurrency and performance needs:

  • TSimpleServer: A simple single-threaded server.
  • TThreadPoolServer: A multi-threaded server using a standard thread pool.
  • TNonblockingServer: A multi-threaded server using non-blocking I/O.
  • THsHaServer: "Half-Sync/Half-Async" server, combining a thread pool with non-blocking I/O.^[600-developer__big-data__java-serializable.md]

Sources

^[600-developer__big-data__java-serializable.md]