How to Deprecate and Retire a Protobuf Field (reserved vs [deprecated])

You have a field nobody wants anymore, and the tempting move is to delete the line. Do not. The line is not the field. The field is a number on the wire, and that number is still being written by every old client that has not updated, so the instant you delete the line and someone later gives that number to a new field, you have built the worst failure protobuf has to offer: bytes that decode cleanly and come out wrong, on both ends, with no error anywhere. Proto3 has two mechanisms for retiring a field, reserved and [deprecated = true], and they do completely different jobs. People mix them up, and the mix-up is usually where the accident lives.

[deprecated = true] is the soft one, and it changes nothing on the wire. The field stays in the schema, stays encoded, stays decoded, and both old and new code keeps sending and reading it. The marker is a promise to the people using the schema: this field is on its way out, stop building new things on it. Some language code generators surface it in the output, in Java it becomes a @Deprecated on the getter, so the signal reaches the IDE and the person writing the next feature. Deprecate first, every time. You are telling the whole fleet to migrate off a field before you remove the field, which is the only order in which removing it is safe.

When migration is done, you delete the line, and now you fence the number: reserved 7;. A reserved number can never be assigned to a new field, and protoc will refuse the build the moment someone tries. That refusal is the whole value. Reusing a number is the one change in protobuf that silently corrupts instead of loudly failing, because old clients still encode with the old meaning and new ones decode with the new one. The reserved statement is also free to add whenever, it lives in the schema, not on the wire, so old clients never see it and nothing breaks by adding it late. The only deadline is before somebody reuses the number, which is why you add it in the same commit you delete the field, not in the cleanup sprint three months from now.

There is a second, weaker form, reserved by name: reserved "old_email";. It stops someone from reusing the name, which is not a wire break but is a real bug factory, two fields with the same name in a message that is not a rename, and the confusion it causes is exactly the kind you do not want to debug in production. The habit is to do both in the same line of thinking: delete the field, reserve the number, reserve the name. Ranges work the same way, reserved 20 to 40; when you deleted a whole section, and reserved 20 to max; if you genuinely never expect the message to grow again. The last one is a one-way door on the message, so use it sparingly and only where you really mean it.

The question nobody can answer from the schema is whether the field is actually dead, because the schema is your intent and the traffic is the reality. A field can be deleted from every service you maintain and still be on the wire from a mobile app that shipped in 2024 and gets updated when it feels like it. The honest way to check is to look at real messages and see whether the number is still in there. That is what the raw decode tab at proto.datajutsu.com is for: no schema, no compiler, just the bytes, and every field number in plain view. If field 7 shows up in traffic, old clients are still sending it, and the field is not dead yet, so keep it encoded, or at minimum keep it reserved, and let the migration finish. When the number stops appearing, you can keep the reserved line, which costs nothing, and forget the field. It pairs with the unknown-field work, because a reserved field arriving in new code shows up as exactly that, an unknown field, which is expected behavior, not an error to chase.

The order that keeps you safe, in full: deprecate first and let the fleet migrate off the field; delete the line only after traffic has gone quiet; reserve the number and the name in the same commit; and never, under any schedule, reuse a number. It is the same rule as the breaking-changes review, applied to the one change you make on purpose. Do it in that order every time and field retirement stops being a risk event and becomes a two-line diff.

Subscribe to Data Jutsu

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe