βΆGraphQL vs REST vs tRPC in 2026 β which should I use?
REST: mature, stateless, caching works out-of-the-box with HTTP. Good for simple CRUD. GraphQL: type-safe, exact data shape, solves overfetching at the cost of query complexity. Best for complex domains (e-commerce, social) where clients need varied data shapes. tRPC: RPC with TypeScript inference, zero-overhead, full end-to-end type safety. Emerging trend for monoliths; not suitable for multi-client ecosystems. For B2C startups: GraphQL (SEO-friendly, client control). For internal tools: tRPC. For massive public APIs: REST.
βΆFederation vs schema stitching β what's the difference?
Schema stitching: old pattern, manually merge schema strings, fragile, requires delegation logic. Federation (Apollo): subgraphs declare entities, @key directives link them, managed at gateway level, type-safe. Federation is the 2026 standard for large orgs. Stitching is legacy; don't start new projects with it.
βΆWhat is the N+1 problem in GraphQL and how do I fix it?
N+1: resolving 10 users triggers 10 separate DB queries for posts (1 for users + N for posts). Solution 1: DataLoader batches requests (collects all IDs, fetches once, caches). Solution 2: eager loading in the root resolver. Solution 3: push the join into the query (SQL subqueries, Prisma include). Apollo Server integrates DataLoader seamlessly; it's the default tool. Without it, GraphQL can be slower than REST on chatty databases.
βΆHow should I cache GraphQL queries on the client?
Apollo Client: normalized cache (entities by ID), automatic deduplication, cache-first/network-only policies per operation. Relay: similar normalized cache, strict conventions. For JSON response caching: set Cache-Control headers on the HTTP response (Apollo Server does this via plugins). Query-level caching: Apollo's built-in policies (cache-first, network-only, no-cache). Server-side: HTTP caching, CDN (Automatic Persisted Queries), Redis for computed fields. Most teams cache at the HTTP layer, not query layer.
βΆSecurity: query complexity attacks, depth limiting, rate limiting β what do I need?
Depth limiting: reject queries deeper than N levels (prevent nested loops). Complexity scoring: assign cost per field (scalar=1, list=Γ10), reject if total >threshold. Rate limiting: per IP or per user. Timeout: long-running queries kill servers. Cost-aware planning: Shopify's algorithm calculates cost before execution. Start with depth limit (max 10) + complexity analysis + APQ (persisted queries) to restrict to approved ops. Credentials: never expose schema introspection in production. Use authenticated endpoints only.
βΆIs GraphQL declining in 2026?
No, but hype-cycle wisdom applies: REST didn't die, REST + GraphQL coexist. GraphQL dominates for web/mobile clients (Shopify, GitHub, Discord). Microservices discovered Federation solves real problems. REST remains default for simple CRUD and ecosystem tooling. tRPC is capturing monolith mindshare (simpler, less ceremony). For new projects: GraphQL if you have complex client patterns, Federation if multi-team. Single-service startups often skip GraphQL (REST + tRPC faster to market).
βΆHow do I handle real-time updates β WebSockets vs polling?
Polling: client asks every N sec, wasteful but simple, works anywhere. WebSockets: persistent connection, server pushes updates, low latency. GraphQL Subscriptions use WebSockets (server sends field updates). Apollo Server supports subscriptions out-of-the-box. For real-time: subscriptions. For occasional updates: polling is fine. For chat/gaming: subscriptions essential. Scaling WebSockets is hard (sticky sessions, PubSub backend). Most teams use third-party (Supabase real-time, Firebase, Socket.io) rather than DIY GraphQL subscriptions.
βΆWhen should I use code generation (GraphQL Code Generator) vs manual types?
Always use code generation. GraphQL Code Generator watches your schema and operations, generates TypeScript types for queries/mutations/subscriptions. Eliminates mismatch (schema changes, types don't). Pro: queries are type-safe end-to-end, autocomplete on response data. Apollo Client has built-in @graphql-codegen plugin. Takes 5 minutes to set up. If you're writing types by hand, you're doing it wrong.