← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Message Serialization (Avro/Protobuf)

messaging Intermediate

TL;DR

Binary serialization formats (Avro, Protobuf, MessagePack) are faster and smaller than JSON for high-throughput messaging — with schema evolution support for Avro.

Explanation

JSON: human-readable, no schema, large. Avro: binary, schema required, schema registry for evolution. Protobuf: binary, .proto schema, excellent language support, smaller than Avro. MessagePack: binary JSON (no schema). Schema registry (Confluent): stores Avro/Protobuf schemas, enforces compatibility (backward/forward/full). Schema evolution: Avro backward compatible — add optional fields with defaults. Protobuf: add fields with new numbers, never reuse numbers. For PHP: use avro-php, google/protobuf PHP library. JSON is fine for low-volume; use binary for high-throughput Kafka pipelines.

Common Misconception

JSON is sufficient for all messaging — for high-throughput Kafka pipelines (millions/sec), JSON parsing CPU and size become significant. Protobuf is 3-10x smaller and 5-10x faster to parse.

Why It Matters

At high throughput, serialization format determines CPU cost and network bandwidth — binary formats can cut infrastructure costs significantly.

Common Mistakes

  • No schema validation on JSON messages — producer sends wrong structure, consumer crashes.
  • Not using a schema registry — schema changes break consumers silently.
  • Reusing Protobuf field numbers — causes decoding errors in old consumers.

Code Examples

✗ Vulnerable
// JSON — verbose, no schema enforcement:
$producer->send(json_encode(['userId' => 1, 'amount' => '10.00'])); // Is amount int or string?
✓ Fixed
// Protobuf — typed, compact:
$msg = new OrderCreated();
$msg->setUserId(1);
$msg->setAmountCents(1000); // Explicit type
$producer->send($msg->serializeToString());

// Consumer:
$event = new OrderCreated();
$event->mergeFromString($rawMessage);

Added 23 Mar 2026
Views 19
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 5 Perplexity 4 Unknown AI 3 Ahrefs 2 ChatGPT 1 Google 1
crawler 15 pre-tracking 1
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Use Protobuf for new high-throughput pipelines. Add schema registry if using Avro. Never change Protobuf field numbers. Always validate message schema on consumer.
📦 Applies To
cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
json_encode\|json_decode
Auto-detectable: ✗ No
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File Tests: Update

✓ schema.org compliant