Senior LevelREST APIs & Web Services
How do custom Protobuf serializers minimize binary wire size compared to JSON?
❓ Interview Prompt: Explain Protobuf binary encoding mechanics, Tag-Length-Value (TLV), Varints, omitting field names, and payload size reduction.
Why Protocol Buffers v3 binary payloads are up to 80% smaller than equivalent JSON payloads:
Binary Encoding Mechanics:
1
No Field Names on Wire: JSON transmits string key names ('"firstName": "Alice"'). Protobuf replaces key strings with 1-byte field numbers ('tag = 1').
2
Varints (Variable-Length Integers): Small integers ('42') take 1 byte instead of 4 or 8 bytes.
3
Tag-Length-Value (TLV): Encodes field numbers and wire types compactly without quotes, commas, or whitespace formatting overhead!
Code Implementation Example
json
// JSON Payload (62 bytes):
{ "id": 101, "name": "Alice", "email": "alice@example.com" }
// Equivalent Protobuf v3 Binary Byte Array (24 bytes!):
// [ 0x08, 0x65, 0x12, 0x05, 0x41, 0x6c, 0x69, 0x63, 0x65, 0x1a, 0x11, ... ]💡Comparing JSON text payload byte size vs Protobuf binary payload encoding.
🎯 Interview Key Takeaway
Protobuf replaces string field keys with tag numbers and varints, yielding binary payloads up to 80% smaller than JSON.
#Protobuf#Binary Encoding#Varints#Senior
Back to all REST APIs & Web Services Questions→