What is the difference between proto2 and proto3?
Answer
Proto3 is the current recommended version. Key differences from proto2: (1) Field presence — proto2 supports optional, required, and repeated; proto3 makes all singular fields optional by default (no required), removing required field validation; (2) Default values — proto3 uses zero values as defaults (0 for numbers, "" for strings, false for bools) and doesn't serialize them, reducing message size; proto2 allows explicit defaults; (3) Unknown fields — proto3 originally discarded unknown fields (fixed in 3.5+ to preserve them); proto2 preserves them; (4) Maps — proto3 has native map fields (map<string, Value>); proto2 uses repeated message entries; (5) JSON mapping — proto3 defines a standard JSON encoding; proto2 doesn't. Proto3 is simpler and preferred for new projects. Proto2 is still used in legacy Google codebases.
Previous
What is gRPC gateway and what problem does it solve?
Next
What are the best practices for designing gRPC APIs at scale?