Apollo Optics and your GraphQL Server
Performance monitoring for Scaphold apps
Update: There is a new version of Optics! Apollo Engine has everything Optics does plus error tracking, query caching, and more. Engine is free for 1 million requests a month and it’s easy to switch from Optics to Engine using our migration guide.
Hi folks! Today, we’re going to be walking through why you should be monitoring and analyzing your GraphQL server for performance, and how Scaphold and Apollo Optics integrate to make this very easy.
Why are analytics important?
For those that care about performance, money, UX, and scalability.
As we move into a GraphQL-first world, it’s important to be able to understand not only what data you’re fetching, but also how it’s being fetched. Many people think of this as an after-thought, hoping that simply getting as much code as possible out as fast as possible will help them win over their competition.
However, this approach can be costly on many levels. First, your application’s end users will notice the clunkiness of your application. In addition, on your servers, fetching data the wrong way can create inefficiencies that cost you in CPU usage, memory leaks, and slow response times (not to mention your AWS bill skyrocketing through the roof). Not the type of growth you’re looking for, probably.
Let’s get started!
Easily hook up Apollo Optics into your GraphQL API in a couple minutes.
Luckily, there’s a simple tool to use for GraphQL query analytics: Apollo Optics. You can try it out for free, and it comes with a beautiful dashboard that helps you visualize your queries to gain insights on request order and response times.
GraphQL lends itself to awesome tooling like this due to its type system, where you can clearly and automatically introspect what the inputs and outputs are of a an API.
Here’s a step-by-step run-through of how you can create and immediately get analytics for a GraphQL app using Scaphold and Optics.
- Sign up for Scaphold and create an app.
Once you hit Create, you’ll automatically have a production-ready GraphQL server and API at your disposal.
2. Sign up for Apollo Optics and grab your API key.
On your Apollo Optics account, open your app settings.
Copy your API key for use in the next step.
3. Add Apollo Optics integration on Scaphold.
In the Integrations Dashboard, click Add.
Paste your API key from earlier into the appropriate field, then hit Create.
4. Make a request and see it in your Optics dashboard!
In this case, we created a couple users and queried for all of them back.
Our data shows up within seconds in our Apollo Optics dashboard. Hooray!
Seeing the Value
Trimming out unnecessary calls can save you time and money.
To demonstrate how much money we can save by leveraging analytics to eliminate unnecessary calls, let’s make a Stripe call to create a new customer in order to simulate Facebook’s payment flow.
Check it out in your Optics dashboard. Look at how much time that request took: 219ms.
Looks like the bottleneck is when we’re asking for the created field to be returned as part of the request. We actually don’t need that value on our client, so let’s remove it.
After running this mutation, we can see that the total request time was only 157ms.
Request time decreased by over 28%! 🎉
In dollar amounts, you were able to save Facebook about $20 each time a new customer was created. Now, that’s pretty significant.
Congratulations! You’ve successfully set up powerful analytics to help you optimize your GraphQL API, and saved yourself both time and money.
Thanks for reading!
If you’re interested in learning more about analytics, feel free to join our Slack channel and ask us directly, or get started today with Apollo Optics and Scaphold.io! We’re happy to provide more information on how you can optimize your GraphQL API and more.
Originally published at Scaphold.io.