Notes I wrote down for myself after having the same data-fetching debate across too many teams. How TanStack Query compares with RTK Query, URQL, Apollo and SWR, and when each one actually wins.
Every few years I land on a new codebase and run into the same conversation. Someone wants RTK Query because Redux is already in package.json. Someone else wants URQL or Apollo because the back end has a GraphQL endpoint. A third person suggests plain fetch inside useEffect to avoid adding a dependency.
I almost always end up pushing for TanStack Query. Not out of habit, and not because the other libraries are bad, but because most product front ends hit the same problems once they grow past a few screens.
tl;dr
Start with TanStack Query unless you're committed to Redux middleware driving
your data flows, or you're 100% GraphQL and genuinely need a normalised entity
cache.
That rule covers almost every React app I've worked on.1 The decision flow below is the short version I walk through in architecture reviews:
decision flow · 4 checks before defaulting
check
exception
default
1
Real-time collaborative or local-first sync?
yes →Sync engineConvex · Zero · Electric · Liveblocks
2
Committed to Redux listeners driving API flows?
yes →RTK Queryone Redux store · listeners & middleware
3
100% GraphQL and need a normalised cache?
yes →URQL (Graphcache) / Relaynormalised graph · fragment colocation
4
Read-only server app or tiny embed budget?
yes →Server loaders / SWRskip a full client cache
no to all four
TanStack Querydefault choice · pair with fetch, graphql-request, tRPC or OpenAPI codegen
01Real-time collaborative or local-first sync?
yes
Sync engineConvex · Zero · Electric · Liveblocks
no
02Committed to Redux listeners driving API flows?
yes
RTK Queryone Redux store · listeners & middleware
no
03100% GraphQL and need a normalised cache?
yes
URQL (Graphcache) / Relaynormalised graph · fragment colocation
no
04Read-only server app or tiny embed budget?
yes
Server loaders / SWRskip a full client cache
no
05TanStack Query
default choice · pair with fetch, graphql-request, tRPC or OpenAPI codegen
Most teams skip straight past all four gates. Being on GraphQL alone does not trigger gate 03; having a legacy Redux store does not trigger gate 02.
If you only need the summary table to paste into a tech spec, here it is:
comparison · 7 solutions · overview
strength / default
drawback
Solution
Cache model
Strengths & drawbacks
TanStack Querydefault
any promisestandalone
Document cache
hierarchical keys
+Strengths: Clean server/client split, best devtools, strong mutations and infinite queries, huge ecosystem
−Drawbacks: No built-in normalised cache; pairs with external codegen (orval, hey-api, tRPC)
RTK Query
any queryFnRedux Toolkit
Document cache
Redux store · tags
+Strengths: Zero extra library in Redux shops, unified Redux DevTools and listeners, built-in OpenAPI codegen
−Drawbacks: Pulls server state into Redux; boilerplate to split endpoints (injectEndpoints); no built-in Suspense hooks
−Drawbacks: Basic mutation story, clunky prefix invalidation, no official devtools
Relay
GraphQL speccompiler
Normalised store
compiler-backed
+Strengths: Best performance and consistency at huge scale; fragment masking; eliminates waterfalls
−Drawbacks: Steepest learning curve; compiler build step; requires strict back end schema compliance
fetch + useEffect
any0 kB
None
component state
+Strengths: Zero dependencies for a trivial one-off call
−Drawbacks: You end up re-inventing cancellation, deduplication, retries and caching with subtle race bugs
Use “copy markdown” in the header to paste the full five-column table straight into a tech spec or RFC.
Server state is not client state
Most of the friction in these debates comes from treating API responses like client state.
Client state is owned by the browser: whether a modal is open, which tab is active, what someone typed into a filter input. It's synchronous, local, and always up to date because your code is the only thing mutating it.
Server state is the opposite. It lives somewhere else, other users can change it while you look at it, and your copy in memory is stale the moment it arrives. What you need for it isn't a store: you need a cache with staleness rules, background refetches, deduplication, retries and garbage collection.
state boundary · 3 architectures
server cache
client state
coupled store
second path
TanStack Query
decoupled layers
client stateuseState · URL · Zustand
server cacheQueryClient (independent)REST · GraphQL · RPC · Promise
one mental model for every API
RTK Query
inside the Redux store
Redux store
UI slices + reducers
API slice + cache tags
Middleware & listeners
keeps you tied to Redux
URQL / Apollo
protocol-specific client
GraphQL cacheQueries & mutations
leaks outREST · auth · uploads · 3rd-party
needs a second fetching layer
Keeping server state outside your client store lets you swap transports or shrink UI state without rewriting every screen.
Once you separate the two, something nice happens in almost every React app I've touched: the client store shrinks to almost nothing. Half of what used to live in Redux disappears into query keys, another chunk moves into the URL, and the little that's left fits in useState or a tiny Zustand store.
RTK Query goes the other way. It pulls server caching into Redux. That makes sense if Redux listeners and middleware already orchestrate your app. Everywhere else, it keeps Redux alive in a codebase whose only real state problem was fetching data.
URQL and Apollo have a different boundary issue: they tie your caching layer to a single protocol. Even at companies that call themselves "GraphQL shops", I rarely see a real product that stays 100% GraphQL forever. Auth callbacks, file uploads, webhooks, billing widgets and third-party services sneak in as REST. Before long you have a GraphQL client for 80% of the app and ad-hoc fetch calls for the rest.
Document cache vs. normalised cache
The strongest technical case for Apollo, Relay or URQL with Graphcache is normalised caching, so it's worth being clear about what it actually buys you and what it costs.
In a document cache (TanStack Query, RTK Query, SWR, default URQL), each query stores the response it got back rather than splitting it into entities. When a mutation changes an item, you trigger a background refetch for affected queries — by key prefix in TanStack Query, cache tags in RTK Query, or __typename in default URQL — or update the cache optimistically if you want instant feedback.
In a normalised cache, the client flattens every response into a single table keyed by __typename and id, then replaces nested objects with pointers. If a mutation updates Issue:42 and returns its new title, every list and detail view pointing at Issue:42 updates immediately with no second network call.
Predictable keys, zero hidden graph state. Costs one extra request on write (or an optimistic update).
Normalised cache
Apollo Client · URQL Graphcache · Relay
ListQuery
refs -> Issue:42
DetailQuery
ref -> Issue:42
Issue:42
title: "Fix auth"
owner -> User:7
the catch
Field edits sync instantly across queries
List inserts, deletes, missing IDs and pagination still need hand-written cache updaters.
Normalised caches shine on dense, entity-heavy graphs. For most product UIs, invalidating a query key is simpler and fails far less often.
On paper, normalised caching sounds strictly better. In practice, it handles edits to existing records cleanly and gets awkward fast on everything else:
Creating an item: which filtered or sorted lists should the new record appear in? The cache can't guess, so you write a manual updater.
Deleting an item: you have to evict it and clean up dangling references or pagination edges.
Missing IDs: forget to select id on one nested field and records silently overwrite each other or stop updating.
Pagination: merging cursor or offset pages requires custom field policies that are easy to get subtly wrong.
By the time you've debugged your third stale-list bug in a normalised cache, invalidating ["issues"] and letting TanStack Query refetch in the background starts looking very attractive.2
How the options compare
No library wins every axis. Putting the five main options side by side across six dimensions makes the trade-offs obvious, including the two places where TanStack Query does not come first.
trade-offs · 6 dimensions · my scorecard (0–10)
TanStack Query
RTK Query
URQL
Apollo
SWR
Protocol flexibility
REST, GraphQL, RPC and mixed APIs
TanStackany promise
SWRany promise
RTK Queryany queryFn
URQLGraphQL only
ApolloGraphQL only
State independence
Usable without adopting a client store
TanStackstandalone
SWRstandalone
URQLstandalone
Apolloown store
RTK Queryneeds Redux
Mutation ergonomics
Optimistic updates, rollbacks & invalidation
TanStackkeys + rollbacks
RTK Querytag invalidation
URQLtypename / cache
Apollocache + refetch
SWRbasic mutation
DevTools & debugging
Inspecting fresh, stale and inactive entries
TanStackin-app panel
RTK QueryRedux DevTools
Apollobrowser ext
URQLbrowser ext
SWRnone official
Normalised caching
Automatic cross-query entity updates
Apollodefault
URQLGraphcache
TanStackmanual only
RTK Querymanual only
SWRmanual only
Bundle lightness
Bundlephobia min+gzip core footprint
SWR~6 kB
URQL~12 kB*
TanStack~13 kB
RTK Query+RTK core
Apollo~39 kB
My own 0–10 scores for typical React product apps, not a benchmark — take them with a pinch of salt. Bundle sizes are Bundlephobia min+gzip estimates (Nov 2026); *URQL adds ~12 kB with Graphcache, and RTK Query rides on top of Redux Toolkit.
Two things stand out whenever I look at that chart:
TanStack Query has no glaring weak spot for everyday product work. It's not the smallest bundle (SWR is), and it doesn't normalise a GraphQL graph automatically (Apollo and URQL Graphcache do). Everywhere else (protocol flexibility, state independence, mutations, devtools) it's at or near the top.
The tools people compare it against are specialists. RTK Query is a Redux specialist. URQL and Apollo are GraphQL specialists. SWR is a minimal read-first specialist. Specialists are great when your whole app fits their niche, and painful the day it stops fitting.
One pattern across REST and GraphQL
One thing that wins over sceptical teammates faster than slides is showing how little code it takes. With queryOptions, you define a query key and fetcher once, get full TypeScript inference everywhere (useQuery, prefetchQuery, getQueryData), and the fetcher can be REST, GraphQL, tRPC or anything else that returns a promise:
queries / issues.ts
import { queryOptions } from "@tanstack/react-query";import { gql, request } from "graphql-request";interface Issue { id: string; title: string;}export const issueKeys = { all: ["issues"] as const, detail: (id: string) => ["issues", id] as const,};// REST endpointexport const issueListQuery = (status: "open" | "closed") => queryOptions({ queryKey: [...issueKeys.all, { status }], queryFn: async ({ signal }): Promise<Issue[]> => { const res = await fetch(`/api/issues?status=${status}`, { signal }); if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); }, });// GraphQL endpoint, same cache and devtoolsexport const issueDetailQuery = (id: string) => queryOptions({ queryKey: issueKeys.detail(id), queryFn: async ({ signal }): Promise<Issue> => { const data = await request<{ issue: Issue }>({ url: "/graphql", document: gql` query ($id: ID!) { issue(id: $id) { id title } } `, variables: { id }, signal, }); return data.issue; }, });
typescript45 lineslines 15–23, 26–45
Both queries share the same cache, the same invalidation prefix (issueKeys.all), the same retry rules and the same devtools panel. If a team migrates an endpoint from REST to GraphQL (or back again), the components calling useQuery(issueDetailQuery(id)) don't change at all.
The pushbacks I keep hearing
These are the four objections that come up in almost every meeting, and the short answers I give now.
"We already have Redux, so RTK Query is free"
Having Redux in the repo is usually historical: teams put API responses in Redux years ago because there was nothing better. If your new features don't need Redux middleware or cross-slice listeners reacting to API actions, adopting RTK Query locks you into Redux for another three years instead of letting you retire it gradually.
If you want OpenAPI code generation, TanStack Query pairs cleanly with @hey-api/openapi-ts and orval, and tRPC's React client wraps TanStack Query directly. You don't need RTK Query just to get generated hooks.
"Our back end is GraphQL, so we should use URQL or Apollo"
Being on GraphQL doesn't automatically mean you need a GraphQL client. graphql-request (with GraphQL Codegen for typed documents) plus TanStack Query covers 90% of GraphQL apps with one simple cache model.
Only reach for URQL or Apollo when you can point to a concrete feature you actually need: normalised cross-query updates via Graphcache, fragment colocation across a big team, or an exchange pipeline for offline queues and persisted queries.
"SWR is smaller and simpler"
At install time, yes: SWR is around 6 kB gzipped versus roughly 13 kB for TanStack Query. In a real app, that gap disappears the week you start writing wrappers around useSWRMutation, manual prefix invalidation helpers, and console.log statements because there are no official devtools.
"We can just use fetch and useEffect"
For one static JSON file on a marketing page, sure. The moment two components need the same data, or a user clicks between tabs quickly and triggers out-of-order responses, you're quietly building a worse version of TanStack Query by hand: AbortController cleanup, in-flight deduplication, retry backoff, window-focus refresh and stale-while-revalidate state. There's no prize for maintaining that yourself.
When I wouldn't pick TanStack Query
An argument that says "use my favourite tool everywhere" is easy to dismiss, and it would also be wrong. There are four situations where I'd pick something else without fighting it:
Deeply invested Redux teams. If Redux listeners, sagas or middleware genuinely drive your business logic and everyone on the team already thinks in Redux, RTK Query keeps everything in one place.
100% GraphQL with dense, interconnected entity views. Think Linear-like issue trackers or social graphs where editing one record must immediately update six unrelated widgets on screen without refetching. Here, URQL with Graphcache or Relay earns its complexity.
Real-time collaborative or local-first apps. If the product is built around live multiplayer state or offline-first writes, a request/response cache is the wrong abstraction. Reach for a sync engine like Convex, Zero, Electric or Liveblocks.
Server-rendered read-heavy apps or tiny embeds. If React Server Components or route loaders handle nearly all reads and there's little client-side mutation state, or you're shipping a tiny third-party script under a hard kilobyte cap, skip the client query cache altogether.
Why I keep coming back to it
Outside those four cases, TanStack Query is the safest long-term bet I know in the React ecosystem.
It stays out of your client state, works with whatever back end your company has today or migrates to next year, gives new hires a mental model they probably already know, and ships devtools that turn "why is this stale?" from a twenty-minute hunt into a five-second glance.
Next time this comes up at work, I'm just sending the link to this page.