How do you version gRPC APIs?
Answer
gRPC versioning follows Protobuf's backward compatibility rules and can be approached in multiple ways: (1) Field-based versioning — add new fields with new numbers; old clients ignore unknown fields; old servers ignore new fields. Never remove or change existing field numbers — this breaks wire compatibility; (2) Package versioning — use Protobuf packages like package myapi.v1 and package myapi.v2; maintain separate .proto files per major version; (3) URL versioning — embed version in the service name or server address (v1.api.example.com:443); (4) Non-breaking changes — safe: adding optional fields, adding new services, adding new RPC methods, adding new enum values; (5) Breaking changes — unsafe: removing fields, changing field numbers, changing field types, renaming fields. The Buf CLI provides a buf breaking command to detect breaking changes in CI/CD pipelines.