Live data from Hacker News

REST vs GraphQL vs gRPC

danhacks.com

151–160 of 168 posts

Re: REST vs GraphQL vs gRPC

#151

Another con of GraphQL (and probably GRPC) is caching. You basically get it for free with REST. REST can also return protobufs, with content type application/x-protobuf. Heck, it can return any Content-Type. It doesn't have to be confined to JSON. GRPC needs to support the language you're using. It does support a lot of the popular languages now. But most languages have some sort of http server or client to handle RE…

We solve the cacheability part by supporting aliases for queries by extended the GraphQL console to support saving a query with an alias. Also, with gzip, the size of json is not a big deal given redundant fields compress well.

Cacheability isn't just about the transfer, it's also about decreasing server load in a lot of applications. An expensive query might return a few bytes of JSON, but may be something you want to avoid hitting repeatedly.

Re: REST vs GraphQL vs gRPC

#152

I feel like this is rather shallow, and, by focusing so heavily on just the transport protocol, misses a lot of more important details. For starters, REST and "JSON over HTTP/1.1" are not necessarily synonyms. This description conflates them, when really there are three distinct ways to use JSON over HTTP/1.1: Actual REST (including HATEOAS), the "openAPI style" (still resource-oriented, but without HATEOAS), and JSO…

A counterpoint here is that if someone was seriously considering these three theyre likely choosing between HATEOAS, resource-oriented gRPC, and GraphQL.

Re: REST vs GraphQL vs gRPC

#153
post #75

> Easily discoverable data, e.g. user ID 3 would be at /users/3. All of the CRUD (Create Read Update Delete) operations below can be applied to this path Strictly speaking, that's not what REST considers "easily discoverable data". That endpoint would need to have been discovered by navigating the resource tree, starting from the root resource. Roy Fielding (author of the original REST dissertation): "A REST API must…

You are quite correct, but by this stage the original definition of REST to include HATEOAS has pretty much been abandoned by most people. Edit: Pretty much every REST API I see these days explains how to construct your URLs to do different things - rather than treating all URLs as opaque. Mind you having tried to create 'pure' HATEOAS REST API I think I prefer the contemporary approach!

I don't understand why the original dissertation is treated like gospel

Re: REST vs GraphQL vs gRPC

#154
post #95

Earlier quoted context omitted.

> Personally I prefer to have explicit control over the caching mechanism rather than leaving it to network elements or browser caching. I'm not talking about browser caching, I'm talking about the reverse proxy that fronts your ("backend") service to the internet. High traffic global/unauthenticated reads, especially those that never change, should get cached by the frontend (of the "backend", not the SPA) reverse p…

I am sure you have good reasons for your concrete design but in the general case: Why not simply build the caching into your backend services rather than having a proxy do it based on the specifics of http protocol? It would be simpler and far more powerful.

Proxy caching / leveraging caching to external service makes sense when you have a LOT of users scattered around the globe - let Akamai/Cloudflare take care of edge node caching and maintenance. In the end it saves you a lot of engineering time and infrastructure costs not mentioning user experience. YMMV but it pays off in our current setup.

Re: REST vs GraphQL vs gRPC

#155
post #15

I think for people who didnt try GRPC yet, this is for me the winner feature: "Generates client and server code in your programming language. This can save engineering time from writing service calling code" It saves around 30% development time on features with lots of API calls. And it grows better since there is a strict contract. Human readability is over-rated for API's.

On the GraphQL side you can use gqless[0] (or the improved fork I helped sponsor, here[1]). It's by far the best DX I've had for any data fetching library: fully typed calls, no strings at all, no duplication of code or weird importing, no compiler, and it resolves the entire tree and creates a single fetch call. [0] https://github.com/gqless/gqless [1] https://github.com/PabloSzx/new_gqless

Pretty cool! Graphql-code-generator is great, but this goes a whole lot further. I no longer have to even write queries.

I guess the big advantage is that when you write a manual query you can still pull down more data than you need by accident. Whereas this approach only pulls down what you need.

Re: REST vs GraphQL vs gRPC

#157

Additional GraphQL con: it requires some thought and planning in order to ensure data is cacheable in CDNs and other reverse proxies. This is generally simpler in REST because the APIs tend to be more single use. In GraphQL you have to essentially predefine all the queries in order to achieve the same cache-ability of responses. Then identify those, essentially, over REST.

Solved: https://www.apollographql.com/docs/apollo-server/performance... 2-stage request.

1. Hashes queries and uses GET requests.

2. If missing, sends a standard graphql as POST

Re: REST vs GraphQL vs gRPC

#158
post #97

I am totally expecting the next fad in web development to be just exposing a raw SQL interface to the front-end...

Jokes aside, isn’t this ultimately what we are all looking for?

We have added so many layers and translations between our frontend and database.

Graphql brought us closer and it starts to run into some of the security concerns already.

What if someone just made this direct sql interface safe/restricted?

Re: REST vs GraphQL vs gRPC

#159
post #34
post #20

I wish gRPC was bidirectional For now I will stick to SignalR

It supports bidi, and also single request, multiple responses, or multiple requests, single response - https://grpc.io/docs/what-is-grpc/core-concepts/#bidirection...

'Client- and server-side stream processing is application specific'

Sounds like write it yourself using two streams

Re: REST vs GraphQL vs gRPC

#160

Earlier quoted context omitted.

You are quite correct, but by this stage the original definition of REST to include HATEOAS has pretty much been abandoned by most people. Edit: Pretty much every REST API I see these days explains how to construct your URLs to do different things - rather than treating all URLs as opaque. Mind you having tried to create 'pure' HATEOAS REST API I think I prefer the contemporary approach!

I don't understand why the original dissertation is treated like gospel

I don't think its completely unreasonable to look at a definition like REST and be dogmatic about certain aspects like HATEOAS which are arguably absolutely central to the original concept.

However, in retrospect, it might have been an idea to give what developed from Fielding's original work a clearly different name.

Post reply on HN