Reading — step 1 of 5
Read
~2 min readProduction
MessagePack vs JSON vs Others
| Feature | JSON | MessagePack | Protobuf | CBOR | BSON |
|---|---|---|---|---|---|
| Schema | No | No | Yes | No | No |
| Wire size | Bigger | Small | Smaller | Small | Bigger |
| Speed (encode) | Slow | Fast | Fast | Fast | Fast |
| Type system | Limited | Rich (binary, ext) | Rich + custom | Rich (tags) | Rich |
| Browser native | Yes (JSON.parse) | No (libs) | No | No | No |
| Human-readable | Yes | No | No | No | No |
| Standardized | RFC 8259 | spec | proto3 | RFC 8949 | MongoDB |
| Streaming | Hard | Yes | Yes | Yes | Yes |
When to use each:
JSON:
- Public APIs (browser-friendly).
- Config files (Hjson, JSON5 for human).
- Logging.
- Default for most web work.
MessagePack:
- Internal RPCs where you want JSON-like flexibility but smaller.
- Caches that need compact serialization.
- Languages without good Protobuf support.
- Schemaless storage.
Protobuf:
- Service-to-service in big systems.
- Tight schema control + evolution.
- gRPC.
- Google + many enterprises.
CBOR:
- Similar to MsgPack but IETF standardized.
- Used in some IoT (CoAP).
BSON:
- MongoDB internal.
- Larger than MsgPack but typed.
FlatBuffers / Cap'n Proto:
- Zero-copy access to structured data.
- Game state, real-time graphics.
Avro:
- Hadoop / Kafka ecosystems.
- Schema embedded with data (write).
Performance benchmarks (rough, vary by platform):
- JSON: 1x baseline.
- MsgPack encode: 2-3x faster.
- MsgPack size: 30-50% smaller.
- Protobuf encode: 3-5x faster than JSON.
- Protobuf size: 60-80% smaller than JSON.
Picking:
- Public + browser: JSON.
- Internal + flexibility: MsgPack.
- Internal + strict + perf: Protobuf.
- IoT + standardized: CBOR.
For new internal services: Protobuf is usually the right choice. MsgPack when you need JSON's flexibility minus the verbosity.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…