The value that we're able to build and extract from diverse sets of data becomes really, really powerful. And the reason why then GraphQL makes this all really helpful for us is that to orchestrate this, there's less overhead, because I've just merged all the pieces into a single API, I have a smaller control plane, I'm not having to worry about shipping around my environment variables and everything else. I've got reusable patterns that I can reuse over and over again at different tooling. And it's like totally agnostic to the consuming application, if I'm shipping an Android application or an iOS application or whatever it might be that doesn't matter. And that agnostic part is actually really, really, really critical because I'm arguing here that that API has value for us across a number of different contexts, not just front-end consumers.
Well, let's go ahead and dive a little bit further into the theoretical models here. So what we have here is sort of your common GraphQL service structure, right? You've got your order product, you've got for reads, and then log in, log out, purchase, and editing your orders as mutations, or roughly speaking. And so you've got maybe SQL services or REST services identified for the data you need on the one side, and then on the other side, you've got micro-services for logging in and logging out and resets, and that's kind of roughly how this data sort of plays together. Well, you'll see that the data dependencies of something like a purchase, we need access to all this data. But something like a purchase model might actually be protected context, right? Because we're talking about mutating a database, or we're inserting content, or wanting to have data that's potentially interfacing with our database, and so we want this federated of data dependencies in the context of wherever our service might be running. So if that service happens to be purchased, we still need user order and product, but why can't we just get access to that data, like, at the execution time? And we're going to talk about some of the reasons people say that you can't, but let's go ahead and break this into a bit more of a less abstract model.
What happens if we were to say that the data model we're actually working with is way more complex, right? So we've got, you know, network credit average, we've got pending purchases, historical income, we've got the history of the users' returns, blah, blah, blah, what we have here is a risk assessment model. This is highly protected data. This is something we would like to be able to get information from as a feedback to just kind of wait, whether or not this person has a risk assessment for a credit score or whatever else. It's like, we need all this other data, which is going to live in very different silos, to be able to come together to make this weighted calculation. And so what I'm arguing here is I'm saying that, you know, we have the query coming from the client, from the front-end client, trying to get information about, am I approved or not approved, whatever it might be, but then that same protected environment can actually make a query itself with the same data API that I was able to call from my front-end client with the same API endpoint from the actual risk assessment service back to my same GraphQL API and get the entire data picture that I'm looking for to be able to make that calculation. Why do I, all of a sudden, do I need to actually break out into an entirely new environment for all of this data? I want to be able to access this data at the place that I need it. And so, then, if I can make that calculation, I can work with all the data payload I need for my calculation, I'm reducing the amount of round-trips and everything else that I might happen to need. Well, this isn't actually just theory, right? This is actually something that we see implemented everyday, at Hasura specifically, across healthcare, across reverse ETL things, DORA metrics, we have food delivery companies, all kinds of different services that are having to deal with this data.
Now I wanna go into some dissenting opinions and, as I say, also here, everybody's allowed to be wrong, but one of the arguments is that it's not what GraphQL was created for. I argue that, well, actually, it is totally what it was designed for, to be defining your data dependencies for an execution. Yes, it wasn't in the front-end context to reduce data over the wire, but it was about getting the data you need in the context you need it. Well then, what about latency? Okay, so, marginally higher than potentially a very optimally designed REST API, but that too is a solvable problem, so I want to cover our approach to that. So when we move on here, talking about our solutions for that, we want to do the gotchas, and there are none, so we can just go. So when we talk about latency, there are actually solvable problems for this, but this is something you have to bear in mind with the data model. This is true for any API, but generally speaking, the user can wait, right? I would be happy to wait an extra one to two seconds, if the service worked the first time and didn't have a hangup on the API side. The second piece is new API, new problems. So potentially we're actually just shifting all of the errors or the issues we had with best-consuming patterns for our microservices just into an entirely new context where we have to build out all of this new infrastructure to support microservices consumption of GraphQL. And here's where I really want to kind of hammer here. So we actually have a new API, but we have a hero emerging.
Comments