[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-ep-103-optimize-latency-with-binary-protocol-and-protobuf-all--*":3,"academy-blog-translations-5el58rpk7rqo756":80},{"data":4,"page":67,"perPage":67,"totalItems":67,"totalPages":67},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":75,"keywords":76,"locale":49,"published_at":77,"scheduled_at":13,"school_blog":71,"short_description":78,"status":69,"title":6,"updated":79,"updated_by":13,"slug":72,"views":74},"EP.103 Optimizing Latency with Binary Protocol and Protobuf","sclblg987654321","school_blog_translations","\u003Cp>In real-time WebSocket communication systems, \u003Cstrong>speed and efficiency\u003C\u002Fstrong> are critical especially when user volume or data payload increases.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>By leveraging \u003Cstrong>Binary Protocol\u003C\u002Fstrong> and \u003Cstrong>Protocol Buffers (Protobuf)\u003C\u002Fstrong>, you can dramatically reduce data size, lower latency, and significantly boost your WebSocket server’s throughput. 🚀\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>1. Why Use a Binary Protocol?\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>WebSockets typically transmit data in \u003Cstrong>JSON format\u003C\u002Fstrong>, which is easy to read but comes with several drawbacks:\u003C\u002Fp>\u003Cul>\u003Cli>Large data payload\u003C\u002Fli>\u003Cli>Requires parsing every time\u003C\u002Fli>\u003Cli>Consumes CPU and bandwidth\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Binary protocols\u003C\u002Fstrong> help reduce this overhead because:\u003C\u002Fp>\u003Cp>✅ They use \u003Cstrong>30–70% less data\u003C\u002Fstrong> than JSON\u003Cbr>✅ Convert data into a \u003Cstrong>binary stream\u003C\u002Fstrong> that's faster to parse\u003Cbr>✅ Lower \u003Cstrong>latency\u003C\u002Fstrong> between server ↔ client\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Format\u003C\u002Fth>\u003Cth>Data Size (bytes)\u003C\u002Fth>\u003Cth>Latency\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>JSON\u003C\u002Ftd>\u003Ctd>~120 bytes\u003C\u002Ftd>\u003Ctd>15 ms\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Binary (Protobuf)\u003C\u002Ftd>\u003Ctd>~40 bytes\u003C\u002Ftd>\u003Ctd>5 ms\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>2. What Is Protocol Buffers (Protobuf)?\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Protobuf is a \u003Cstrong>high-efficiency serialization format\u003C\u002Fstrong> developed by Google.\u003Cbr>It’s ideal for speed-critical systems such as \u003Cstrong>WebSockets\u003C\u002Fstrong>, \u003Cstrong>gRPC\u003C\u002Fstrong>, or \u003Cstrong>IoT\u003C\u002Fstrong> networks.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Example \u003Ccode inline=\"\">.proto\u003C\u002Fcode> definition:\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-proto\">syntax = \"proto3\";\n\nmessage ChatMessage {\n  string sender = 1;\n  string content = 2;\n  int64 timestamp = 3;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>You can then generate Go code using:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext language-bash\">protoc --go_out=. --go_opt=paths=source_relative chat.proto\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>3. Example: Using Protobuf with WebSocket in Go\u003C\u002Fh2>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net\u002Fhttp\"\n\n\t\"github.com\u002Fgorilla\u002Fwebsocket\"\n\t\"google.golang.org\u002Fprotobuf\u002Fproto\"\n)\n\nvar upgrader = websocket.Upgrader{\n\tCheckOrigin: func(r *http.Request) bool { return true },\n}\n\nfunc handleConnection(w http.ResponseWriter, r *http.Request) {\n\tconn, err := upgrader.Upgrade(w, r, nil)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer conn.Close()\n\n\tfor {\n\t\t_, data, err := conn.ReadMessage()\n\t\tif err != nil {\n\t\t\tbreak\n\t\t}\n\n\t\tvar msg ChatMessage\n\t\tif err := proto.Unmarshal(data, &amp;msg); err == nil {\n\t\t\tfmt.Printf(\"[%s]: %s\\n\", msg.Sender, msg.Content)\n\t\t}\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"\u002Fws\", handleConnection)\n\tfmt.Println(\"WebSocket Server running on :8080\")\n\thttp.ListenAndServe(\":8080\", nil)\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>✅ The \u003Cstrong>client side\u003C\u002Fstrong> can also encode\u002Fdecode messages using Protobuf — enabling \u003Cstrong>fast and lightweight\u003C\u002Fstrong> communication.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>4. Results from Using Binary Protocol + Protobuf\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>🔹 Reduce latency by \u003Cstrong>over 60%\u003C\u002Fstrong>\u003Cbr>🔹 Save bandwidth — especially for mobile users\u003Cbr>🔹 Scale the system \u003Cstrong>without changing schema\u003C\u002Fstrong>\u003Cbr>🔹 Lower \u003Cstrong>CPU usage\u003C\u002Fstrong> during message parsing\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>5. Best Practices\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>💡 Use \u003Cstrong>Gzip\u003C\u002Fstrong> or \u003Cstrong>Brotli\u003C\u002Fstrong> compression along with binary data\u003Cbr>💡 Design your Protobuf \u003Cstrong>schema to be flexible\u003C\u002Fstrong> for future versions\u003Cbr>💡 Use \u003Cstrong>connection pooling\u003C\u002Fstrong> to manage large user bases efficiently\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🚀 Challenge for You\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Try switching from JSON to Protobuf. Measure your system's \u003Cstrong>latency, throughput, and memory usage\u003C\u002Fstrong> and see how performance skyrockets! ⚡️\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🔜 Next EP\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>EP.104 – WebSocket Compression and Delta Updates\u003C\u002Fstrong>\u003Cbr>Dive into \u003Cstrong>real-time compression techniques\u003C\u002Fstrong> and learn how to update only the \u003Cstrong>changed parts\u003C\u002Fstrong> of data to make your WebSocket server \u003Cstrong>faster and lighter\u003C\u002Fstrong> than ever! 🔥\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp data-start=\"498\" data-end=\"834\">\u003Cstrong>Read more\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FGolang\">\u003Cstrong>Golang The Series\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FJS2GO\">\u003Cstrong>JS2GO\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fen\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\">\u003Cstrong>10 Eps That Will Make You a Pro Tailwind CSS Overnight\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🔴 YouTube: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.youtube.com\u002Fchannel\u002FUC2eI2RxcA2zbTqZyHyWIfRg\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevschool\u002F\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdevacademy.com\u002Fen\">\u003Cstrong>https:\u002F\u002Fwww.superdevacademy.com\u002Fen\u003C\u002Fstrong>\u003C\u002Fa>\u003Cstrong>&nbsp;\u003C\u002Fstrong>\u003C\u002Fp>","178_11zon_4sdnl7u3b4.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fuyl9obcyyaw348c\u002F178_11zon_4sdnl7u3b4.webp","2026-03-04 08:45:52.493Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:34:00.920Z","ecac9y661or1xka","WebSocket","2026-04-10 16:08:05.227Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:44:10.705Z","xicaissou94ouj5","Protobuf","2026-04-10 16:12:40.965Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:45:52.242Z","fjcmfms1mw4u0hd","Binary Protocol","2026-04-10 16:13:05.403Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:20:14.253Z","ah6lvy4x8qe08l5","Golang","2026-04-10 16:07:26.172Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:44:47.893Z","1r53azecnj44o3t","Real-time","2026-04-10 16:12:50.006Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":54,"collectionId":55,"collectionName":56,"created":13,"expand":57,"id":71,"slug":72,"updated":73,"views":74},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":66,"th":66},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","5el58rpk7rqo756","ep-103-optimize-latency-with-binary-protocol-and-protobuf","2026-05-11 23:19:27.100Z",222,"uyl9obcyyaw348c",[20,25,30,35,40],"2025-10-27 02:19:47.289Z","Learn how to boost your WebSocket Server’s performance by using Binary Protocol and Protocol Buffers (Protobuf) to reduce latency, minimize bandwidth usage, and improve real-time communication efficiency.","2026-04-25 02:47:57.653Z",{"th":72,"en":72}]