GraphQL vs REST vs tRPC: API Design for Commerce Frontends
Teams argue about GraphQL, REST, and tRPC as if one must win everywhere. In commerce the right answer changes depending on who calls the API, how it is cached, and whether you control both ends. Here is a practical way to pick, layer by layer.
Ask three engineers how to design the API for a commerce storefront and you will get GraphQL, REST, and tRPC, each delivered with the confidence of a religious conviction. All three are right in the right place, and all three cause pain in the wrong one. The mistake is treating this as a single decision for the whole system.
A commerce frontend does not talk to one API. It talks to a commerce platform's API, to a CMS, to a search provider, to payment and tax services, and to your own backend. Some of those you control, some you do not, and some are exposed to the public. The GraphQL vs REST vs tRPC question has a different best answer for each boundary. This guide maps the tradeoffs and gives you a framework for choosing.
Start With the Boundary, Not the Technology
Before comparing protocols, classify each API by two questions. First, who calls it: your own frontend only, or third parties, partners, and mobile apps you do not ship? Second, who owns both ends: can you change client and server together in one deployment, or is one side outside your control?
Those two answers eliminate most of the debate. A public API consumed by unknown clients needs stability, documentation, and cache friendliness. An internal API between your own storefront and your own backend can trade those for speed of development and type safety. And an API you merely consume, like a commerce platform's, is chosen for you.
REST: Boring, Cacheable, Universal
REST maps resources to URLs and uses HTTP verbs and status codes the way the web was designed. Its biggest strength in commerce is that the entire HTTP caching ecosystem understands it. A GET for a product at a stable URL can be cached by browsers, CDNs, and reverse proxies using standard Cache-Control headers, validated with ETags, and purged by URL or surrogate key.
That matters enormously for catalog traffic, where the same product and collection responses are requested by thousands of shoppers. REST also has the lowest barrier for third parties: every language, every tool, and every partner integration knows how to call it.
The weaknesses are the familiar ones. Fixed response shapes cause over fetching (the product list returns fields the card never shows) and under fetching (the page needs three endpoints instead of one). Versioning becomes a long term chore. Without a schema discipline such as OpenAPI, documentation and contracts drift.
Choose REST when you are exposing a public or partner API, when responses are highly cacheable at the CDN, when you need broad compatibility, or when webhooks and simple integrations dominate.
GraphQL: Flexible Reads, Careful Operations
GraphQL lets the client ask for exactly the fields it needs in one round trip, against a strongly typed schema. For a product page that needs title, images, variants, price, inventory, and metafields, that single query replaces several REST calls, and the frontend team can change what it asks for without waiting on a backend release.
The tradeoffs show up in operations, and commerce teams feel them in three places.
Caching. Queries typically travel as POST requests to a single endpoint, which most CDNs do not cache by default. You can recover caching with persisted queries sent as GET requests, response caching at the gateway, or by caching at the framework data layer. It is workable, but you have to build it. Our write up on edge caching for personalized storefronts shows how cache keys and vary rules behave once personalization enters the picture, and it applies directly here.
Cost control. Flexible queries mean a client can ask for something expensive. Public GraphQL endpoints need depth limits, complexity scoring, rate limits, and allow lists of persisted queries. Without them, one careless query can hurt your origin.
N plus one behavior. A naive resolver layer can fan out into many backend calls. DataLoader style batching and thoughtful resolver design are required, not optional.
Choose GraphQL when many different clients (web, mobile, kiosks, agents) need different slices of the same data, when your frontend team iterates faster than your backend can, or when you are federating multiple backends behind one schema. For that last case, see how Apollo Federation, Hasura, and WunderGraph compare as commerce API gateways.
tRPC: Type Safety When You Own Both Ends
tRPC is different in kind. It is not a protocol you publish; it is a way to call server functions from a TypeScript client with types inferred end to end. You define procedures on the server, and the client gets autocomplete and compile time errors with no schema file and no code generation step.
For an internal API between a Next.js storefront and a TypeScript backend in the same repository, the developer experience is excellent. Refactor a field on the server and the compiler tells you every place the frontend breaks. There is almost no ceremony.
The limits are structural. tRPC assumes TypeScript on both sides, so it does not suit native mobile clients, partners, or other languages. It is not designed as a public API contract, and the transport is not built around HTTP cache semantics the way REST is, although queries can use GET and be cached with some effort. If your client and server ever need to deploy independently with long lived clients in the wild, the lack of a versioned contract hurts.
Choose tRPC when the frontend and backend live in one TypeScript codebase, the API is strictly internal, and development speed and refactor safety outrank everything else. It shines for admin tools, internal dashboards, and the private API behind a storefront.
Third Party Platform APIs Are Mostly Decided for You
Most commerce frontends are built on top of a platform whose API you cannot change. Shopify's Storefront API is GraphQL. Platforms like commercetools offer both GraphQL and REST. Others are REST first. The practical effect is that your public facing choice is often a choice about the layer you build on top.
Two rules help. First, do not leak a platform's schema through your whole application. If every component imports platform specific query fragments, replatforming or even a version bump becomes a rewrite. Second, expect platform API versioning to force periodic updates, so isolate the calls behind a thin data access layer you can adapt in one place. Our overview of Shopify Hydrogen vs Next.js Commerce touches on how much of that coupling each framework encourages.
The Backend for Frontend Layer Is Where This Resolves
The pattern that settles most of these arguments is a backend for frontend, often shortened to BFF. It is a server layer owned by the frontend team that sits between the storefront and every upstream system.
The BFF lets you use the right tool at each boundary. Upstream, you consume whatever the platforms give you: GraphQL from the commerce platform, REST from the tax service, a search SDK from the search provider. Downstream, you expose one shaped API to your own frontend, tuned to the screens you actually render. That downstream API can be tRPC if everything is TypeScript, REST if you need CDN friendly endpoints, or GraphQL if multiple clients need flexible reads.
A BFF also gives you one place for caching policy, authentication, rate limiting, error normalization, and secret handling, so tokens for third party services never reach the browser. The cost is another service to run, so keep it thin: shape and aggregate, do not reimplement business rules that belong in the platform.
The Decision Framework
| Situation | Best fit | Reason |
|---|---|---|
| Public or partner API | REST | Universal clients, HTTP caching, stable contracts |
| Highly cacheable catalog reads at the CDN | REST, or GraphQL with persisted GET queries | Cache hit rate drives cost and speed |
| Multiple client types needing different data shapes | GraphQL | Client driven selection, one schema |
| Federating several backends | GraphQL with a gateway | Single graph over many services |
| Internal API, one TypeScript monorepo | tRPC | End to end types, minimal ceremony |
| Consuming a platform API you do not control | Whatever it offers, wrapped in a BFF | Isolate vendor coupling |
| Mutations such as cart and checkout | REST or typed RPC | Explicit, uncached, easy to audit |
| Webhooks and system to system events | REST | Simple, universally supported |
A defensible default for a new headless storefront: consume platform APIs behind a BFF, use tRPC or plain server functions between your frontend and BFF if you are all TypeScript, and expose REST for anything public or CDN cached. Reach for GraphQL as your own API when client diversity or federation justifies the operational weight.
What This Means for Your Business
API design looks like an engineering preference, but it shows up on the P&L. Cacheability determines how much origin capacity you pay for at peak. Over fetching slows pages, and slower pages convert worse. Weak contracts create integration breakage with partners and marketplaces. And tight coupling to one platform's schema turns a future replatform from a project into a rewrite.
The teams that avoid these costs are not the ones who picked the trendiest protocol. They drew clear boundaries, put a thin layer between their frontend and every vendor, and matched each interface to its audience.
How Contra Collective Bridges the Gap
We design the data layer behind headless storefronts, including BFF architecture, caching strategy, and API boundaries that survive platform changes, and we are happy to say plainly when plain REST is the better answer than a fashionable one. If you are untangling an API layer or planning a new build, talk to our team.
Final Thoughts
GraphQL, REST, and tRPC are tools for different boundaries, not rivals for one crown. REST wins where caching and public access matter, GraphQL wins where many clients need flexible reads over a federated backend, and tRPC wins where you own both ends in TypeScript. Put a backend for frontend between your storefront and the outside world, and you can use each where it is strongest.
More from the lab.
Bun vs Node.js: Runtime Decisions for Production Storefronts
Bun is fast, pleasant, and increasingly capable, but a production storefront runtime is a risk decision, not a speed contest. The smartest teams adopt Bun in layers, starting with tooling and moving to production only when the evidence supports it. Here is a practical way to decide.
Turborepo vs Nx: Monorepo Tooling for Storefront Teams
Turborepo and Nx both promise faster builds and saner monorepos, but they push you toward different working styles. For storefront teams sharing a design system across several brands, the choice shapes CI time and governance for years. Here is how to pick.
Commercetools vs. Shopify Plus: The Case for Pure Headless Commerce
When enterprise teams choose between commercetools and Shopify Plus, they're really choosing between two fundamentally different philosophies about ownership, flexibility, and velocity. Here's the unvarnished technical breakdown.