Thrift

Summary: A binary encoding format that uses a schema and field tags to achieve compact data representation and evolvability.

Sources: chapter4

Last updated: 2026-04-15


Apache Thrift, originally developed at Facebook, is a binary encoding library. It requires a schema defined in an Interface Definition Language (IDL).

Binary Encoding Formats

Thrift has two main binary encoding formats:

  1. BinaryProtocol: A simple but less compact format.
  2. CompactProtocol: Packs the same information into fewer bytes by using variable-length integers and other optimizations.

Schema Evolution

Thrift achieves compatibility by using field tags (numbers like 1, 2, 3) instead of field names in the encoded data.

  • Forward Compatibility: Older code can skip unknown field tags based on type annotations.
  • Backward Compatibility: New code can read old data as long as every field has a unique tag number.

Rules for Evolution

  • You can add new fields as long as they are optional or have a default value.
  • You can only remove optional fields.
  • You must NEVER change a field’s tag number.