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.

gRPC-Web: Moving past REST+JSON towards type-safe Web APIs

329 pointsby bestanabout 8 years ago

28 comments

andrewingramabout 8 years ago
I first saw this one a few weeks ago, and have been trying to weigh up its pros and cons over GraphQL (my tool of choice).<p>gRPC-Web:<p>* Speaks protocol buffers, a fast and compact format compared to JSON<p>* Allows clients to use the same APIs as backend services.<p>GraphQL:<p>* Enables a client-centric view of the system. I have abstractions in my GraphQL server that only make sense to clients. It&#x27;s a query-centric implementation of the Backend-for-frontend pattern, where the owners of the service are also the consumers.<p>* Enables an entire UI&#x27;s requirements to be fetched in one go (or optionally split up, if some content is less important). To achieve the same level of aggregation performance in gRPC would require building something analogous to GraphQL.<p>The other benefits of gRPC-Web outlined in the article (generating typescript bindings) are equally possible with GraphQL (Relay Modern generates flow types, and is probably just one pull request from supporting TypeScript too)<p>The status code standardisation only makes sense for single-purpose endpoints&#x2F;calls, once you&#x27;re dealing with aggregations, the semantics of a downstream status code will vary depending on the use case the query fulfills.<p>I think both solutions have use cases, and can even happily co-exist. I don&#x27;t believe gRPC-Web to be as much of a game-changer as GraphQL, but for certain scenarios (needing to rapidly fetch streams of data that don&#x27;t have cross-dependencies) I can definitely see the benefits of a solution based on gRPC.
评论 #14211248 未加载
评论 #14210990 未加载
评论 #14210956 未加载
评论 #14213834 未加载
runeksabout 8 years ago
I don&#x27;t understand this, to be honest. What does type safety have to do with serialization formats or application protocols? I&#x27;ve used Servant (Haskell) to define the REST API for my backend, which gives me type safety, server stubs and generated client code for free. In my view, type safety is about what you internally use to represent your API, and has nothing at all to do with the underlying protocol(s). There&#x27;s nothing about REST+JSON that prevents type safety, as far as I&#x27;m aware.<p>I plan to switch to protobuf3 for the serialization format, since this offers both a JSON and binary representation. Why would I want to choose gRPC+proto3 over REST+proto3?
评论 #14211315 未加载
评论 #14211319 未加载
评论 #14214120 未加载
grw_about 8 years ago
The reference implementation of gRPC on github[0] has 998 open issues and 215 open pull requests. Every time I&#x27;ve tried to use this package I have encountered a previously-reported issue which has remained unfixed for months.<p>If you need to interact with Google platform it&#x27;s hard to avoid using gRPC, since many &quot;official&quot; libraries seem to be migrating towards this library, while it remains fragile and bug-ridden. My &quot;days since gRPC problem&quot; counter is currently on &quot;2&quot;, after hitting an issue which &#x2F;crashed my python interpreter&#x2F; and required altering apache config to workaround[1].<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues&#x2F;9223" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues&#x2F;9223</a>
评论 #14214561 未加载
评论 #14211213 未加载
评论 #14210681 未加载
评论 #14211403 未加载
评论 #14211437 未加载
评论 #14211125 未加载
评论 #14215201 未加载
mvitorinoabout 8 years ago
I think I like gRPC, but have several reservations regarding replacing REST with it. REST web services often return multiple mime formats, not just pure structured data. Some services return images, others return HTML, and then you also have cache... Maybe I just don&#x27;t know enough about gRPC, but I can already imagine many people passing images around as byte arrays inside protocol buffers and when we look back, we have reinvented SOAP, which reinvented Corba.
评论 #14211092 未加载
评论 #14210617 未加载
lstroudabout 8 years ago
Stub generation? Remote access protocols? CORBA all over again?<p>So, now I know the next big thing. Portable distributed objects. :-P
评论 #14211331 未加载
评论 #14211034 未加载
评论 #14214054 未加载
评论 #14211000 未加载
评论 #14211873 未加载
archgroveabout 8 years ago
Everything old is new again, except tunnelled over HTTP.
评论 #14211542 未加载
zargathabout 8 years ago
Another hammer to a multifaceted problem, keep in mind that people have a lot of different use cases where JSON REST API&#x27;s are the lesser evil.<p>I only skipped through the spec for gRPC, but the protocol seems very limited. I dont like the &#x27;gRPC status codes&#x27;, where HTTP status codes at least can be grouped in ranges.<p>The abstraction from the technology&#x2F;protocol should not be the issue compared to the abstraction from the core business logic. When handling multiple consumers, customers and technologies I tend to worry more about where logic is handled and where data is stored, compared to how its transferred.
rdtscabout 8 years ago
REST + JSON is simple, easy to debug, and it does the job. Web clients speak JSON, servers speak JSON, humans can read JSON usually. JSON can be gzipped so you get some benefit there.<p>gRPC is another large pile of foreign C code that&#x27;s essentially a black box. If there is a buffer overflow there that your code hits only somehow, you&#x27;d have to know how to debug it and fix it.<p>Also chances are you are not Google, Facebook or Amazon , and you don&#x27;t really do BigData just your know, regular data.
评论 #14212352 未加载
评论 #14213013 未加载
TimMeadeabout 8 years ago
Just saw this during the morning reading. Without a deep dive, this looks very promising. We have recently been moving to k8s and grpc for our node work and the last piece was how to get to the browser. If this ties it all as one straight protocol from db to browser it will be very welcome and could not have come at a better time. We were evaluating the alternative (GraphQL etc) but our experiences with node and grpc have been excellent so far.<p>Immediate evaluation planned.
评论 #14211150 未加载
Gigablahabout 8 years ago
The title (&quot;by Google and Improbable&quot;) is a bit misleading since it implies a collaboration between the two, when it&#x27;s actually Improbable&#x27;s own implementation that they released ahead of Google&#x27;s pending spec.
评论 #14210438 未加载
devoplyabout 8 years ago
Unless I need high throughput, I am sticking with JSON Rest as it&#x27;s good enough for most things and easier to debug by sticking a proxy in the middle or using ngrep.
linkmotifabout 8 years ago
This kind of stuff couldn&#x27;t happen soon enough. REST is so arbitrary and less than useful for building UIs. It&#x27;s just bad.<p>I&#x27;ve got Relay talking to a GraphQL service built in graphql-java which then talks to a gRPC service layer. The gRPC service layer is a great fit for GraphQL. Some type safety all around, but there could always be more. And there could always be less JSON. Please, no more JSON. The only thing it&#x27;s good for is debug logging.
beastman82about 8 years ago
I&#x27;m using my own gRPC services and Google&#x27;s speech recognition gRPC API and I absolutely love it. Protobuf&#x2F;types, generated code, clear API contract.
grovesNLabout 8 years ago
I&#x27;m not sure why you need to modify your serialization or protocol to get type safety.<p>I&#x27;ve been using NSwag (<a href="https:&#x2F;&#x2F;github.com&#x2F;NSwag&#x2F;NSwag" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NSwag&#x2F;NSwag</a>) to generate TypeScript clients from .ASP.NET controllers and it works great. It can generate TypeScript request&#x2F;response handlers, and interfaces or classes for any public facing models.
westurnerabout 8 years ago
Wikipedia: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;GRPC" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;GRPC</a><p>Src: <a href="https:&#x2F;&#x2F;github.com&#x2F;grpc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grpc</a><p>Docs: <a href="http:&#x2F;&#x2F;www.grpc.io&#x2F;docs&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.grpc.io&#x2F;docs&#x2F;</a>
grizzlesabout 8 years ago
Personally I&#x27;d prefer a promise based api. eg. stub.QueryBooks(qbr).then(...)<p>A benefit of grpc coming to the web means someone will inevitably build a tool to parse a .proto file and generate a ui to test your microservices during dev. That will be cool.
评论 #14212323 未加载
didibusabout 8 years ago
I acknowledge it could just be me and the specific projects I worked on, but I&#x27;ve never been encumbered by an API style. RPC, Rest, GraphQL, I almost find them all to simply differ in syntax.<p>I&#x27;ve managed to solve all my use cases using all three with equal effort, time and with comparable outcomes.<p>There&#x27;s value in compression and faster serialization&#x2F;deserializarion formats when and only when micro-performance becomes an issue. Other then that, I think programmers spend way too much time debating over these, where I don&#x27;t see any one of them providing an ROI advantage over the others.
评论 #14213025 未加载
j_sabout 8 years ago
Don&#x27;t forget to protect against malicious user input! There are both pros&#x2F;cons for &#x27;non-human-readable&#x27; in the security department for sure.<p><i>Finding a $5,000 Google Maps XSS by fiddling with Protobuf</i> | <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13829925" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13829925</a>
评论 #14212850 未加载
progxabout 8 years ago
There is a reason why more and more people left RPC and use REST.<p>And for me &quot;the next big thing&quot; is something like GraphQL.
评论 #14210535 未加载
评论 #14210424 未加载
评论 #14210574 未加载
评论 #14212719 未加载
pspeter3about 8 years ago
One cautionary tale is to avoid generating code that exists at run time with Typescript. We managed to cause a severe page load regression for a while by generating Typescript for each DbObject and Projection (similar to a persistent GraphQL query).<p>My advice is to only generate types and interfaces if possible.
jupp0rabout 8 years ago
There is also Google&#x27;s own implementation of this that has been in the works for some time. See <a href="https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues&#x2F;8682" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc&#x2F;issues&#x2F;8682</a>
评论 #14210959 未加载
bedersabout 8 years ago
It is still a bit shocking to see how many people are not getting the distinction between an API and a RESTful service.<p>They are very different things and they have very different goals. The hint is in: how much do you value the client?<p>If you have full control over both client&#x2F;server or if we don&#x27;t care about any 3rd party developing a client library for your service, then go with something like GraphQL or gRPC or SOAP with a nice, typed spec you can generate your code from and optimize the heck out of the bytes coming through the tubes.<p>If OTOH you have an interest to create a RESTful service that is discoverable, that doesn&#x27;t require constant client changes, that offer a wider variety of resource representations, that need to stand the test of time, then use HATEOAS and a RESTful architectural style.<p>gRPC is yet another ... RPC. Nothing good or bad about that. Just make sure you understand the consequences.
yeukhonabout 8 years ago
But I always thought speaking HTTP with a server can be considered RPC. We can pack our message in XML, JSON, or whatever serialization we choose, passes on to the destination, unmarshall, do something, return.
daliwaliabout 8 years ago
RPC has its own set of limitations, which if your application qualifies, might be a good fit:<p>* Coupled server and client. gRPC uses protocol buffers which have zero backwards compatibility.<p>* Zero discoverability. The client knows in advance what the server can do.<p>* No standards to follow. You make up your own specs, like Google did.<p>These constraints are orthogonal to REST, the architectural principles behind the web. What they&#x27;re doing is tunneling RPC over the web, which is what most HTTP APIs are doing already. There are only superficial differences like the use of protobuf, lack of verbs and URIs, etc.
评论 #14210649 未加载
评论 #14211158 未加载
je42about 8 years ago
Is this SOAP 2.0 ?
IshKebababout 8 years ago
They sure do like spikes... whatever that means.
评论 #14211325 未加载
godmodusabout 8 years ago
Scalakka devops represent!
jlebrechabout 8 years ago
why not emulate an RPC using webpack?