Why Thrift, Why not HTTP RPC(JSON+gzip)

Thrift's primary goal is to enable efficient and reliable communication across programming languages. but I think HTTP-RPC can also do that, web developer almost everyone knows how to work on http and it is easier to implement HTTP-RPC(json) than Thrift,

Maybe Thrift-RPC is faster, then who can tell me the difference in perfermance between them?


Solution 1:

A few reasons other than speed:

  1. Thrift generates the client and server code completely, including the data structures you are passing, so you don't have to deal with anything other than writing the handlers and invoking the client. and everything, including parameters and returns are automatically validated and parsed. so you are getting sanity checks on your data for free.

  2. Thrift is more compact than HTTP, and can easily be extended to support things like encryption, compression, non blocking IO, etc.

  3. Thrift can be set up to use HTTP and JSON pretty easily if you want it (say if your client is somewhere on the internet and needs to pass firewalls)

  4. Thrift supports persistent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.

Personally, I use thrift for internal LAN RPC and HTTP when I need connections from outside.

I hope all this makes sense to you. You can read a presentation I gave about thrift here:

http://www.slideshare.net/dvirsky/introduction-to-thrift

It has links to a few other alternatives to thrift.

Solution 2:

Here is good resource on performance comparison of different serializers: https://github.com/eishay/jvm-serializers/wiki/

Speaking specifically of Thrift vs JSON: Thrift performance is comparable to the best JSON libraries (jackson, protostuff), and serialized size is somewhat lower.

IMO, strongest thrift advantages are convenient interoperable RPC invocations and convenient handling of binary data.