REST architecture has been ubiquitous in web applications over the past two decades is the widespread adoption coming to an end?
First of all, let’s explain the difference between REST and gRPC. REST abbreviated for Representation State transfer is an architecture style that focuses on using JSON and XML data formatting to communicate between client and servers. In contrast, gRPC uses protocol buffer to serialize payload data. REST focuses on communication with the use of HTTP endpoints whereas gRPC uses remote procedure calls where functions you define in code are invoked directly by other services.
Why gRPC dominates REST?
gRPC is based on HTTP 2 which solves problems that traditional REST architecture based on HTTP 1.1 battled with. HTTP 2 allows us to multiplex connections meaning that we can send streams of data over a single TCP connection without blocking. With the use of this, we can take advantage of features such as weighted prioritization to request what resources we want to receive first. This can improve the user experience of websites significantly by loading the most interacted components first.
The newer version of HTTP uses a better compressing algorithm for the HTTP headers thus reducing the bytes of the packets considerably. This improvement in compression leads to less data being sent over the network meaning increase in performance
The protocol buffer schema can be written in any language e.g. Go, Python, Java, Ruby, and many more. This can increase developer productivity as they’ll be comfortable writing
Implementation in the language of your own choice
Protocol buffer — the library used to serialize your gRPC data generates stub code in the language of your choice
Features gRPC offers over REST
- bidirectional communication between client and server-client and server can send/receive data irrespective to order.
- client stream data — continuously send server data using the same connection
- server stream data — continuously send data to the client utilizing the same connection
If you are building an application where performance is a key factor when communicating with other services consider using gRPC. You can leverage the HTTP 2 features it exposes natively.