Skip to main content

Data Transfer Showdown: JSON vs Protobuf vs Object Serialisation

In recent months, I’ve had to dive deep into serialization and its impact on system performance for professional reasons. While it may seem like a minor technical detail, choosing the right method for data exchange can have a significant effect on application efficiency, especially in distributed systems.

JSON is a standard for sending and receiving data over the network. Sending data over the network requires sending every character of JSON over the network and although it is very readable. At least, more than XML or any other format, it is not the one that sends the fewest bytes over the network. 

In this article, I’ll compare three common approaches: JSON, Protocol Buffers (Protobuf), and Object Serialization (when both the client and server use the same language, such as Dart or Kotlin). I’ll also share a practical table summarizing estimated results based on size and speed.


JSON

JSON (JavaScript Object Notation) is a human-readable text-based format for structuring data. It is widely used due to its simplicity and compatibility with almost any programming language.

Example in JSON:

Example of a JSON object representing a user with fields for ID, name, active status, and roles.

Advantages:

  • Readable by humans, making debugging easier.
  • Extremely compatible across different programming languages.
  • Ideal for heterogeneous systems.

Disadvantages:

  • Size: Includes redundant text labels, making it heavier.
  • Speed: Parsing text is slower compared to binary formats.
  • Computational Cost: Requires conversion at both the client and server.

Protocol Buffers (Protobuf)

Protobuf, developed by Google, is a binary serialization format that encodes data in a compact and efficient structure. It requires a predefined schema (.proto) for data modeling.

Example in Protobuf:

Protocol Buffers schema defining a User message with fields for ID, name, active status, and roles.

Advantages:

  • Compact Size: Binary messages are much smaller than JSON.
  • High Speed: Serialization and deserialization are optimized for performance.
  • Efficiency: Ideal for systems exchanging large amounts of data.

Disadvantages:

  • Requires a predefined schema, which adds maintenance overhead.
  • Not human-readable, making debugging harder.
  • Both client and server must support Protobuf.

Object Serialization

When the client and server share the same language, Object Serialization allows direct conversion of objects into a binary format using language-specific libraries.

Example in Dart (Serverpod):

YAML definition of a User model for Serverpod, including fields for name, isActive status, and roles.

Advantages:

  • Efficiency: Comparable to Protobuf in size and speed.
  • Ease of Use: No separate schema is needed; the code serves as the model.
  • Speed: Avoids intermediate parsing steps like JSON.

Disadvantages:

  • Limited Compatibility: Only works when the client and server share the same language.
  • Tight Coupling: May depend on language or framework versions.
  • If we want this binary serialization efficiency, we must check and ensure that the technology we use does not create a JSON-based encoding and decoding wrapper.

Example in Kotlin for KMP:

Kotlin code defining a serializable User data class with fields for ID, name, active status, and roles.



Comparative Table with Estimated Results

The data in the following table was generated by running serialization and deserialization benchmarks using Serverpod, alongside comparisons using Dart for both JSON and Protobuf. All tests were conducted under the same conditions to ensure fairness and accuracy.

To measure performance, we serialized and deserialized a dataset containing nested objects, lists, strings, and integers. The benchmarks involved 10,000 operations for each method, with results averaged across multiple runs to account for any anomalies.

Key details of the test setup:

  • Dataset: A structured object with 100 fields, including a mix of primitives and nested elements.
  • Hardware: The benchmarks ran on a modern machine with an AMD Ryzen 5 processor and 16GB of RAM.
  • Tools: Serverpod for its native serialization, and Dart libraries for JSON and Protobuf implementations.

While JSON and Protobuf are widely recognized for their specific strengths, Serverpod introduces additional value beyond raw performance. It combines solid serialization capabilities with advanced features like code autogeneration, built-in monitoring tools, and an ORM—making it a well-rounded choice for backend development.

The table below summarizes the findings, highlighting not just the performance metrics but also the qualitative differences between these serialization methods.

A comparison table of JSON, Protobuf, and Object Serialization features, including payload size, serialization speed, deserialization speed, human readability, and interoperability.


Personal Reflection

This comparison reveals how serialization methods can influence both network performance and resource usage. JSON remains a practical choice for heterogeneous systems due to its simplicity, but its verbosity makes it unsuitable for high-performance scenarios. Protobuf, with its compact size and speed, is a clear winner for systems requiring efficient data transfer. Object serialization offers similar efficiency but is limited by its language dependence.

Serverpod, while not part of this direct comparison, occupies an interesting middle ground. Although its serialization performance might not match Protobuf in absolute terms, it offers a wealth of additional features that set it apart. These include code autogeneration, built-in monitoring tools, an ORM, and much more. These capabilities extend beyond the scope of this post but are worth exploring on Serverpod’s official website.

One of the most surprising findings is how much JSON can lag behind in terms of size and speed—Protobuf often generates payloads 2–3 times smaller, with significantly faster processing. However, this isn’t widely discussed online, and I hope this article provides some clarity for others exploring serialization. If you have questions or experiences to share, I’d love to hear from you in the comments.

Comments

© 2020 Mobile Dev Hub