Can anyone explain when to use protocol buffer instead of JSON for micro-services architecture? And vice-versa? Both on synchronous and asynchronous communication.

推荐答案

何时使用JSON

  • 您需要或希望数据是人类可读的
  • Data from the service is directly consumed by a web browser
  • Your server side application is written in JavaScript
  • 您还没有准备好将数据模型绑定到模式
  • 您没有足够的带宽将另一个工具添加到您的工具库中
  • The operational burden of running a different kind of network service is too great

Pros of ProtoBuf

  • Relatively smaller size
  • Guarantees type-safety
  • 防止架构违规
  • Gives you simple accessors
  • 快速序列化/反序列化
  • 向后兼容性

While we are at it, have you looked at flatbuffers?

这里将介绍其中的一些方面

Reference:

https://codeclimate.com/blog/choose-protocol-buffers/

https://codeburst.io/json-vs-protocol-buffers-vs-flatbuffers-a4247f8bda6f

Json相关问答推荐

盒子图显示不正确

无法从JSON解析ZonedDateTime,但可以使用格式化程序很好地解析

在Ansible中从json中提取特定数据

Powershell ConvertFrom-Json 意外地从包含字符串的单个项目数组生成字符串而不是对象数组

报告重复的对象键

从 oracle 数据库中的 json blob 打印值

如何在 Apps 脚本中循环遍历 JSON 响应

从字节解码 JSON 数据,将 float 值更改为 int

JSON 模式实际用于什么目的?

PowerShell - JSON/PsCustomObject - 为什么我的数组被扁平化为一个对象?

如何使用 LINQ 在 C# 中重构对象?

如何通过 NSJSONSerialization 在 JSON 中包含空值?

JSON.stringify 不会转义?

如何将有向无环图 (DAG) 存储为 JSON?

杰克逊:反序列化 for each 值都具有正确类型的 Map

从调试器获取 IntelliJ Idea 中的 JSON 对象

在 iPhone 上解析 JSON 日期

Laravel 5 控制器将 JSON 整数作为字符串发送

如何从 jQuery ajax 调用将复杂对象传递给 ASP.NET WebApi GET?

杰克逊自动将 Joda DateTime 格式化为 ISO 8601 格式