Questions about gRPC support in web browsers and how they utilize HTTP2
Asked Answered
C

1

24

Upon discovering gRPC, I stumbled across this blog post

Why isn’t everyone already using gRPC in their SPAs?

Traditionally it’s not been possible to use gRPC from browser-based applications, because gRPC requires HTTP/2, and browsers don’t expose any APIs that let JS/WASM code control HTTP/2 requests directly.

But there is a solution! gRPC-Web is an extension to gRPC which makes it compatible with browser-based code (technically, it’s a way of doing gRPC over HTTP/1.1 requests). gRPC-Web hasn’t become prevalent yet because not many server or client frameworks have offered support for it… until now.

ASP.NET Core has offered great gRPC support since the 3.0 release. And now, building on this, we’re about to ship preview support for gRPC-Web on both server and client. If you want to dig into the details, here’s the excellent pull request from James Newton-King where it’s all implemented.

There is some good information here, but the post is around a year old at this point.

There are also some major pushes from Microsoft with .NET and Blazor technology recently.

It looks like grpc-web is pretty well maintained and always adding a lot of language support, so that's something to keep an eye on... but as I understand it grpc-web is still built to operate over HTTP1.1?

For me, another question that still remains why HTTP2 is not supported through browser APIs, to which I cannot find any documentation on.

I would love to start using gRPC, but am also concerned about the cons that might come with it.

Thank you for any explanations to my lack of understanding.

Note there is a slightly related question on SO about this here, to which the answers were not totally comprehensive and older.

Chancellorship answered 21/1, 2021 at 8:31 Comment(0)
G
16

I have used grpc in my projects and understand your questions about it. The first two questions can be answered via a quote from grpc.io followed by some elaboration.

- For me, another question that still remains why HTTP2 is not supported through browser APIs, to which I cannot find any documentation on.

- It looks like grpc-web is pretty well maintained and always adding a lot of language support, so that's something to keep an eye on... but as I understand it grpc-web is still built to operate over HTTP1.1?

It is currently impossible to implement the HTTP/2 gRPC spec3 in the browser, as there is simply no browser API with enough fine-grained control over the requests. For example: there is no way to force the use of HTTP/2, and even if there was, raw HTTP/2 frames are inaccessible in browsers. The gRPC-Web spec starts from the point of view of the HTTP/2 spec, and then defines the differences. quote reference

- I would love to start using gRPC, but am also concerned about the
cons that might come with it.

I puplished an story about gRpc. You should read. This can be helpful to understand gRPC.

I also want to talk about this topic. Why do you want to use gRPC? Is this about the speed of Http2 and gRPC? Is Http1.1 is old technology? Today, REST protocols work on Http1.1. If they start to use Http2.0, there won't be any changes to these interfaces. Also, REST is faster than gRPC if you don't work with streaming. gRPC has a better advantage when it comes to speed.

Below, I linked the supported types of RPC from GRPC-WEB

enter image description here

Googol answered 21/1, 2021 at 19:6 Comment(10)
That article is exactly what I was looking for. Thank you for your insight. Do you know why HTTP/2 can’t be forced or why raw HTTP/2 frames aren’t exposed? Is this a security thing from a browser standpoint or just a lack of development in browsers (for whatever reason)? It seems like gRPC web isn’t worth the extra overhead to migrate (on the proxy end of things at least)Chancellorship
"If to be honest I dont have detail knowlage about on Http/2 security. " May, You can ask a new question on Stackoverflow about this.Googol
" It seems like gRPC web isn’t worth the extra overhead to migrate (on the proxy end of things at least)" I understand that you find useless to grpc. I think, each protocol has advantage and disadvantage. think the differences of Rest and Soap :)Googol
ASP.NET Core has gRPC web support built in. No separate proxy required: learn.microsoft.com/en-us/aspnet/core/grpc/…Subdiaconate
It is completely not clear why "REST is faster than gRPC" given the fact that REST is not formally defined at all. It is more like a "philosophy", or a concept. In other words, it is practically impossible to compare a concrete protocol and it's implementations with just an idea in terms of performance.Enchanting
For example, both JSON and protobuf are serialization formats, and they can be directly compared. And JS implementation of protobuf is certainly faster than JSON implementation (JSON.parse/stringify). gRPC is backed by protobuf, and seems like APIs which claim to "be REST" tend to use JSON...Enchanting
@tosh If you compoare the Http1.1 and Http2.2 protocol, you can detect the speed issue. Especialy look on acknowlogment state. Also the grpc can transfer data on single tcp but this is not possible for Rest. If we make a test on Streaming, we can detect this issue also.Googol
I'm not sure I understood what you are talking about. Both REST and gRPC can work over, again, both HTTP 1 & 2. I also don't understand what is Http2.2 - if we are talking about Hyper Text Transfer Protocol, then there is just no such a thing (and Http 2.1 as well) - there is only HTTP/2Enchanting
Can you share your performance test results on this - REST is faster than gRPC?Epigeal
Great article you provided. Thanks!Polonium

© 2022 - 2024 — McMap. All rights reserved.