Who Shot Rest? Let’s Discover gRPC

Eyup Can Arslan
7 min readMar 7, 2022

--

Photo by Maxim Hopman on Unsplash

Today, the Http have an important value on data transmission world. This remind me of Dallas. “Dallas” was an important series on the tv world. People asked a question that “Who shot Jr?”, to each other as long period in the past. Nowadays we have similar question on data transmission world. Who shot Rest?

Is gRPC a assassin or instigator? Is the target Http1? What is the fault of Rest?

Nowadays, gRPC are preferred instead of Rest especially on internal network communication. This approach brings to mind a question “What is the fault of Rest?” Why do developer choose gRpc instead of Rest? Was a magic wand touch it? Of course no magic to be done… In that case, there are a few question possible to solve this unknown issue. Can gRPC decrease system cost ? Is the reason of this, can be network capacity, transfer ratio speed ?

If we try to cover definition as basically, gRpc is an open source remote procedure framework. gRpc can efficiently connect internal services to each other. This is also possible to data center.

At this point may, we can start to think what is the differences between gRpc and RPC.

The very important and huge differences between them, the letter of “g” !!!
This “g” is represent of Google. gRPC was started to develop Google in 2015.
Just kidding :) This is only an detail.

Here is the real differences between gRPC and RPC

GRPC works on Http/2. For this way, it can use the advantages of Http/2
like bi -directional communication, streaming, multiplexing etc.
Instead of Http/2, RPC works on Http 1. So, RPC can not give an efficient solution in this topics.

GRPC use protobuf to serialize structured data.
Instead of protobuf, RPC can use XML or JSON.

** There is an important issue is that gRPC is an RPC framework. It’s feature was upgraded with the power of Http/2

Photo by Shubham Dhage on Unsplash

OMG! What a mess :) There are many definition. Let’s cleared up the confusion over the each point with the explain them step by step.

Let’s Starts With The Http

Hyper Text Transfer Protocol (http) is an computer network protocol that allow to share text, image, video (as summary data :) ) between computer.
In this point I want to split the technical explanation and look at the history.

Although, We know that Http was created in CERN, if we look at the inspiration point of Http, we meet with Ted Nelson who was coined “Hyper Text Term”.

An Mockup Of Hypertext, In 1972

As additionally, When I talked about on CERN, I want to share first website on the world in the below link…

Let’s return back to technical explanation and start to cover Http feature as basically

  • Simple
  • Extensible
  • Stateless
  • Reliable Connections
  • Caching, Sessions
  • Authentications

These can be called as basic feature of https. You can visit this web site to get detail info about this…

Photo by Darwin Vegher on Unsplash

Wow, What a big world ! Maybe , a question mark may appear in our minds. Is all of perfect feature created all of sudden?

Of course, No ! There is no magic to be done :) There are 6 important version was published and all of them important milestone.

Nowadays, Http’s 1.1 and 2 version are prefered in modern services. They came with it many features in world of Http.

We can say that, basic http features like headers and status code, was born with Http1. This was perfect but not usefull if time latency was important espacialy under the high trafic. The main reason of time latency was that Http1 was support only one request and response on same tcp connection. Connection resubility was not avaible.

Htt 1 Round Trip

The solve this time latency and support the proxies, Http 1.1 was created in 1997. Multiple request and response was avaible on the same tcp connection. Also, the pipelining was avaible that client sent many request without waiting the resposes. But the request and response order was important at there.

Http 1.1 Round Trip

If we look at the “Http1.1 Round Trip” figure, the time latency was solved. That’s perfect. Especialy in pipeline, look like ideal solution to high load. But what happen if one request’s response time higher than others.

According to this graphic, the round trip time nearly 60. Unfortunately, this is not possible to Http 1.1

Estimated round trip will be like this. Also, this will be avalible with Http1.1's pipeline mode. In this point to solve this problem, Http/2 protocol was created.

Http 2 Multiplexing Round Trip

The multiplexing feature was developed to solve head-of-line blocking problem. Also, the streaming feature was born over Http.

Let’s return back to gRpc and Rest comparison.

In the beginning of the story, I mentioned gRPC and Rest. Now, That’s time to explain gRpc and Rest releation with Http. In the other words, explain API and Http relation. If we want to cover Rest and gRpc as basicly, they are API types and running over HTTP

API(Application Program Interface) is an interface to allow create comunication between computers. A few api style was developed between 1991 and 2022. I shared a few one in the following image.

Rest, works acorringdingly request and response model over Http1.1. This is useful if your system don’t run under huge data and high traffic. For example, The Modern SOA or another calling microservices run with multiple request, multiple clients. This is the cause of huge data and high traffic, consequently slows the entire system.

Rest works on “Http 1.1”. It have latency problem under high traffic even if used pipelining. What if we implement Rest over the Http/2. It may help us with it’s amazing feature like Multiplexing. This sound is good in theory but this is not usefull as pratically. Because of, The Rest’s request and response model will be same.

GRPC does not face a similar obstacle. gRpc works on Http 2. It works accoringly bidirectional comminications rules intead of the request and response model. This meaning is that, gRpc can use Http/2’s all features like streaming, multiplexing etc. It can handle multiple request from multiple client. This solve the Rest’s problem so, huge data and high traffic don’t slows the entire system. Also, gRPC can works under Http1.1 but limited specifications like unary streaming.

May a question mark can be occured in our mind. Is the gRpc really perfect like this? Why Rest is preferred to use in system against gRpc?

All of the two API has advantage and disadvantage. We compored gRpc and Rest under the huge data in the above. What about external network’s client interface? gRpc need proxy to use external network client. Rest, can support this defaulty. The another disadvantage of gRpc, today’s modern web broswer still problem to support Http/2. For this reason, Rest still is prefered to use external network communication. If we look at the internall network communication, gRpc is started to use espacially under the high traffic.

The new things, that come programming world with Http/2 and gRpc, is not only these. We know that Json and XML is used as data message formatting with most of the API type. This format is changeg by gRpc. It uses Protocol Buffer (Protobuf) by default to serialize payload data.

Json, Xml and etc data message format needs a translation to send over TCP. This translation must be made between unicode characters and byte sequences. This adds an extra step to the process of transmitting data. However, protobuf’s translation lighter than others. Because, protobuf is consist of binary format. Protobuf has highly compressed format that’s allow to reduce message size on transfer line. These ability has some disadvantages that Protobuf file dont have humman readable format. We know that, Json give us a perfect opportunity at there.

In a conculusion, gRpc and Rest are the type of API. These work on Http. gRpc can be prefered intenal network. It can be usefull under high traffic. It help’s to decrease system load. Rest can be prefered external networks communications against of gRpc.

That’s all. Thank you for your reading.

References

--

--