Eloy
Eloy

Reputation: 396

Are there any performance benefits to gRPC compared to JSON over HTTP/2 other than size?

I read that gRPC is more performant than traditional HTTP APIs due to more compact serializing with Protocol Buffers. The other performance claim is that unlike HTTP/1.1 JSON APIs, it supports pipelining.

As I currently understand, the pipelining of multiple connections over a single HTTP connection is done by HTTP/2 and not by gRPC. So, apart from the from the more efficient data serializing format, is there actually a performance benefit for gRPC compared to JSON over HTTP/2?

Upvotes: 1

Views: 3740

Answers (1)

Jonas
Jonas

Reputation: 129065

There are multiple aspects here.

Protocol: HTTP/1.1 vs HTTP/2

There are many improvements in HTTP/2 over HTTP/1.1, but there are also disadvantages for some use cases. Some examples of improvments:

  • HTTP/2 is a binary protocol whereas HTTP/1.1 is a text protocol
  • HTTP/2 can reuse the TCP-connection for multiple requests sent to different endpoints but to the same server.
  • HTTP/2 has improved header compression features with HPACK. This is useful if you e.g. send the same Authorization: Bearer <JWT-token> in consecutive API-requests.

Payload format: JSON vs Protocol Buffers

This may have an effect on payload size but serialization and deserialization performance is probably more important. Another important aspect is developer tooling and productivity.

Protocol Buffers, used by gRPC is not the only efficient binary payload format. There are many alternatives, e.g. FlatBuffers, a zero-copy format, designed after experience with Protocol Buffers. Another binary format, mainly for smaller payload (not serialization performance) is Avro. Avro format may have a benefit in evolvability of the payload format (see e.g. Designing Data-Intensive Applications).

See e.g. JSON vs Protocol Buffers vs FlatBuffers for a comparison.

gRPC

gRPC is a higher protocol abstraction than purely using HTTP/2. Fewer details is left to the developer to take care of. In all, there are many aspects in the choice of HTTP/2+JSON vs gRPC, it all depends on what's the most important aspect for your use case.

Upvotes: 2

Related Questions