Why JSON lost to Google Protocol Buffers? How MicroServices Communicate Efficiently Together?

Rachit Jain Podcast 4 years ago

Description

In this video, we understand how is response data encoded during inter-network communications and also how is it stored on disk?
Sets, Maps, Arrays - they are in-memory data structures. But how can we store them on disks? Python uses in-built pickle module to encode (serialize) data to store them onto disks. But can it be read by a Java client?
Things would have been easy if we used JSON to encode data and store on disks. So why use Pickle?
Actually, we rely on other binary encodings like Google Protobuf, Facebook Thrift for doing this encoding and decoding.
We can serialize the data into protobuf in Python and then parse and read it from a C++ client - no issues!
Plus, we save on the amount of bytes needed to store the data. For a JSON taking 83 bytes on disk, protobuf may need only 33 bytes! Smaller sizes also result in faster inter-server communications. Thus, when a microservice talks to microservice, its common to encode response into protobuf which is then parsed by the reader.

The other benefit with Protobuf is it supports forward and backward compatibility - you can extend and add new keys to your data and old code can work with new data (forward) while new code can work with old data (backward).

One thing to note is Protobuf works well with messages which are few megabytes in size.

References
DDIA Book: https://amzn.to/3B6TJcm
System Design Playlist: https://bit.ly/system-design-course
Google Protobuf: https://developers.google.com/protocol-buffers/docs/overview
Blog1: https://auth0.com/blog/beating-json-performance-with-protobuf/
Blog2: https://betterprogramming.pub/use-binary-encoding-instead-of-json-dec745ec09b6


Sponsored By Educative.io
โœ… ๐—˜๐—ฑ๐˜‚๐—ฐ๐—ฎ๐˜๐—ถ๐˜ƒ๐—ฒ.๐—ถ๐—ผ [46% OFF] ๐Ÿ‘‰๐Ÿปhttps://bit.ly/educative-unlimited-extra-discount
Educative.io coupon "rachit" to get extra discount or use the link above to get "Unlimited" access to "ALL" courses on their websites - React, System Design, Coding Interview in C++, Python, Java, Redux, Docker and what not!

Chapters
00:00 Preview of Google Protobuffers Beating JSON
00:15 Sponsor
00:50 Introduction
1:12 How are Arrays, Sets, Maps Stored on Disk?
1:49 Encoding and Decoding in the Web HTTP Requests
2:36 Encoding Algorithm should support Decoding Algorithm
3:05 Approach A - Encode Everything to JSON!
3:38 Approach B - Binary Encodings Beat JSON for TerraBytes of Data
4:41 File Encoding Should Support Forward and Backward Compatibility
6:50 Where to use JSON?
7:03 MicroService to MicroService - Binary Encodings Are Better
8:10 Demo Comparing JSON Encoding with Google Protobuf
10:09 Comparison of HTTP Response Times - JSON vs Google Protobuf
12:12 How Exactly Google Protobuf is more efficient than JSON encodings?


๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ฉ๐—œ๐—˜๐—ช ๐—ฃ๐—ฅ๐—˜๐—ฃ ๐—ฃ๐—ฅ๐—ข๐——๐—จ๐—–๐—ง๐—ฆ
โœ… ๐—˜๐—ฑ๐˜‚๐—ฐ๐—ฎ๐˜๐—ถ๐˜ƒ๐—ฒ.๐—ถ๐—ผ [10% OFF for First 90 Users] ๐Ÿ‘‰๐Ÿปhttps://educative.io/rachit
โœ… ๐—ฆ๐˜†๐˜€๐˜๐—ฒ๐—บ ๐——๐—ฒ๐˜€๐—ถ๐—ด๐—ป [Discount for Indian audience] ๐Ÿ‘‰๐Ÿปhttps://bit.ly/design-rachit
โœ… ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ด ๐—•๐—ผ๐—ผ๐—ธ๐˜€ [Amazon Affiliate] ๐Ÿ‘‰๐Ÿปhttps://amazon.in/shop/rachitjain

SUBSCRIBE AND HIT BELL ICON TO CHECK MORE OF MY CONTENT
http://youtube.com/RachitJain?sub_confirmation=1


๐—ฆ๐—ข๐—–๐—œ๐—”๐—Ÿ ๐—ฃ๐—ฅ๐—ข๐—™๐—œ๐—Ÿ๐—˜๐—ฆ
โœ… Portfolio Website - https://rachitiitr.com
โœ… Instagram - https://www.instagram.com/rachitiitr
โœ… LinkedIn - https://linkedin.com/in/rachitiitr
โœ… Twitter - https://twitter.com/rachitiitr
โœ… Github - https://github.com/rachitiitr/DataStructures-Algorithms
โœ… Facebook - https://fb.me/AlgorithmsWithRachitJain


๐—œ๐— ๐—ฃ๐—ข๐—ฅ๐—ง๐—”๐—ก๐—ง ๐—ฃ๐—Ÿ๐—”๐—ฌ๐—Ÿ๐—œ๐—ฆ๐—ง๐—ฆ
โœ… ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—Ÿ๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ๐˜€ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=J1JZjhdr3Oo&list=PLfBJlB6T2eOshO8-LYaMt-Pes1IFojJ_l
โœ… ๐—š๐—ฟ๐—ฎ๐—ฝ๐—ต ๐—ง๐—ต๐—ฒ๐—ผ๐—ฟ๐˜† ๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=xyJxCjweLKE&list=PLfBJlB6T2eOu3dTPKzvAf2axlmQUXGY91
โœ… ๐—–++ ๐—ฆ๐—ง๐—Ÿ ๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=g-1Cn3ccwXY&list=PLfBJlB6T2eOvyt21CIX_PMmhOgWHiFVab
โœ… ๐— ๐˜† ๐—ฃ๐—ฒ๐—ฟ๐˜€๐—ผ๐—ป๐—ฎ๐—น ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—˜๐˜…๐—ฝ๐—ฒ๐—ฟ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ๐˜€ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=0Vmtmqa9Og0&list=PLfBJlB6T2eOuUAof03sQFlUcrk_Bc7jOA
โœ…๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐˜ƒ๐—ถ๐˜๐˜† ๐—ง๐—ถ๐—ฝ๐˜€ ๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=0Vmtmqa9Og0&list=PLfBJlB6T2eOuUAof03sQFlUcrk_Bc7jOA
โœ…๐—Ÿ๐—ถ๐—ณ๐—ฒ ๐—Ÿ๐—ฒ๐˜€๐˜€๐—ผ๐—ป๐˜€ & ๐— ๐—ฒ๐—ป๐˜๐—ผ๐—ฟ๐˜€๐—ต๐—ถ๐—ฝ ๐Ÿ‘‰๐Ÿปhttps://www.youtube.com/watch?v=9SGM0EqyUc0&list=PLfBJlB6T2eOv8klCHHNVLOmTOIxKu-xzn



๐—ฃ๐—ฅ๐—ข๐—š๐—ฅ๐—”๐— ๐— ๐—œ๐—ก๐—š ๐—ฃ๐—ฅ๐—ข๐—™๐—œ๐—Ÿ๐—˜๐—ฆ
โœ… Github โ–บ https://github.com/rachitiitr/DataStructures-Algorithms
โœ… Programming Blog โ–บ http://rachitiitr.blogspot.com
โœ… CodeForces โ–บ http://www.codeforces.com/profile/rachitjain
โœ… CodeChef โ–บ http://www.codechef.com/users/rachitiitr