Software Engineering: Facebook Thrift

I read Facebook's Thrift Whitepaper. Thrift is, basically, Facebook's open source replacement for CORBA. In short, it looks fine.

The whitepaper mentions CORBA only very briefly: "Relatively comprehensive, debatably overdesigned and heavyweight. Comparably cumbersome software installation."

Thrift feels very C++-ish. For instance, they use Boost. The Thrift IDL compiler is written in C++ with Lex and Yacc. They also implemented their own C++ thread primatives, including Mutex, Condition, and Monitor. The whitepaper also discusses their threading and memory management issues in C++.

They have an interesting scheme for versioning APIs such as struct fields and function parameters. They put numbers on the fields so that if a client and server aren't currently running the same version of the IDL, things can continue working. This is important for rolling upgrades. Here's an example:
struct Example { 
1:i32 number=10,
2:i64 bigNumber,
3:double decimals,
4:string name="thrifty"
}
That was, perhaps, the most surprising thing to me. I was having BASIC flashbacks. I assume that if you need to delete a field, you just delete the whole line and leave a gap in the numbers.

However, an interesting case arises. What happens if you delete field 4 in the above example, and someone else unknowingly adds a new field, reusing the same id? It's probably important to leave a comment in the code saying which is the highest id that has been used so far.

I don't think I would have used numbers. Instead, I would have used a "deleted" keyword. Of course, numbers could still be used in the implementation, behind the scenes:
struct Example { 
i32 number=10,
deleted i64 bigNumber,
double decimals,
deleted string name="thrifty"
}
Perhaps they thought of this too, but there's some reason they dismissed it. For instance, it is sort of ugly to have those "deleted" lines, and you can only add new fields at the end. Heh, I guess this is one time where numbers actually enhance readability ;)

Anyway, I didn't actually try it out, but I'm sure it's fine.

Comments

Leon Atkinson said…
It's cool that Facebook is throwing off a bunch of open source. Did you see Facebook's Cassandra? It's something like BigTable.
Take at peek at Google's Protocol Buffers to see what Facebook based their design off of.

From what I've read Facebook was hiring Google engineers with Protocol Buffers experience when they were building Thrift.
> It's cool that Facebook is throwing off a bunch of open source. Did you see Facebook's Cassandra? It's something like BigTable.

Awesome!

> Take at peek at Google's Protocol Buffers to see what Facebook based their design off of.

Oh, interesting!
jeff said…
jeez, not sure where this meme started, but thrift was based on pillar, a cross-language rpc framework from our former cto, written in ml. for all we know, google based protocol buffers on pillar.
> jeez, not sure where this meme started

CORBA? What was popular before CORBA?

By the way, +1 for mentioning ML ;)