TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The state of gRPC in the browser

203 pointsby simjueover 6 years ago

17 comments

limaover 6 years ago
My team has been using gRPC + Improbable&#x27;s grpc-web [0] + Typescript for a green field project and it has been amazing.<p>- Typing all the way to the frontend.<p>- gRPC&#x2F;protobuf forces you to describe your interfaces and are self-documenting.<p>- gRPC semantics like error codes and deadlines (if you propagate them through your stack, they&#x27;re particularly useful - for instance, we cancel database transactions across service boundaries if a request times out).<p>- Performance is great (but we&#x27;re far from seeing bottlenecks with JSON, it&#x27;s not the reason we choose gRPC).<p>- We use grpc-gateway which auto-generates a REST proxy for our customers. We sometimes use it for interactive debugging. [1]<p>- Rather than importing database models for our management tools and one-off scripts, using the API is so frictionless that we even use it inside our backend code and for CLI utilities.<p>The Google API design guide is helpful: <a href="https:&#x2F;&#x2F;cloud.google.com&#x2F;apis&#x2F;design" rel="nofollow">https:&#x2F;&#x2F;cloud.google.com&#x2F;apis&#x2F;design</a><p>One piece of advice: Treat your gRPC calls like you would treat a GraphQL resolver - if you squint your eyes, they&#x27;re very similar concepts.<p>Rather than specifying a GraphQL query, you specify a Field Mask.<p><a href="https:&#x2F;&#x2F;developers.google.com&#x2F;protocol-buffers&#x2F;docs&#x2F;reference&#x2F;csharp&#x2F;class&#x2F;google&#x2F;protobuf&#x2F;well-known-types&#x2F;field-mask" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;protocol-buffers&#x2F;docs&#x2F;referenc...</a><p>Happy to answer questions on our experience.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;improbable-eng&#x2F;grpc-web" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;improbable-eng&#x2F;grpc-web</a><p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;grpc-ecosystem&#x2F;grpc-gateway" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grpc-ecosystem&#x2F;grpc-gateway</a>
评论 #18868172 未加载
评论 #18869919 未加载
评论 #18867071 未加载
评论 #18868338 未加载
评论 #18870401 未加载
maxpertover 6 years ago
Web has come a full circle. First we disgust and hate SOAP XML and friends. Then we go to REST and realize of it&#x27;s too loose! Then we invent stuff like Swagger and JSONAPI in order to put some interfacing in place. And then we bring in cripples that give similar but water downed features of SOAP, GRPC, GraphQL and more friends.<p>Edit: I know I might get downvotes but think for a second we could have just taken some good parts from SOAP to begin with and have all the goodness.
评论 #18867933 未加载
评论 #18868130 未加载
评论 #18868374 未加载
评论 #18868603 未加载
评论 #18870728 未加载
评论 #18869591 未加载
评论 #18870070 未加载
rhackerover 6 years ago
We built out our gRPC services starting about 8 months ago. I pounded my fists on the gRPC-web issue board a bunch of times. Things started moving. In the end, it was too little and the effort is too divided. Also the route for which they wanted to implement streaming was, personally, poorly designed.<p>We have since switched to GraphQL and haven&#x27;t looked back.
评论 #18868380 未加载
评论 #18869858 未加载
helipaddiover 6 years ago
Could someone explain the difference between gRPC and Apache Thrift? Even tough the Apache Thrift project is not as active as gRPC it works quite well for us.
评论 #18870506 未加载
评论 #18869334 未加载
评论 #18869750 未加载
评论 #18872246 未加载
SlowRobotAheadover 6 years ago
Slight off topic, but has anyone executed gRPC on a C platform for embedded? I&#x27;m willing for forgo the automatic code generation - but hell if there are any good resources I&#x27;ve been able to find on this.
评论 #18872269 未加载
gregwebsover 6 years ago
I am using the HTTP Gateway and generating OpenAPI from that for type-safe access [1]. The main downside is that this introduces an additional build step in your project and a small amount of additional run-time processing. The upside is supporting a JSON API and not requiring gPRC(-Web) for clients. Even for non-browser clients, GRPC tooling can still be heavy-weight to pull into your project. Not all languages have easy to use OpenAPI integration, but any language can always just send some JSON.<p>But with the HTTP Gateway you are actually supporting both, so a browser client can still use GRPC-Web if it is able.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;gogo&#x2F;grpc-example" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gogo&#x2F;grpc-example</a>
评论 #18878346 未加载
platformover 6 years ago
One other that helps JSON&#x2F;REST to remain defacto these days, is not just a web browser support. But also nice mobile clients like Retrofit.<p>Retrofit seamlessly converts JSON data by means of json de-serializer, into Java classes. So we get typefull semantic (but, albeit at run time only).<p>I have retrofit integrated with RxJava, and when I looked what it would take to &#x27;plugin&#x27; gRPC, I found that I have to change not just my backend, but all the wiring for the mobile frontends. And, at the time it looked like too much work.<p>If Retrofit, would make it transparent JSON vs gRPC -- then it would be great for folks that already invested into Retrofit&#x2F;JSON.
hardwaresoftonover 6 years ago
gRPC is two things to me (please correct me if I&#x27;m forgetting something):<p>- A specification language for services and the RPC calls they take (except RPC response primitives include single message and stream)<p>- A binary object definition&#x2F;packing scheme (aka protobuf)<p>Outside of the HTTP and what HTTP&#x2F;2 makes possible, I feel vaguely like everyone is rushing to replace pure HTTP&#x2F;HTTP2 (and HTTP3 in the future) with something that is less extensible and could be implemented <i>inside</i> HTTP for the most part.<p>Obviously you can&#x27;t do anything about the inefficiencies of headers in HTTP&#x2F;1 (this is better in HTTP&#x2F;2 &amp; 3), the lack of built-in stream semantics (again only HTTP&#x2F;1 though you can make do with some longpolling&#x2F;SSE&#x2F;websockets scheme) but outside of the HTTP stuff you can absolutely transmit your content as a stream of tightly packed bytes and let consumers do whatever they need to...<p>Why is gRPC anything more than a content type? It&#x27;s so weird to see gRPC evolve from (in some sense, I might be wrong) HTTP + HTTP&#x2F;2, and now people trying to shoe horn it back into the browser.<p>It&#x27;s really hard to find metrics (maybe I should do a comparison and post results I guess), but like in this SO post[0]. The hype train is presenting gRPC as the <i>next</i> thing, but it shouldn&#x27;t be, IMO. Most of the improvement is from use of <i>protobuf</i> for more efficient (de)serialization -- and I don&#x27;t think gRPC is the best tool for declaring API schemas (RPC or otherwise) either.<p>[0]: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;44877606&#x2F;is-grpchttp-2-faster-than-rest-with-http-2" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;44877606&#x2F;is-grpchttp-2-f...</a>
评论 #18872298 未加载
blixtover 6 years ago
Has anyone considered using this or something else for IPC – that is, communicating between memory boundaries in the same application (e.g., Node&#x2F;web, Swift or C# to a web container, etc.)?<p>Even just for Electron the built in IPC API doesn’t really cut it long term since you don’t get typing nor proper request&#x2F;response or topic based streaming support so bugs are more likely to sneak in.
评论 #18872455 未加载
013aover 6 years ago
The state of gRPC on the browser is the main reason why my company selected Twirp instead. Being able to natively call a simple HTTP endpoint with a JSON payload is fantastic; its the benefits of protobufs when you can use it, with a graceful fallback for clients that need normal HTTP. Of course you can get this with grpc-gateway, but now you have two things to maintain.
inputdevover 6 years ago
I&#x27;ve had issues with npm and binaries of gRPC in firebase related to node versions and electron versions. It seems like this could be a good alternative if it was used in firebase since it&#x27;s implemented in typescript - not sure I completely understand it, though.
anderspitmanover 6 years ago
I&#x27;m quite surprised they&#x27;re not using websockets for streaming. Anyone know why?<p>EDIT: Better question: is anyone aware of a system like gRPC but built with bidirectional streaming for the browser from the beginning?
评论 #18871242 未加载
评论 #18869730 未加载
评论 #18869922 未加载
评论 #18870416 未加载
评论 #18869583 未加载
vbezhenarover 6 years ago
I&#x27;m surprised that streaming is not implemented for web client. Streaming seems to be a huge feature for gRPC. Why does it take so long?
DrScientistover 6 years ago
I&#x27;m excited this as an option in the toolbox.
continuationsover 6 years ago
What&#x27;s the advantage of using this over something like XMLHttpRequest?
评论 #18870441 未加载
评论 #18869593 未加载
评论 #18868715 未加载
keymoneover 6 years ago
&gt; An efficient JSON-like message encoding<p>how is this still &quot;the future&quot;?
baron816over 6 years ago
Another team at my company developed a microservice that uses gRPC that my team depends on and it’s been an absolute nightmare. Protobufs are just too limited in what they can do to make them useful except in very specific, narrow cases.
评论 #18867086 未加载
评论 #18867351 未加载
评论 #18867055 未加载
评论 #18866831 未加载
评论 #18867358 未加载
评论 #18869981 未加载
评论 #18870921 未加载