Api Design hard
Your gRPC service uses Protobuf. You need to rename field 'userId' to 'user_id'. How do you do this without breaking existing clients?
- A Directly modify the field name in the .proto definition; Protobuf uses string keys for serialization and will dynamically map the new name during deserialization.
- B Retain the original field number (tag) while renaming the identifier; Protobuf identifies fields by their numeric tags in the wire format, making the name change a purely cosmetic update.
- C Deprecate the original field by assigning it a new, higher field number and declaring the new 'user_id' identifier with the original field number to ensure legacy support.
- D Implement a custom gRPC interceptor that performs a string replacement on the binary buffer to substitute the old identifier with the new one before the message is parsed.
Answer: B. Retain the original field number (tag) while renaming the identifier; Protobuf identifies fields by their numeric tags in the wire format, making the name change a purely cosmetic update.
Protobuf relies on unique **field numbers** (tags) to identify fields in the binary wire format, not field names. Renaming `userId` to `user_id` does not change the tag (e.g., `tag = 1`). Therefore, old clients (sending `userId`) and new servers (reading `user_id`) remain compatible as long as the tag and data type match. Changing the tag number, however, would break compatibility.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?