144

The goal is to introduce a transport and application layer protocol that is better in its latency and network throughput. Currently, the application uses REST with HTTP/1.1 and we experience a high latency. I need to resolve this latency problem and I am open to use either gRPC(HTTP/2) or REST/HTTP2.

HTTP/2:

  1. Multiplexed
  2. Single TCP Connection
  3. Binary instead of textual
  4. Header compression
  5. Server Push

I am aware of all the above advantages. Question No. 1: If I use REST with HTTP/2, I am sure, I will get a significant performance improvement when compared to REST with HTTP/1.1, but how does this compare with gRPC(HTTP/2)?

I am also aware that gRPC uses proto buffer, which is the best binary serialization technique for transmission of structured data on the wire. Proto buffer also helps in developing an language agnostic approach. I agree with that and I can implement the same feature in REST using graphQL. But my concern is over serialization: Question No. 2: When HTTP/2 implements this binary feature, does using proto buffer give an added advantage on top of HTTP/2?

Question No. 3: In terms of streaming, bi-directional use-cases, how does gRPC(HTTP/2) compare with (REST and HTTP/2)?

There are so many blogs/videos out in the internet that compares gRPC(HTTP/2) with (REST and HTTP/1.1) like this. As stated earlier, I would like to know the differences, benefits on comparing GRPC(HTTP/2) and (REST with HTTP/2).

5
  • what did you end up using? is there a framework for HTTP2+REST?
    – knocte
    Oct 25, 2017 at 7:23
  • 2
    @knocte I ended up using gPRC. It reduced the latency quite well. Regarding the HTTP/2+REST, there is no specific framework, it is the settings that you need to change in the server that you using. Say, you are using nginx, look into the docs for seeing the steps to setup HTTP/2. Oct 27, 2017 at 3:33
  • and you must make sure that HTTP/1.1 reuses connection. Otherwise search for "tcp cold start". gRPC reuses connection by default. Mar 6, 2018 at 14:25
  • @LakshmanDiwaakar Have you tried HTTP2 REST + PROTOBUF (or MESSAGEPACK) ? I am keen to know. Personally I would like to use gRPC but want to avoid PROTOBUF in favour of MESSAGEPACK. How are you deploying gRPC? Any framework are you using like Spring Boot, Quarkus or Micronaut?
    – Debjit
    Jan 15 at 22:28
  • I do not understand why people relate REST with JSON together? We can have REST + PROTOBUF or REST + MESSAGEPACK also. @LakshmanDiwaakar Thank you for putting up the question.
    – Debjit
    Jan 15 at 22:38

3 Answers 3

148

gRPC is not faster than REST over HTTP/2 by default, but it gives you the tools to make it faster. There are some things that would be difficult or impossible to do with REST.

  • Selective message compression. In gRPC a streaming RPC can decide to compress or not compress messages. For example, if you are streaming mixed text and images over a single stream (or really any mixed compressible content), you can turn off compression for the images. This saves you from compressing already compressed data which won't get any smaller, but will burn up your CPU.
  • First class load balancing. While not an improvement in point to point connections, gRPC can intelligently pick which backend to send traffic to. (this is a library feature, not a wire protocol feature). This means you can send your requests to the least loaded backend server without resorting to using a proxy. This is a latency win.
  • Heavily optimized. gRPC (the library) is under continuous benchmarks to ensure that there are no speed regressions. Those benchmarks are improving constantly. Again, this doesn't have anything to do with gRPC the protocol, but your program will be faster for having used gRPC.

As nfirvine said, you will see most of your performance improvement just from using Protobuf. While you could use proto with REST, it is very nicely integrated with gRPC. Technically, you could use JSON with gRPC, but most people don't want to pay the performance cost after getting used to protos.

4
  • Thank you @Carl for the answer. Can you share us some links/docs explaining all the above things and the link for benchmarks? Jul 7, 2017 at 1:35
  • 5
    I updated the response to link to the dashboard. I don't have docs directly explaining these, but I am a core contributor. Jul 7, 2017 at 18:21
  • please provide the load balancing library link
    – BozoJoe
    Apr 11, 2019 at 5:39
  • @CarlMastrangelo I think this was the answer i was looking for. Also, I would argue for the PROTOBUF thing, I am comfortable using gRPC but protobuf is something i want to avoid and would prefer something like MESSAGEPACK.
    – Debjit
    Jan 15 at 22:33
36

I am not an expert on this by any means and I have no data to back any of this up.

The "binary feature" you're talking about is the binary representation of HTTP/2 frames. The content itself (a JSON payload) will still be UTF-8. You can compress that JSON and set Content-Encoding: gzip, just like HTTP/1.

But gRPC does gzip compression as well. So really, we're talking about the difference between gzip-compressed JSON vs gzip-compressed protobufs.

As you can imagine, compressed protobufs should beat compressed JSON in every way, or else protobufs have failed at their goal.

Besides the ubiquity of JSON vs protobufs, the only downside I can see to using protobufs is that you need the .proto to decode them, say in a tcpdump situation.

1
  • 2
    Thank you @nfirvine for your opinion on the question. The serialization feature kinda makes sense. Can you add some more details/explanation on how serialization happens in REST and gRPC. It would be great, If you could share some links on the same. Jul 5, 2017 at 2:09
0

What I found out is, If you want to send files such as txt, img or video files then REST/HTTP is much faster than gRPC. If you want to send objects over the wire, then gRPC is effecient.

Sources: For sending files,, sending large files,, another blog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.