At the recent Aeron MeetUp held in London on November 21, 2024, Zach Bray, Aeron Performance Engineer, gives a deep dive into SBE, the world’s most efficient message encoding standard and how it optimizes data serialization for high-performance systems. This blog summarizes some key findings. Want to watch the recording instead? Watch it here >>

Why Simple Binary Encoding (SBE) matters

In high-performance systems, the choice of data format for encoding and decoding messages can significantly impact latency and throughput. This is particularly crucial for systems that exchange a large volume of messages, such as replicated state machines built on top of an Aeron Cluster. While Aeron itself is agnostic to the data format [SBE or any other format is supported], the efficiency of the chosen format can make a substantial difference.

Performance comparison of protocol buffers

It is rare that organisations publish results comparing the use of different data formats in complex systems, but a case study from LinkedIn’s engineering blog highlights the importance of the choice. The study observed that switching from JSON to Protobuf resulted in notable latency improvements at the 99th percentile and modest throughput gains. However, SBE offers even greater performance advantages due to its design principles.

SBE, Simple Binary Encoding - Protobuf Improvements
Source: LinkedIn Integrates Protocol Buffers With Rest.li for Improved Microservices Performance, by Karthik Ramgopal

Design Principles of SBE

SBE’s design principles make it a great choice of data format for high-performance systems.

SBE, Simple Binary Encoding - Design Principles

  • Copy-Free and Allocation-Free Encoding
  • SBE uses flyweight encoders and decoders, which operate like stencils positioned over a buffer. This method allows direct writing of values into the buffer without intermediate copies, unlike Protobuf, which requires multiple intermediate copies. This approach minimizes overhead and maximizes efficiency.

    SBE, Simple Binary Encoding - Flyweight Encoders

  • Native Type Mapping
  • SBE maintains the same representation on the wire as in memory, ensuring minimal transformation overhead. In contrast, Protobuf uses variable-length encoding for tags and integers, which introduces additional computational complexity. This translates to SBE being significantly faster.

    Microbenchmarks run by Adaptive, typically, show well over an order of magnitude > 10x improvement over Protobuf in the number of messages encoded per unit of time for densely populated messages. Want to know more? Get in touch to discuss SBE.

  • Streaming Access
  • SBE’s design principles allow for forward-only memory access when encoding and decoding, which is highly predictable and works well with hardware prefetching. This contrasts with other formats like Cap’n Proto and FlatBuffers, which use relative pointers and can suffer from data-dependent loads, reducing prefetching efficiency.

Practical Implications and SBE Roadmap

While SBE offers significant performance benefits, it also places more responsibility on developers to ensure correct encoding and decoding order. To mitigate this, recent enhancements include runtime field precedence checks and DTO generation to make more operations safe.

  • Runtime Field Precedence Checks
  • These checks ensure that the order of operations during encoding and decoding adheres to the schema, preventing errors but at a runtime performance cost which might make it less suitable for production environments.

  • DTO Generation
  • Rather than classifying things as ‘safe/unsafe’, this approach attempts to simply make more things ‘safe’. By copying data into an object graph, this approach allows for safer arbitrary access to different fields, albeit with some performance trade-offs.

The SBE Roadmap

Plans for future work on SBE includes improving schema evolution tooling to prevent breaking changes, making flyweights use safer and reducing boilerplate code through generating proxies, adaptors, and domain model bindings.

Is SBE for you?

SBE stands out as a highly efficient message encoding standard, particularly suited for high-performance systems where latency and throughput are critical. While it requires careful handling by developers, recent and upcoming enhancements aim to make it more robust and easier to use.

For a more detailed exploration of SBE and its benefits, watch the full recording of Zach Bray‘s talk at the Aeron MeetUp.


← Watch the SBE Intro recording now