In this discussion, I make some points on why we should use protobuf
over JSON-RPC for the various APIs that our nodes will expose. This has already started with protocols such as MVDS and RemoteLog using protobuf
whereas Waku and Mailservers still use JSON-RPC, a relic from their Ethereum past.
There are several aspects we should look at, however it is important that we do in order to chose a suitable candidate as we work on our protocols. It is important that we pick one with which we can stick and continue to use for the rest of our work.
This discussion was started due to the updating of our mailserver api, there is an open pull request on the subject, see vacp2p/specs#116 for details.
Transport
Both JSON-RPC and Protocol Buffers are transport agnostic, this means they can be defined and work over various transports e.g. websockets, http etc. This means both are equal in this.
Serialization
JSON-RPC is simply JSON, however with protocol buffers we have a variety of forms the data can be represented, including binary and json based formats.
Definitions
Protocol Buffers has a more formal schema, it is easy to define what the input is for a given query and what the output is. See the below example.
message Foo {}
message Bar {}
service Baz {
rpc Bat (Foo) returns (Bar);
}
This however does not exist for JSON-RPC, there is no formalization on how to define the schemas, methods etc. This has been pointed out by MHS in regards to Ethereum.
Tooling
Another issue pointed out in the thread regarding the use of JSON-RPC within ETH2.0 is that JSON-RPC doesn’t really have any tooling. There is no standard on how to define request, responses nor is there any formal language. Protocol buffers however give us this. The fact that we have an actual specification and proper tools for protocol buffers to me is the most important point.
IP
One of the arguments often mentioned in the blockchain space (especially Ethereum), is the fact that the protocol buffer IP is owned by google. Which could potentially be a bad thing (?), I think this is a non issue however.
Stateful
One thing Peter mentioned, is that json-rpc is stateful, this may be problematic. I am not sure if this is just ethereum related or more general, however this means that horizontal scaling is completely out of the picture. JSON-RPC is made for two peers sending messages between eachother, which it is good at. It is not really made for client-server relationships however, which a mailserver is.