Grpc vs rest api performance8/5/2023 ![]() ![]() Ultimately, it is one service talking to another. The only difference now is that instead of frontend, basket service makes 10 RPC calls to Discount.Grpc service. You can manage it using only Discount.Grpc but then you need to implement JavaScript gRPC stub on frontend. This will reduce calls between frontend and backend.īut why two discount services? Discount.API is for frontend to backend communication implemented through Open API standard and Discount.Grpc is for backend to backend communication. We can delegate this task to basket service wherein as soon as the item is added in the basket, we can tell basket service to communicate with discount ( Discount.Grpc to be precise) service and apply the discount to each item and then give back the whole JSON response to the user. If we give frontend the responsibility to call discount API and calculate the discounted item price, then it needs to make 10 API calls. We also need to apply discounts to the individual items. Now think of another scenario where the user adds 10 items in the basket. In case the user wants to see all discounts on one page, we can make a call from the browser to Discount.API service. Our backend architecture is designed in form of microservices where we have a basket, catalogue, ordering, discount and brand services. Technically, all the fields in the objects or few? Let’s consider a scenario where we are running an online shopping platform, of course not as big as Amazon. Well, the client requesting the data can decide how much data it wants. What if your payload is always bigger? No matter what protocol you use, the data to be transmitted over the Internet will take time according to no. To achieve better performance, gRPC and HTTP/2 alone are not enough. Point-to-point real-time services that need to handle streaming requests or responses.Polyglot systems where multiple languages are required for development.Lightweight microservices where efficiency is critical.Reduced network usage with Protobuf binary serialization.Supports client, server, and bi-directional streaming calls.Tooling available for many languages to generate strongly-typed servers and clients.Contract-first API development, using Protocol Buffers by default, allowing for language agnostic implementations.Modern, high-performance, lightweight RPC framework.HTTP/2 just modifies the way data is framed and transported between the client and server. All the core concepts, such as HTTP methods, status codes, URIs, and header fields, remain in place. HTTP/2 doesn’t modify the application semantics of HTTP in any way. From that, HTTP/2 is able to know if the header contains the same value and only sends the header value if it is different from the previous header. HTTP/2 maps the header on both the client and the server-side. But compressing headers is not the most important part. Everything in HTTP/2 is encoded before it’s sent, including the headers. This is solved in HTTP/2 using a strategy called HPack. You might have also come across cases where HTTP headers are bigger than the payload. Using this mechanism, it’s possible to have data from multiple requests in a single connection. In this layer, the HTTP request/response gets broken down into frames. The binary layer encapsulates and encodes the data. This kind of request/response multiplexing is made possible in HTTP/2 with the introduction of a new HTTP/2 layer called binary framing. A new connection will need to be created for each of them. In traditional HTTP protocols (till HTTP/1.1), it is not possible to send multiple requests or get multiple responses together in a single connection. So how is gRPC’s performance better than other API models? HTTP/2 is one of the big reasons on which gRPC relies. In gRPC, one service can directly call a method of another service on a different machine as if it were a local object, making it easier for you to create distributed applications and services. But why use gRPC when we already have REST and Open API (think of Swagger) Why gRPC? Although, the client (JavaScript, etc) can also make the call. ![]() This is where gRPC (Remote Procedure Call) comes into the picture to facilitate backend to backend communication more efficiently. These services are not only called from frontend but there is also a lot of inter-service communication to get the aggregated results. Nowadays, the backend architecture purely depends upon microservices. Before we get into the nitty-gritty of Protobuf and FieldMasks, it is important to understand what is gRPC. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |