Slide 1

Slide 1 text

Why Protocol Buffers (Protobuf) Are Better than JSON @rajivmanivannan

Slide 2

Slide 2 text

• 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

Slide 3

Slide 3 text

• 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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

How do Protocol Buffers Work? Sample .Proto f ile

Slide 6

Slide 6 text

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)

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

• Python (Server) • Flutter (Client) https://github.com/rajivmanivannan/protobuf-demo Protobuf Demo

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Q & A Thank you