<p>What are the biggest pros and cons of <a href="http://incubator.apache.org/thrift/" rel="noreferrer">Apache Thrift</a> vs <a href="http://code.google.com/apis/protocolbuffers/" rel="noreferrer">Google's Protocol Buffers</a>?</p>

[{'answer_id': 69367, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 3, 'selected': False, 'text': "<p>Protocol Buffers seems to have a more compact representation, but that's only an impression I get from reading the Thrift whitepaper.  In their own words:</p>\n\n<blockquote>\n  <p>We decided against some extreme storage optimizations (i.e. packing\n  small integers into ASCII or using a 7-bit continuation format)\n  for the sake of simplicity and clarity in the code. These alterations\n  can easily be made if and when we encounter a performance-critical\n  use case that demands them.</p>\n</blockquote>\n\n<p>Also, it may just be my impression, but Protocol Buffers seems to have some thicker abstractions around struct versioning.  Thrift does have some versioning support, but it takes a bit of effort to make it happen.</p>\n"}, {'answer_id': 69374, 'author': 'hazzen', 'author_id': 5066, 'author_profile': 'https://Stackoverflow.com/users/5066', 'pm_score': 7, 'selected': False, 'text': '<p>They both offer many of the same features; however, there are some differences:</p>\n\n<ul>\n<li>Thrift supports \'exceptions\'</li>\n<li>Protocol Buffers have much better documentation/examples</li>\n<li>Thrift has a builtin <code>Set</code> type</li>\n<li>Protocol Buffers allow "extensions" - you can extend an external proto to add extra fields, while still allowing external code to operate on the values. There is no way to do this in Thrift</li>\n<li>I find Protocol Buffers much easier to read</li>\n</ul>\n\n<p>Basically, they are fairly equivalent (with Protocol Buffers slightly more efficient from what I have read).</p>\n'}, {'answer_id': 296349, 'author': 'eishay', 'author_id': 16201, 'author_profile': 'https://Stackoverflow.com/users/16201', 'pm_score': 6, 'selected': False, 'text': '<ul>\n<li>Protobuf serialized objects are about 30% smaller than Thrift.</li>\n<li>Most actions you may want to do with protobuf objects (create, serialize, deserialize) are <a href="http://eishay.blogspot.com/2008/11/serialization-protobuf-vs-thrift-vs.html" rel="noreferrer">much slower than thrift</a> unless you turn on <a href="http://www.eishay.com/2008/11/protobuf-with-option-optimize-for-speed.html" rel="noreferrer"><code>option optimize_for = SPEED</code></a>. </li>\n<li>Thrift has richer data structures (Map, Set)</li>\n<li>Protobuf API looks cleaner, though the generated classes are all packed as inner classes which is not so nice.</li>\n<li>Thrift enums are not real Java Enums, i.e. they are just ints. Protobuf has real Java enums.</li>\n</ul>\n\n<p>For a closer look at the differences, check out the source code diffs at <a href="https://github.com/eishay/jvm-serializers/wiki" rel="noreferrer">this open source project</a>.</p>\n'}, {'answer_id': 632975, 'author': 'StaxMan', 'author_id': 59501, 'author_profile': 'https://Stackoverflow.com/users/59501', 'pm_score': 3, 'selected': False, 'text': '<p>One obvious thing not yet mentioned is that can be both a pro or con (and is same for both) is that they are binary protocols. This allows for more compact representation and possibly more performance (pros), but with reduced readability (or rather, debuggability), a con.</p>\n\n<p>Also, both have bit less tool support than standard formats like xml (and maybe even json).</p>\n\n<p>(EDIT) Here\'s an <a href="http://code.google.com/p/thrift-protobuf-compare/" rel="noreferrer">Interesting comparison</a> that tackles both size &amp; performance differences, and includes numbers for some other formats (xml, json) as well.</p>\n'}, {'answer_id': 1223197, 'author': 'Mike Gray', 'author_id': 451199, 'author_profile': 'https://Stackoverflow.com/users/451199', 'pm_score': 6, 'selected': False, 'text': '<p>Another important difference are the languages supported by default.</p>\n\n<ul>\n<li>Protocol Buffers: Java, Android Java, C++, Python, Ruby, C#, Go, Objective-C, Node.js</li>\n<li>Thrift: Java, C++, Python, Ruby, C#, Go, Objective-C, JavaScript, Node.js, Erlang, PHP, Perl, Haskell, Smalltalk, OCaml, Delphi, D, Haxe</li>\n</ul>\n\n<p>Both could be extended to other platforms, but these are the languages bindings available out-of-the-box.</p>\n'}, {'answer_id': 1482464, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>And according to the <a href="http://wiki.apache.org/thrift/ThriftInstallationWin32" rel="noreferrer">wiki</a> the Thrift runtime doesn\'t run on Windows.</p>\n'}, {'answer_id': 2532224, 'author': 'saidimu apale', 'author_id': 234966, 'author_profile': 'https://Stackoverflow.com/users/234966', 'pm_score': 6, 'selected': False, 'text': '<p>RPC is another key difference. Thrift generates code to implement RPC clients and servers wheres Protocol Buffers seems mostly designed as a data-interchange format alone.</p>\n'}, {'answer_id': 2760529, 'author': 'dhruvbird', 'author_id': 155951, 'author_profile': 'https://Stackoverflow.com/users/155951', 'pm_score': 3, 'selected': False, 'text': '<p>I was able to get better performance with a text based protocol as compared to protobuff on python. However, no type checking or other fancy utf8 conversion, etc... which protobuff offers.</p>\n\n<p>So, if serialization/deserialization is all you need, then you can probably use something else.</p>\n\n<p><a href="http://dhruvbird.blogspot.com/2010/05/protocol-buffers-vs-http.html" rel="noreferrer">http://dhruvbird.blogspot.com/2010/05/protocol-buffers-vs-http.html</a></p>\n'}, {'answer_id': 7216455, 'author': 'Grzegorz Wierzowiecki', 'author_id': 544721, 'author_profile': 'https://Stackoverflow.com/users/544721', 'pm_score': 6, 'selected': False, 'text': '<p>As I\'ve said as <a href="https://stackoverflow.com/questions/4293385/thrift-vs-protocol-buffers/7216492#7216492">"Thrift vs Protocol buffers"</a> topic :</p>\n\n<p>Referring to <a href="http://blog.mirthlab.com/2009/06/01/thrift-vs-protocol-bufffers-vs-json/" rel="nofollow noreferrer">Thrift vs Protobuf vs JSON comparison</a> :</p>\n\n<ul>\n<li>Thrift supports out of the box <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=tree;f=lib;hb=HEAD" rel="nofollow noreferrer">AS3, C++, C#, D, Delphi, Go, Graphviz, Haxe, Haskell, Java, Javascript, Node.js, OCaml, Smalltalk, Typescript, Perl, PHP, Python, Ruby, ...</a></li>\n<li>C++, Python, Java - in-box support in Protobuf </li>\n<li><a href="http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns" rel="nofollow noreferrer">Protobuf support for other languages (including Lua, Matlab, Ruby, Perl, R, Php, OCaml, Mercury, Erlang, Go, D, Lisp) is available as Third Party Addons</a> (btw. <a href="http://www.swi-prolog.org/pldoc/package/protobufs.html" rel="nofollow noreferrer">Here is SWI-Prolog support</a>).</li>\n<li>Protobuf has much better documentation and plenty of examples.</li>\n<li>Thrift comes with a good <a href="http://thrift.apache.org/tutorial/" rel="nofollow noreferrer">tutorial</a></li>\n<li>Protobuf objects are smaller</li>\n<li>Protobuf is faster when using "optimize_for = SPEED" configuration</li>\n<li>Thrift has integrated RPC implementation, while for <a href="http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns" rel="nofollow noreferrer">Protobuf RPC solutions are separated, but available</a> (like <a href="http://zeroc.com/ice.html" rel="nofollow noreferrer">Zeroc ICE</a> ).</li>\n<li>Protobuf is released under BSD-style license</li>\n<li>Thrift is released under Apache 2 license</li>\n</ul>\n\n<p>Additionally, there are plenty of interesting additional tools available for those solutions, which might decide. Here are examples for Protobuf: <a href="http://code.google.com/p/protobuf-wireshark/" rel="nofollow noreferrer">Protobuf-wireshark</a> , <a href="http://code.google.com/p/protobufeditor/" rel="nofollow noreferrer">protobufeditor</a>.</p>\n'}, {'answer_id': 25563451, 'author': 'Stefan Steiger', 'author_id': 155077, 'author_profile': 'https://Stackoverflow.com/users/155077', 'pm_score': 3, 'selected': False, 'text': '<p>ProtocolBuffers is FASTER.<br />\nThere is a nice benchmark here:<br />\n<a href="https://github.com/eishay/jvm-serializers/wiki" rel="nofollow noreferrer">https://github.com/eishay/jvm-serializers/wiki</a> (last updated 2016, but there are forks that contain faster serializers as of 2020, e.g. ActiveJ created a fork to demonstrate their speed on the JVM: <a href="https://github.com/activej/jvm-serializers" rel="nofollow noreferrer">https://github.com/activej/jvm-serializers</a>).</p>\n<p>You might also want to look into Avro, which can be faster. There are two libraries for Avro in .NET:</p>\n<ol>\n<li><a href="https://www.nuget.org/packages/Apache.Avro" rel="nofollow noreferrer">Apache.Avro</a></li>\n<li><a href="https://www.nuget.org/packages/Chr.Avro" rel="nofollow noreferrer">Chr.Avro</a> - written by engineers at C.H. Robinson, a supply chain logistics company</li>\n</ol>\n<p>By the way, the fastest I\'ve ever seen is <a href="https://capnproto.org/" rel="nofollow noreferrer">Cap\'nProto</a>;<br />\nA C# implementation can be found at the <a href="https://github.com/mgravell/capnproto-net" rel="nofollow noreferrer">Github-repository of Marc Gravell</a>.</p>\n'}, {'answer_id': 43413875, 'author': 'Babra Cunningham', 'author_id': 5477287, 'author_profile': 'https://Stackoverflow.com/users/5477287', 'pm_score': 3, 'selected': False, 'text': "<p>I think most of these points have missed the basic fact that Thrift is an RPC framework, which happens to have the ability to serialize data using a variety of methods (binary, XML, etc).</p>\n\n<p>Protocol Buffers are designed purely for serialization, it's not a framework like Thrift. </p>\n"}, {'answer_id': 46021476, 'author': 'Sinapse', 'author_id': 1584435, 'author_profile': 'https://Stackoverflow.com/users/1584435', 'pm_score': 1, 'selected': False, 'text': '<p>There are some excellent points here and I\'m going to add another one in case someones\' path crosses here.</p>\n\n<p>Thrift gives you an option to choose between thrift-binary and thrift-compact (de)serializer, thrift-binary will have an excellent performance but bigger packet size, while thrift-compact will give you good compression but needs more processing power. This is handy because you can always switch between these two modes as easily as changing a line of code (heck, even make it configurable). So if you are not sure how much your application should be optimized for packet size or in processing power, thrift can be an interesting choice.</p>\n\n<p>PS: See this excellent benchmark project by <code>thekvs</code> which compares many serializers including thrift-binary, thrift-compact, and protobuf: <a href="https://github.com/thekvs/cpp-serializers" rel="nofollow noreferrer">https://github.com/thekvs/cpp-serializers</a></p>\n\n<p>PS: There is another serializer named <code>YAS</code> which gives this option too but it is schema-less see the link above.</p>\n'}, {'answer_id': 48482910, 'author': 'trilogy', 'author_id': 9278333, 'author_profile': 'https://Stackoverflow.com/users/9278333', 'pm_score': 2, 'selected': False, 'text': '<p>For one, protobuf isn\'t a full RPC implementation.  It requires something like gRPC to go with it.  </p>\n\n<p>gPRC is very slow compared to Thrift:</p>\n\n<p><a href="http://szelei.me/rpc-benchmark-part1/" rel="nofollow noreferrer">http://szelei.me/rpc-benchmark-part1/</a></p>\n'}, {'answer_id': 53685080, 'author': 'JSON', 'author_id': 1246037, 'author_profile': 'https://Stackoverflow.com/users/1246037', 'pm_score': 0, 'selected': False, 'text': "<p>It's also important to note that not all supported languages compair consistently with thrift or protobuf. At this point it's a matter of the modules implementation in addition to the underlying serialization. Take care to check benchmarks for whatever language you plan to use.</p>\n"}, {'answer_id': 62926477, 'author': 'dyy.alex', 'author_id': 10272632, 'author_profile': 'https://Stackoverflow.com/users/10272632', 'pm_score': 2, 'selected': False, 'text': '<p>I think the basic data structure is different</p>\n<ol>\n<li>Protocol Buffer use variable-length integee which refers to variable-length digital encoding, turning a fixed-length number into a variable-length number to save space.</li>\n<li>Thrift proposed different types of serialization formats (called &quot;protocols&quot;).\nIn fact, Thrift has two different JSON encodings, and no less than three different binary encoding methods.</li>\n</ol>\n<p>In conclusion，these two libraries are completely different. Thrift likes a one-stop shop, giving you the entire integrated RPC framework and many options (supporting cross-language), while Protocol Buffers is more inclined to &quot;just do one thing and do it well&quot;.</p>\n'}]
['https://Stackoverflow.com/questions/69316', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']