11 ms·
GraphQL Performance Monitoring Is Hard
- xemdetia 7y agoOh goody I just hit my first medium.com effective paywall. Can we kill it now and go back to ordinary blog hosting? https://i.imgur.com/Ii3VcfA.png https://i.imgur.com/Ii3VcfA.png
- ehutch79 7y agoI keep seeing stuff like this and wonder where the actual advantage to graphQL is?
- kenrose 7y ago1. Fewer API round trips compared to REST. 2. Clients only download the data they need. No more REST silly patterns like BFF trying to support multiple client needs. Yes, this does make instrumentation and rate limiting harder, but not impossible. It’s akin to using SQL... sometimes the query optimizer does weird things, but declaratively asking for your data is much better than imperatively pulling and joining it yourself.
- BinaryIdiot 7y ago> 1. Fewer API round trips compared to REST. Why? This is always my chief complaint about GraphQL: there is no reason it should take fewer trips than directly hitting an endpoint unless you're structuring everything very rest-y in which case you're doing it wrong and GraphQL is a bandaid (and you'd still probably make the same amount of trips unless you're heavily caching things). IMO. > 2. Clients only download the data they need. Most third party APIs let you specify what fields you want via a query string or post variable which amounts to the same thing. Honestly I think if people stopped trying to force REST into everything and just made RPC like calls to HTTP we'd have far less of a need for GraphQL. Don't get me wrong, I still think GraphQL is pretty cool for third party access in some respects but I don't think it's as useful as a lot of people make it out to be.
- biggestdecision 7y agoSure, it's possible to setup a REST api with those features (return full objects for fields rather than ID's, client specifies which fields to return in the query). But then you've basically just built a graphQL api. Any syntax you pick for allowing the client to specify which (nested) fields to return is going to look like a graphQL query. And using graphQL gives you some nice tools to use on the client side.
- BinaryIdiot 7y ago> But then you've basically just built a graphQL api Not really. The type of API where you specify what you want and the API itself included whatever data you need in an RPC fashion has been around for decades, I feel weird calling it a "graphql api". Ultimately GraphQL gives you some tools. The developer just has to figure out if those tools make up for the additional overhead (processing, size, training, etc). Sometimes it'll be justified I just think more often then not it really isn't.
- biggestdecision 7y agoSure it's not a new concept. But on the web graphQL is the most prominent implementation of that concept. You can roll your own version of the concept, but why bother when a perfectly serviceable one already exists? With already written client & server implementations in your language of choice?
- wereHamster 7y ago> [other types of APIs] has been around for decades GraphQL is indeed not a new invention. It's a standardisation of existing ideas, that has been given a particular name, and a whole community of people who are building tooling around it. If you tell me you are using/implementing GraphQL then I immediately know what to expect. I know which tools I can use, I know you have a schema, I know I can run queries and the syntax of those etc. But if you tell me that you are using a REST/HATEOAS/RPC with some particular query syntax then I first have to spend a day reading through the documentation to understand the API.
- tjpnz 7y ago>1. Fewer API round trips compared to REST. 2. Clients only download the data they need. No more REST silly patterns like BFF trying to support multiple client needs. In most cases a thoughtfully designed REST API built according to HATEOAS shouldn't exhibit these problems. I've seen too many teams with a flawed understanding of both viewing GraphQL as some kind of silver bullet. Instead of stopping to consider their architecture they just rush out and implement GraphQL only to find themselves having significantly worse performance issues than they were having before.
- strken 7y agoMy understanding of the advantage of GraphQL is that it allows you to load a structure like user { groups(first: 10) { posts(first 1) { content author { name address { state } } } } } and have all the round-trips take place within a datacentre, instead of needing to query /user /user/12/groups?limit=10 /groups/34/posts?limit=1 /posts/56 /users/78 /users/78/address and without having to write a separate /top_posts_view endpoint. I don't understand from the description "a thoughtfully designed REST API built according to HATEOAS" what your proposal to solve this problem is.
- JoachimSchipper 7y agoA quick search suggests that GraphQL should usually cause one client -> server -> SQL-server query - i.e. only one network round trip. No?
- strken 7y agoI've only used it to aggregate backend services rather than as an SQL query builder, and this is also how it's used at Facebook. I'd have concerns about writing business logic in resolvers. If I was using it with a single SQL db I'd probably write a separate non-GraphQL layer for business logic and keep the resolvers thin.
- 7y ago
- bsaul 7y agoI’ve read somewhere GraphQL major use case was in actually building BFF... Unless you’re building one giant graphql enpoint exposing your whole database ?
- tepidandroid 7y agoAlong with what kenrose said, imagine the flexibility of being able to request the exact view that you need from the server for any client you have in mind. A perfect view fetched in a single trip -no overfetching or underfetching, no bespoke HTTP endpoints for every new use-case and a self documenting API + type-safety to boot. Some trade-offs are things like more backend complexity, querying complex data (like deeply nested or recursive data structures) becomes harder, limiting exponential query complexity as the data branches out, etc. It also becomes more difficult to predict resource usage and to monitor performance, as the article mentions.
- lkrubner 7y agoThere is something badly broken with your process for denormalization if you think bespoke endpoints are more work than GraphQL. Presumably you have to denormalize for many internal uses, as well as external ones, so it pays to automate that process till it is both flexible and easily configured and automatic.
- thom 7y agoBut you’ve just described a bunch of work to do to achieve what’s GraphQL gives you for free, surely?
- dmitriid 7y agoThere’s nothing free. Requesting “any view for any potential client” will most likely cripple your backend because you can’t optimise ad-hoc queries.
- thom 7y agoSo in the presumably rare case that this happens can one not just add a new view, map it in the GraphQL schema and still come out far ahead on development time? I just feel like a huge number of people are going to accept lower complexity in the short term with some optimisation to do later. That seems like an fairly sensible and defensible tradeoff. I’ll admit I’m not picturing public APIs though.
- true_religion 7y agoGraphQL is basically well structured RPC calls. So everything you wanted to do with SOAP, with none of the headaches and really nice instrumentation and documentation thrown in as part of the protocol. I'm usually surprised with all the comparisons to REST. It's far more practical and way less dogmatic.
- aleksei 7y ago> I'm usually surprised with all the comparisons to REST. I'd say that's because you should mentally substitute RPC whenever you see REST. Basically everyone talking about REST APIs mean RPC over HTTP with nouns in the endpoints.
- davnicwil 7y agoTo me, the question is the other way round because the advantages (pointed out by all the other comments in this thread so I won't repeat) are clear, kind of immediately. It's the disadvantages, particularly the 'unknown unknowns' that I wonder about, and that's what's kept me from using it. GraphQL so far seems like the archetypal counter example for the 'use boring stuff' philosophy of software engineering. I kind of hope I'm wrong here, because the advantages are big and pretty cool.
- strken 7y agoGraphQL is pretty boring, at least on the server. You give your GraphQL library a schema and tell it how to deal with fields, and then it makes a tree of fields from your query and populates them according to your instructions. It can get "exciting" on the client, particularly with libraries like Apollo. See for example the bug https://github.com/apollographql/apollo-client/issues/1186 https://github.com/apollographql/apollo-client/issues/1186, which took two years to fix. The tooling for persisted queries can also be hard to set up, and they're close to required if you want to expose GraphQL to your client.
- dmitriid 7y agoIt’s actually exciting on the server. Ad-hoc queries with unlimited complexity? Check. No caching? Check. No auth? Check.
- barbellguy97 7y agoWhat do you mean wirh unlimited complexity, no caching oe aithorization? Have you ever used ot server-sody? Because they are all solved problems, except maybe caching in the transport layer, depensing on which forn of caching you're targetting.
- dmitriid 7y ago> What do you mean wirh unlimited complexity, no caching oe aithorization? I mean what I mean exactly. - GraphQL allows ad-hoc queries of unlimited complexity. - Since it's POST requests, there's no caching on the HTTP layer. - Since it's add-hoc queries, it's hard to devise a cache for the DB layer. - There are no easy solutions for either authentication or authorisation for queries (and subqueries and/or fields) > Because they are all solved problems If by solved you mean "busily reinventing the wheel and adding layers and layers of unneeded complexity, and it will only work if you buy into a single vendor's solution such as Apollo". For crying out loud, one of the "solutions" for caching is to actually parse both the incoming and the outgoing requests, read the fields and decide if it needs to be cached.
- deleted 7y ago[deleted]
- itake 7y agoIsn't that what https://www.apollographql.com/platform https://www.apollographql.com/platform solves?
- gms 7y agoYep, only if you're using Apollo though.
- KenanSulayman 7y agoIs it tho? We’re using elastic APM which is free and the Nodejs modules just work. They’re breaking down every request down to the database call.
- DevKoala 7y agoI am confident that GraphQL can be superior to REST in an scenario in which the client is iterating on features at an exponentially faster pace than the back end development can support. However, I’ve yet to find myself in that scenario. Simplicity of instrumentation and rate limiting are higher priorities in my experience.
- kromem 7y agoNot really. I mean, not any more difficult than any other internal component of an application. Yes, you can't just aggregate by URL endpoint, but add opentracing and start at the top level resolver, and then start a new segment at each nested resolver. Poof - you have an extremely nuanced view of your application performance. Add in aggregate time metrics for each unique query/mutation and you'll have an even better view of what going on - far better than if you were simply looking at API endpoint timings in the first place.
- ThePhysicist 7y agoI always thought it was a bit crazy to let the client control the computational complexity of a query (to a certain degree) as it makes query optimization really difficult. A few years back I designed a REST API and made the mistake of allowing too many query parameters, which made it really hard to optimize the database as there were hundreds of possible filter combinations (some requiring joins) that a client could ask for and that needed to be covered with indexes, so while most of the common queries worked well some of the "long tail" queries would always run into timeouts. When using GraphQL with a backend like Hasura that generates SQL queries I would think that you have the same problem for complex data models, as there will be countless combinations of filters and joins that your database would need to efficiently cover. From what I understand most organizations solve this by either restricting the types of queries you can make through GraphQL or by just defining timeouts and dropping queries that take too long (which does not offer a great user experience). To all of you who use GraphQL in practice, how do you solve this issue?
- sgk284 7y agoHasura is the best example I know of a beautiful, well engineered, well documented product that solves the completely wrong problem. It just converts a custom syntax represented in GraphQL into arbitrary SQL queries, which is absolutely absurd. They have mechanisms to restrict access, but the fundamental foundation of the idea is flawed. GraphQL is great in that you define the exact queries that you know to be performant. Once you resolve your top-level payload, most of the nested fields will be non-parameterized relations. These are usually just tons of multi-gets. So in practice, you have top-level queries that you know to be performant, followed by multi-gets that you know to be performant. If you do have a parameterized field, make sure it's fast.
- jacques_chester 7y ago> GraphQL is great in that you define the exact queries that you know to be performant. How is this meaningfully different from having an SQL query fronted by a REST API?
- 7y ago
- maktouch 7y agoWe solved this by using persistent queries that maps it like /graphql/{queryname}/{hash}?{params} Multiple advantages: 1) client doesn't need to send the whole query unless it doesn't exist. All of this is handled automatically. 2) http caching of queries are now possible since it's a get instead of post 3) we can check slow queries using similar tools as rest. When we see a query being slow, we check each resolvers. We usually keep the queries simple
- 013a 7y agoThis tweet from Ryan Florence [1], a big influencer in the frontend community, is something I think back to pretty often. Its so clear to me that GraphQL is designed and pushed primarily by frontend devs who's goal is, probably unconsciously, to reduce the complexity and thus workload of their slice of the system. Its a selfish local optimization that dramatically increases the net complexity of the entire system. "You dumb backend devs created so much complexity for us frontenders, now its our turn to ruin YOUR part of the system." GraphQL may one day have the tooling and ecosystem to reduce the net complexity of the entire system, but that day wasn't a year ago, its definitely not today, and judging by how long the community has had to mature and still hasn't... probably won't be for a very long time, if ever. Probably because, again, its pushed by frontend developers primarily, so the pace of innovation on the backend side of it is dramatically slower. Apollo Client is an amazing piece of software that does some insanely smart things; Apollo Server is a thin wrapper around Express which does nearly nothing of value beside "make a GraphQL server possible." Given how slowly things are progressing in GraphQL-land, I'd estimate that it has another two years before the zeitgeist moves against it. Though I hope I'm wrong, because its got some pretty cool ideas and is dramatically better for frontend development than anything else out there. [1] https://twitter.com/ryanflorence/status/1060557386421723136 https://twitter.com/ryanflorence/status/1060557386421723136