---
title: "Rate Limiting GraphQL APIs by Calculating Query Complexity"
description: "Shopify's GraphQL Admin API rate-limits by calculated query cost instead of request count: clients get 50 points per second up to a 1,000-point bucket, and each query is priced by static analysis before execution."
url: "https://swe.quest/articles/rate-limiting-graphql-apis-by-calculating-query-complexity-58ede655d49d3a42"
canonical: "https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity"
source: "Shopify Engineering"
published: "2021-06-22"
difficulty: "medium"
kind: "Case study"
reading_minutes: 6
tags: ["graphql","api-design","resilience"]
---

# Rate Limiting GraphQL APIs by Calculating Query Complexity

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2021-06-22, 6 min read, Case study. Original: [https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity](https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity)

## Summary

Shopify's GraphQL Admin API rate-limits by calculated query cost instead of request count: clients get 50 points per second up to a 1,000-point bucket, and each query is priced by static analysis before execution. Objects, interfaces and unions cost 1 point, and scalars and enums are free. Connections cost 2 plus the number of requested objects, and mutations cost 10 to reflect side effects. Responses report requested and actual cost in an extensions object, and any unused requested cost is refunded. Shopify found calculated cost correlates linearly with execution time, which makes server load predictable and rewards clients for requesting only the data they need.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [GraphQL](https://swe.quest/tags/graphql.md) (Backend & APIs)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)

## Prerequisites

- GraphQL queries and mutations ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))
- Relay-style connections
- token bucket rate limiting

## Keywords

Shopify Admin API, GraphQL, Relay connections, GraphiQL

## Related posts

- [Shopify’s journey to faster breadth-first GraphQL execution](https://swe.quest/articles/shopify-s-journey-to-faster-breadth-first-graphql-execution-83f0f58b8c4dabd1.md): Shopify Engineering · 2026-03-12 · Hard · 14 min read · GraphQL, Performance engineering, Ruby, Query engines
  Shopify built GraphQL Cardinal, a breadth-first GraphQL execution engine that calls each field resolver once with the full set of objects at that level instead of once per object.
- [Querying Strategies for GraphQL Clients](https://swe.quest/articles/querying-strategies-for-graphql-clients-25fcea5a0897f025.md): Shopify Engineering · 2021-06-15 · Medium · 8 min read · GraphQL, Mobile, Web performance, Frontend
  GraphQL client queries tend to grow slower and harder to roll out as features accumulate, and Shopify's Orders & Fulfillments web and mobile teams work through a progression of strategies against a sub-one-second mobile page load goal.
- [What today's software owes to Bronze Age clocks](https://swe.quest/articles/what-today-s-software-owes-to-bronze-age-clocks-f1c84fb59510a8bf.md): PlanetScale · 2026-10-07 · Medium · 8 min read · Resilience, PostgreSQL, API design, Algorithms
  Leaky buckets, descended from Bronze Age water clocks, remain a cheap admission-control mechanism: a bucket stores only its last level and timestamp, so its current level can be computed lazily as max(0, level\_then − drain\_rate × elapsed).
- [pg\_graphql: A GraphQL extension for PostgreSQL](https://swe.quest/articles/pg-graphql-a-graphql-extension-for-postgresql-3a34efbe6d730fc2.md): Supabase · 2021-12-03 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql is an open-source PostgreSQL extension, written in C and SQL, that reflects a GraphQL schema from existing tables and resolves queries entirely inside the database.
- [10 Tips for Building Resilient Payment Systems](https://swe.quest/articles/10-tips-for-building-resilient-payment-systems-94c9ade99576742c.md): Shopify Engineering · 2022-07-28 · Medium · 13 min read · Payments & fintech, Resilience, Observability, Incidents & postmortems, Ruby
  Ten lessons from Shopify's payment infrastructure for keeping payment systems reliable at scale.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
