Arguing against using protobuffers
You have misunderstood the &quot;required considered harmful&quot; argument. It&#x27;s not fundamentally about the abstract concept of required vs. optional but about the specific implementation in Protocol Buffers, which turns out to have had unintended consequences.<p>Specifically: As implemented, required field checking occurred every time a message was serialized, not just when it was produced or consumed. Many systems involve middlemen who receive a message and then send it on to another system without looking at the content -- <i>except</i> that it <i>would</i> check that all required fields were sent, because that&#x27;s baked into the protobuf implementation.<p>What happened over and over again is that some obscure project would redefine a &quot;required&quot; field to &quot;optional&quot;, update both the <i>producer</i> and the <i>consumer</i> of the message, and then push it to production. But, once in production, the <i>middlemen</i> would start rejecting any message where these fields were missing. Often, the middleman servers were operating on &quot;omnibus&quot; messages containing bits of data originating from many different servers and projects -- for example, a set of search results might contain annotations from dozens of Search Quality algorithms. Normally, those annotations are considered non-essential, and Google&#x27;s systems are carefully architected so that the failure of one back-end doesn&#x27;t lead to overall failure of the system. However, when an optional backned sent a message missing required fields, the <i>entire</i> omnibus message would be rejected, leading to a total production outage. This problem <i>repeatedly</i> affected the search engine, gmail, and many other projects.<p>The fundamental lesson here is: A piece of data should be validated by the consumer, but should <i>not</i> be validated by pass-through middlemen. However, because required fields are baked into the protobuf implementation, it was unclear how they could follow this principle. Hence, the solution: Don&#x27;t use required fields. Validate your data in application code, at consumption time, where you can handle errors gracefully.<p>Could you design some other version of &quot;required&quot; that doesn&#x27;t have this particular problem? Probably. But would it actually be valuable? People who don&#x27;t have a lot of experience here -- including Jeff and Sanjay when they first designed protobufs -- <i>think</i> that the idea of declaring a field &quot;required&quot; is obvious. But the surprising result that could only come from <i>real-world experience</i> is that this kind of validation is an application concern which does not belong in the serialization layer.<p>&gt; There is no metadata anywhere.<p>Specifically, you mean there is no header &#x2F; container around a protobuf. This is one of the best properties of protobufs, because it makes them compose nicely with other systems that already have their own metadata, or where metadata is irrelevant. Adding required metadata wastes bytes and creates ugly redundancy. For example, if you&#x27;re sending a protobuf in an HTTP response, the obvious place to put metadata is in the headers -- encoding metadata in the protobuf body would be redundant and wasteful.<p>From what you wrote it sounds like you think that if Protobufs had metadata, it would have been somehow easier to migrate to a new encoding later, and Google would have done it. This is naive. If we wanted to add any kind of metadata, we could have done so at any time by using reserved field numbers. For example, the field number zero has always been reserved. So at any time, we could have said: Protobuf serialization version B is indicated by prefixing the message with 0x00 0x01 -- an otherwise invalid byte sequence to start a protobuf.<p>The reason no one ever did this is not because the format was impossible to change, but because the benefits of introducing a whole new encoding were never shown to be worth the inevitable cost involved: implementation in many languages and tools, code bloat of supporting two encodings at once (code bloat is a HUGE problem for protobuf!), etc.