Protobuf vs JSON: The Real Size and Speed Numbers (Measured, Not Handed Down)
You have probably seen the number thrown around, that protobuf is two or three times smaller than JSON, and half the time you have no idea which half of it is true. So I measured it, with one message, the same fields both ways, and the honest answer is that it depends on your fields, and the reason it depends is the whole point. A protobuf message does not store field names. The wire only carries a field number and a wire type, packed into a single tag varint, so a two or three letter name costs one byte where JSON costs the letters plus two quotes plus a comma. That is the first saving, and it scales with how long your field names are and how many fields you have.
The second saving is how numbers and lists are written. JSON has to write numbers as text, so a value like 42 costs two characters, and an ID that is 13 digits costs 13. The wire writes the same 42 as one byte, and 13 digits as a varint that grows with the value. Repeated fields are where the gap gets real, because JSON writes every bracket, quote and comma for every element, while a packed repeated scalar in proto3 is one tag, one length, then the values in a run. I checked it: ten small integers are 12 bytes packed on the wire, 33 characters in JSON, and if a proto2-style unpacked encoder wrote one tag per value it would be 20, which is why a naive port of a repeated field can get bigger before you fix the packing.
The third one is the 64-bit number, and it is the one that bites you. The official protobuf JSON mapping writes int64 and uint64 as strings, because a 13-digit ID read as a JavaScript number collapses above 2^53 (9007199254740992), so an ID you thought you stored is a different ID with no error and no warning. I hit this in my own tool this week: a pure JavaScript runtime without a 64-bit integer library will parse the string 9007199254740993 into a number that already lost the last digit before the bytes were ever written. The mapping keeps the digits safe by refusing to let them become a number, which is exactly why a decoder that only accepts the numeric form will reject valid data from your own service, and why a hand-rolled converter that only accepts the string form will reject data from a C++ one.
Here is the actual measurement so you have real numbers. A message with a name, an age, an email address, an int64 ID, an enum, a repeated int, a repeated string and a nested address comes out at 118 bytes in protobuf and 248 characters in JSON, which is a ratio of 2.1, not 3 and not 10. The per-field math is why the number is what it is. The email field is the tell: the wire writes one tag byte, one length byte and the 18 letters, 20 bytes, while JSON writes the key in quotes, the colon, and the value in quotes, 28 characters. The nested address block is 39 bytes on the wire against 86 characters in JSON, and the gap there is mostly the four inner keys and their quotes being written in full. The name is the anti-example, and I want to keep it in: five letters is 7 bytes on the wire and 14 characters in JSON, a ratio of 2, the same as everything else, because for short text with a short name there is not much to save. The real spread is in the numbers and the lists. Ten small integers are 12 bytes packed, 33 characters as a JSON array, and that ratio is 2.7, higher than the average, and it climbs with the value size and the list length. That is the honest shape of the trade, and it means a message that is mostly long strings with short names will be barely bigger, while a message that is mostly repeated numeric fields is where the 5x case the blogs talk about actually lives.
Speed is the part people get wrong. The claim is that protobuf is faster, and in the languages where it matters, the C++, Go and Java runtimes, it is, because the encode is a tight native loop over a schema the compiler has already looked at. In JavaScript specifically, I benchmarked 500,000 messages, pre-built, and JSON.stringify came out ahead, 162 milliseconds to 275 for the pure JS protobuf encoder. That is not a gotcha, it is a shape: in a browser, the format you parse fastest is often the one you do not have to parse at all. The reason you still reach for protobuf in a JS service is the wire, not the CPU. Fewer bytes means less time on the network, less memory holding the payload, and a smaller body to gzip, and the network is almost always the thing that was actually slow.
So when you are choosing, the rule is the same rule as the rest of the format: the name is not on the wire, the number is. Pick protobuf when the message travels a lot, when it is repeated or streamed, when the fields are numeric or repeated, and when you have two or more versions of the service talking to each other across a schema you will evolve. Pick JSON when the message is mostly long strings, when a human is going to read it in the logs, and when the only thing that has to parse it is another JavaScript runtime. The converter at proto.datajutsu.com does this comparison for your own message: you paste the .proto and the JSON, it encodes both ways, and the output shows the byte count of each, so the 2.1 and the 5 are your numbers instead of mine. The companion piece is the proto3 versus proto2 post, because the packing choice that decides whether your repeated field is 12 bytes or 20 is set by the syntax line, and flipping that line quietly changes the size of every message that carries a repeated field. Read the two together and the whole size question fits on one page.