AboutBlogContact
Distributed SystemsDecember 1, 2007 2 min read 24

Thrift vs. Protocol Buffers: Choosing Your Binary Protocol (2007)

AunimedaAunimeda
📋 Table of Contents

Thrift vs. Protocol Buffers: Choosing Your Binary Protocol

It's late 2007. Your REST/JSON (or worse, XML) APIs are becoming the bottleneck in your distributed system. The overhead of parsing strings and the sheer size of the payloads are killing your latency. You need a binary serialization format. Today, the choice comes down to two titans: Facebook's Thrift and Google's Protocol Buffers (Protobuf).

Apache Thrift: The Full Stack

Thrift isn't just a serialization format; it's a complete RPC framework. Facebook developed it to allow for seamless communication between C++, Java, Python, PHP, and more.

Thrift IDL:

namespace cpp Example
namespace php Example

struct User {
  1: i32 id,
  2: string username,
  3: string email,
}

service UserService {
  User getUser(1: i32 id),
  void saveUser(1: User user),
}

Thrift generates both the data structures and the client/server stubs. It supports multiple "Protocols" (Binary, Compact, JSON) and "Transports" (Socket, Framed, HTTP).

Protocol Buffers: The Lightweight Serialization

Google's Protocol Buffers focuses primarily on the serialization layer. It’s incredibly fast and produces very small messages.

Protobuf IDL:

package example;

message User {
  required int32 id = 1;
  required string username = 2;
  optional string email = 3;
}

Unlike Thrift, Protobuf doesn't include a built-in RPC stack (though many people build their own on top of it). It’s designed to be a "data interchange" format first and foremost.

The Key Differences

  1. Required vs. Optional: Protobuf makes you explicitly label fields as required, optional, or repeated. This is great for versioning—if you want to remove a field, you just make it optional. Thrift handles this through field IDs, but it's less explicit in the IDL.
  2. Language Support: Thrift currently has a slight edge in the number of supported languages out of the box (especially PHP and Ruby).
  3. RPC: If you want a "batteries-included" solution for service communication, Thrift is the winner. If you just need to store data on disk or send it over an existing channel, Protobuf is often simpler.

Whichever you choose, moving away from text-based formats for internal service communication is the single best thing you can do for your infrastructure's performance in 2007.

Read Also

Distributed Locking: etcd vs. Consul (2016)aunimeda
Distributed Systems

Distributed Locking: etcd vs. Consul (2016)

Don't let two cron jobs run at once. In 2016, we're comparing the Raft implementations of etcd and Consul for reliable distributed locking.

Riak: Dynamo in Practice with Riak Core (2010)aunimeda
Distributed Systems

Riak: Dynamo in Practice with Riak Core (2010)

Basho took Amazon's Dynamo paper and made it real. Let's look at the vnode architecture and consistent hashing.

Fault-Tolerant Systems with Erlang/OTP Supervision Trees (2007)aunimeda
Distributed Systems

Fault-Tolerant Systems with Erlang/OTP Supervision Trees (2007)

Designing 'Nine Nines' availability. How Erlang 5.5 (R11B) uses the Let It Crash philosophy and OTP supervision hierarchies to build distributed systems that never die.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles