Apache Thrift Documentation

repository·master·Indexed 27 days ago

https://github.com/apache/thrift

A cross-language RPC framework for efficient data serialization and communication between services written in different programming languages. This documentation covers building the Thrift IDL compiler on Unix-like systems, macOS, and Windows (via CMake, Visual Studio, or manual steps), as well as integration guides for FB303, Rebus, STOMP, ZeroMQ, and various transport samples.

Tokens
57.3K
Snippets
111
Records
348
Agent score
95%

What's inside Apache Thrift

  1. Overview of Apache Thrift

    master

    Apache Thrift is a lightweight, language-independent software stack for point-to-point RPC (Remote Procedure Call) implementation. It provides abstractions for data transport, data serialization, and application-level processing.

    Key features include:

    • Code Generation: A definition language is used as input to generate interoperable RPC clients and servers across multiple programming languages.
    • Language Support: Supports 28 programming languages.
    • Versioning Compatibility: Designed to support non-atomic version changes, allowing servers to be upgraded while servicing older clients, or newer clients to interact with older servers.
  2. Overview of the Thrift OCaml Software Library

    master

    The Thrift OCaml library provides abstract classes, exceptions, and general use functions primarily located in Thrift.ml.

    Key implementation components include:

    • Protocols: TBinaryProtocol
    • Transports: TSocket, TServerSocket
    • Servers: TSimpleServer, TThreadedServer

    Note: The exception TServer is located in Thrift.ml.

  3. Understand Thrift Ruby Native Extension behavior

    master

    Loading the thrift_native extension replaces Thrift::Struct, Thrift::Union, and Thrift::CompactProtocol methods with C implementations for improved performance.

    • Fallback: If the native extension cannot be built or loaded, Thrift falls back to the pure-Ruby implementation.
    • JRuby: JRuby automatically skips the native extension and uses the pure-Ruby path.
    • Binary Protocol: Thrift::BinaryProtocol remains in pure Ruby unless you opt-in to the C-backed version using Thrift::BinaryProtocolAcceleratedFactory or Thrift::BinaryProtocolAccelerated (if available).
  4. Understand the Thrift Python package structure

    master

    Thrift is distributed as a set of Python packages. The top-level package is thrift. It is organized into the following subpackages:

    • thrift.protocol: Contains protocol implementations (e.g., TProtocol).
    • thrift.transport: Contains transport implementations (e.g., TTransport, TSocket).
    • thrift.server: Contains server implementations.
    • thrift.reflection: Contains generated code for reflection structures.
  5. Understand Thrift Compact Protocol Encoding

    master
    The Thrift Compact protocol is an efficient encoding format for RPC. It uses ZigZag encoding for signed integers, Varint (ULEB128) encoding for larger integers, and field ID deltas to minimize the wire footprint. This protocol is designed to be more compact than the standard Binary protocol by reducing the number of bytes required for common types and metadata.
  6. Use FB303 as a standard service interface

    master

    FB303 (Facebook Bassline) provides a standard interface for backend services to implement common cross-cutting concerns. Use this service to provide a unified way to handle:

    • Monitoring
    • Dynamic options and configuration
    • Uptime reports
    • Activity tracking

    Backend projects should inherit from this service to ensure they provide these standard capabilities. If you are adding new functionality, determine if it is a general utility that can be abstracted; if so, it may belong in the fb303 tree.

  7. Understand the Apache Thrift fuzzing strategy

    master

    Apache Thrift uses OSS-Fuzz to continuously test the robustness of both hand-written and generated code. The fuzzing efforts focus on two primary goals:

    1. Security: Testing how generated code handles malformed or malicious input.
    2. Serialization round-trip correctness: Ensuring data remains identical after a serialization and subsequent deserialization cycle.

    For each supported language, Thrift implements two types of fuzzers:

    • Deserializer Fuzzer: Attempts to deserialize raw fuzzer input into Thrift structures to test handling of unexpected input across protocols (Binary, Compact, JSON).
    • Round-Trip Fuzzer: Deserializes input, re-serializes it, and verifies the result matches the original to ensure data integrity.
  8. Understand the Apache Thrift Threat Model scope

    master

    Apache Thrift is an IDL-driven cross-language RPC and serialization framework. It is a library and code generator, not a deployed service.

    Key Scope Details:

    • In-Scope: The apache/thrift repository, including the C++ IDL compiler, language runtimes (lib/<lang>/), and the generated code produced by the compiler.
    • Out-of-Scope: The apache/thrift-website repository, test/tutorial/contrib directories, and third-party packaging mechanisms (e.g., vcpkg, crates.io, Maven Central). While the code inside a package is in-scope, the packaging process itself is not.
    • Security Reporting: As of the current draft, the project does not have a dedicated SECURITY.md. Vulnerabilities should be reported via the Apache Software Foundation (ASF) security PMC pipeline at security@apache.org.
  9. Understand the purpose of the /contrib folder

    master

    The /contrib folder in the Apache Thrift repository serves as a repository for sample code demonstrating Thrift capabilities and potentially helpful utilities.

    Warning: Code in this folder is not maintained on a regular basis and is not part of regular testing procedures. It may not work for your specific environment, purpose, or software version. Use it primarily as a reference for sample implementations.

  10. Understand Thrift Transport Layering

    master

    Thrift uses different transport types with different buffering behaviors:

    • TSocket: An endpoint transport; it is unbuffered.
    • TBufferedTransport: A layered transport wrapper that buffers reads and writes.
    • TFramedTransport: A layered transport wrapper that buffers an entire frame before deserializing.

    If a frame-size cap is set, it bounds the buffered consumption for these layered transports.

  11. Understand Apache Thrift versioning and interoperability

    master

    Apache Thrift follows SemVer 2.0 versioning rules.

    • Major version: Currently always 0.
    • Minor version: Increased for each release cycle.
    • Patch version: Increased for patch builds between release cycles to address critical defects, security, or packaging issues.

    Version Interoperability: Apache Thrift is designed for version interoperability. You can use a version 0.7.0 client with a 0.12.0 server. Note that a specific version number does not guarantee the availability of all features across all languages. Refer to the Language Feature Matrix for feature availability.

    External Package Patches: For language-specific critical defects or packaging errors, the project may bump the patch level for specific third-party distribution points (e.g., 0.12.0.1 for nuget or 0.12.0-1 for maven) without issuing a full project release or a new official tag.