Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why Protocol Buffers (Protobuf) Are Better than...

Why Protocol Buffers (Protobuf) Are Better than JSON

Rajiv Manivannan

September 27, 2024
Tweet

More Decks by Rajiv Manivannan

Other Decks in Technology

Transcript

  1. • Introduction to gRPC • Introduction to Protocol Buffers •

    Comparison: Protobuf vs JSON • Pros of Protobuf • Cons of Protobuf • Protobuf Demo: Python (Server) & Flutter (Client) • Takeaway • Q & A Agenda
  2. • gRPC is a high-performance remote procedure call framework developed

    by Google • Its primary use case is service-to-service communication • RPCs are a way to execute code on another server, like a local method call. They are a great way to implement communication in distributed system • gRPC stands out with Protocol Buffers for the Interface De f inition Language*. It allows gRPC to have strong typing and code generation support. • gRPC uses HTTP/2 for improved network ef f iciency and real-time communication. *Interface De f inition Language (IDL) is a speci f ication language used to de f ine data structures, types, and interfaces in a way that is independent of any speci f ic programming language. Intro to gRPC
  3. What are Protocol Buffers? • Protocol Buffers are a language-neutral,

    platform-neutral extensible mechanism for serializing structured data. • Developed by Google • Schema-based • binary format How are they used? To exchange data between services, especially in micro services, mobile and IoT environments. Intro to Protocol Buffers
  4. Protobuf vs Json FEATURE PROTOCOL BUFFERS JSON Format Binary Text

    (String) Schema Strict (De f ined by .proto) Flexible (Schema-less) Size Smaller Large Performance Faster ( serialisation) Slower Readability Not human-readable Human-readable Backward Compatibility Yes (via optional f ields) Limited (without schema validation)
  5. 1. Compact Binary Format • Reduces payload size signi f

    icantly. 2. Faster Serialization/Deserialization • Optimized for performance in comparison to JSON. 3. Strict Schema and Type Safety • Guarantees the structure and type of data, reducing errors. 4. Backward and Forward Compatibility • Easier to maintain versioned APIs. 5. Cross-language Compatibility • Supports 8+ languages directly like C++, C#, Java, Kotlin, Objective- C,PHP,Python and Ruby. Dart and Go lang are supported by Google. The protoc compiler uses plugins for these languages Pros of Protocol Buffers
  6. Cons of Protocol Buffers 1. Binary Format Not Human-Readable •

    Makes debugging and inspection dif f icult without tools. 2. Additional Learning Curve • Requires knowledge of .proto f iles and toolchain for compiling. 3. More Complex Versioning • Requires careful management of schema evolution. 4. No Native Browser Support • Additional JavaScript libraries required for usage in web applications.
  7. Use Protobuf when: • Data size and speed are critical

    • Schema enforcement is needed • Cross-language support is required Use JSON when: • Human readability and f lexibility are important • Server side application is written in JavaScript Takeaway