Hard GraphQL Problems at Shopify

Rate this content
Bookmark

At Shopify scale, we solve some pretty hard problems. In this workshop, five different speakers will outline some of the challenges we’ve faced, and how we’ve overcome them.

Table of contents:
1 - The infamous "N+1" problem: Jonathan Baker - Let's talk about what it is, why it is a problem, and how Shopify handles it at scale across several GraphQL APIs.
2 - Contextualizing GraphQL APIs: Alex Ackerman - How and why we decided to use directives. I’ll share what directives are, which directives are available out of the box, and how to create custom directives.
3 - Faster GraphQL queries for mobile clients: Theo Ben Hassen - As your mobile app grows, so will your GraphQL queries. In this talk, I will go over diverse strategies to make your queries faster and more effective.
4 - Building tomorrow’s product today: Greg MacWilliam - How Shopify adopts future features in today’s code.
5 - Managing large APIs effectively: Rebecca Friedman - We have thousands of developers at Shopify. Let’s take a look at how we’re ensuring the quality and consistency of our GraphQL APIs with so many contributors.

FAQ

Shopify's versioning system allows for API changes to be made in a controlled manner, ensuring backward compatibility and smooth transitions for developers. It helps manage and schedule API changes, alerting developers about deprecations and necessary updates through version releases.

Shopify deprecates fields by marking them and gradually phasing them out. They provide warnings and updates through their API health dashboard and developer changelogs, giving developers time to adapt before the fields are removed in future API versions.

Shopify optimizes GraphQL query performance on mobile by implementing strategies like pagination, parallel querying, and careful management of query costs. They focus on minimizing data loads and optimizing data retrieval times to enhance user experiences on mobile devices.

Shopify ensures the accuracy of GraphQL queries by using a combination of version control, schema validation, and proactive monitoring of API usage. They manage breaking changes by providing versioned APIs, allowing developers to choose when to adopt new changes and adjust their applications accordingly.

The GraphQL Schema Bot at Shopify automates the detection of common GraphQL issues in schema changes. It helps maintain high-quality API design by flagging potential problems and inconsistencies, thereby reducing manual review workload and ensuring API design standards are met.

Shopify handles nullability by carefully considering whether fields should be nullable or non-nullable based on the likelihood of being able to always return a value. They use nullability to provide flexibility in their schema and to avoid breaking changes that might impact client applications.

Using directives in Shopify's GraphQL APIs allows for more flexible and dynamic query behavior, enabling context-specific customizations such as regional pricing or conditional data fetching. Directives help manage runtime execution and type validation behavior, enhancing API functionality and developer control.

Rebecca Friedman
Rebecca Friedman
Jonathan Baker
Jonathan Baker
Alex Ackerman
Alex Ackerman
Théo Ben Hassen
Théo Ben Hassen
 Greg MacWilliam
Greg MacWilliam
164 min
01 Dec, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The Workshop covered various topics related to GraphQL at Shopify, including the Nplusone problem, batch loading with lazy resolvers, contextualizing GraphQL APIs with directives, optimizing GraphQL for mobile, managing large GraphQL APIs, and handling deprecated fields and nullability. The speakers shared insights and solutions to these challenges, such as using Active Record Preloading, GraphQL Batch library, and custom directives. They also discussed the importance of measuring performance, pagination design, and parallel querying for mobile optimization. Overall, the Workshop provided valuable information on improving GraphQL performance, API design, and versioning strategies.

1. Introduction to Workshop

Short description:

Thank you all for joining us for the workshop. Over the next three hours, five different speakers will discuss the problems they've tackled with GraphQL at Shopify. Each session will be 20 minutes long, followed by a short break and an hour-long Q&A session. Feel free to ask questions in the chat throughout the workshop.

So, once again, thank you to everyone who's been able to join us here. I truly appreciate your time. We all do, all our speakers, all of Shopify. Thank you very much for being there and joining us for the workshop.

So this is how the next three hours will look like. It will be a bit different from what we are used to, but I hope it's good different. So hopefully you can also share that feedback with us at the end of this, but we are going to have five different sessions by five different speakers. All of them are engineers here at Shopify. And all of these sessions will actually be talking about had problems that we've had to tackle with GraphQL here at Shopify. So we hopefully hope that that will shed some light and you're going to get some insight into how the teams were able to look at the problems and you know, the various methods they use to tackle the problem.

So each session or each talk will be 20 minutes long. And at the tail end of that, we are going to have a break, a short break, a 10 minute break, you know, and then after that we are going to have a one hour office hours, or a mail session, if you may wish. So if you do have questions, just keep on dropping them here on chat, we'll make sure we take note of them. And at the tail end of it during the last hour during the office hours, we are going answer your questions. But also if you have a very specific question to any of the sessions as they roll, they are pre recorded, but our speakers are here live, you can definitely get to ask your questions on chat, and they're going to take care of that. So I hope that is fine. Sounds fine and makes sense.

2. Introduction to Jonathan's Session

Short description:

Our first session is by Jonathan, a staff developer at Shopify, focusing on customer storefront applications. Jonathan is here to clarify any questions during the pre-recorded session. Let's get started!

So without much further ado, I think our very first session is by Jonathan. Jonathan is here. Jonathan, I don't know if you want to take just a moment say hi to you know the people who are joining us before we get to a session on? Hello, everyone. I'm Jonathan, as you will see in the talk I'm a staff developer here at Shopify, focusing on our customer storefront applications. So that's from a GraphQL standpoint, that's the storefront API, which is one of two of our public GraphQL APIs and welcome to be here.

Fantastic. Tell us one thing about you that you don't know probably let me make it much more closer home, what's your favorite or your current read or favorite blog or newsletter right now? Shopify's engineering blog. All right, thank you so much, Jonathan. So Jonathan is our first speaker, as I mentioned, all our sessions are pre-recorded but feel free to drop your questions as the session runs. Jonathan is actually here to just help clarify anything just in case we get to that. So let me see. I will share my screen here, share sound as well. All right, fantastic. Let me see. Give me a thumbs up, actually, if you're able to get the sound up here.

QnA

Watch more workshops on topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
React at Scale with Nx
React Summit 2023React Summit 2023
145 min
React at Scale with Nx
Top Content
Featured WorkshopFree
Isaac Mann
Isaac Mann
We're going to be using Nx and some its plugins to accelerate the development of this app.
Some of the things you'll learn:- Generating a pristine Nx workspace- Generating frontend React apps and backend APIs inside your workspace, with pre-configured proxies- Creating shared libs for re-using code- Generating new routed components with all the routes pre-configured by Nx and ready to go- How to organize code in a monorepo- Easily move libs around your folder structure- Creating Storybook stories and e2e Cypress tests for your components
Table of contents: - Lab 1 - Generate an empty workspace- Lab 2 - Generate a React app- Lab 3 - Executors- Lab 3.1 - Migrations- Lab 4 - Generate a component lib- Lab 5 - Generate a utility lib- Lab 6 - Generate a route lib- Lab 7 - Add an Express API- Lab 8 - Displaying a full game in the routed game-detail component- Lab 9 - Generate a type lib that the API and frontend can share- Lab 10 - Generate Storybook stories for the shared ui component- Lab 11 - E2E test the shared component
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
A Framework for Managing Technical Debt
TechLead Conference 2023TechLead Conference 2023
35 min
A Framework for Managing Technical Debt
Top Content
Let’s face it: technical debt is inevitable and rewriting your code every 6 months is not an option. Refactoring is a complex topic that doesn't have a one-size-fits-all solution. Frontend applications are particularly sensitive because of frequent requirements and user flows changes. New abstractions, updated patterns and cleaning up those old functions - it all sounds great on paper, but it often fails in practice: todos accumulate, tickets end up rotting in the backlog and legacy code crops up in every corner of your codebase. So a process of continuous refactoring is the only weapon you have against tech debt.In the past three years, I’ve been exploring different strategies and processes for refactoring code. In this talk I will describe the key components of a framework for tackling refactoring and I will share some of the learnings accumulated along the way. Hopefully, this will help you in your quest of improving the code quality of your codebases.

Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.
Principles for Scaling Frontend Application Development
React Summit 2023React Summit 2023
26 min
Principles for Scaling Frontend Application Development
Top Content
After spending over a decade at Google, and now as the CTO of Vercel, Malte Ubl is no stranger to being responsible for a team’s software infrastructure. However, being in charge of defining how people write software, and in turn, building the infrastructure that they’re using to write said software, presents significant challenges. This presentation by Malte Ubl will uncover the guiding principles to leading a large software infrastructure.
Building a Voice-Enabled AI Assistant With Javascript
JSNation 2023JSNation 2023
21 min
Building a Voice-Enabled AI Assistant With Javascript
Top Content
In this talk, we'll build our own Jarvis using Web APIs and langchain. There will be live coding.