Apache Thrift

Apache Thrift's RPC-First Design

Facebook described Thrift in April 2007 as a way to call services across languages: beside the structs sits a service, and the compiler generates client and server stubs with the types. Fields carry numbers, as in protobuf 59,573 , and encoding is pluggable, a binary, compact or JSON protocol over a socket, HTTP or file transport.

order.thrift: types and an RPC interface in one IDL
namespace py booknest
enum Channel { IOS = 1, ANDROID = 2, WEB = 3 }
struct Item { 1: i32 bookId, 2: i32 qty, 3: i64 unitPriceCents }
struct Order {
  1: i64 orderId, 2: i32 customerId, 3: i64 orderTsMs, 4: Channel channel,
  5: string status, 6: string currency, 7: list<Item> items, 8: optional string coupon,
  9: i64 discountCents, 10: i64 totalCents
}
service OrderService {                         // the RPC interface, generated with the types
  Order getOrder(1: i64 orderId)
  oneway void orderPlaced(1: Order order)
}
thrift.sh: generating Python code and serializing order 1Shell
thrift -out . --gen py order.thrift            # booknest/ttypes.py, booknest/OrderService.py
python thrift_demo.py                          # order 1 through two Thrift protocols
Output
TBinaryProtocolFactory    145 bytes: 0a 00 01 00 00 00 00 00 00 00 ...
TCompactProtocolFactory    54 bytes: 16 02 15 ac 27 16 e0 94 df f2 ...

The binary protocol spends a type byte, a two-byte field id and fixed-width integers per field (0a 00 01, then eight bytes for order id 1); the compact protocol packs id delta and type into one byte and uses zigzag varints. The compiler is Ubuntu 225 's thrift-compiler 0.22.0, the runtime thrift 0.25.0. Thrift mostly works underneath data platforms: Hive 129 's metastore API is Thrift, and Parquet 129 's footer is a Thrift compact struct (Apache Parquet In Depth).