Home/Blog/software engineering
Back to all articles
software engineering#GraphQL#REST API#tRPC

GraphQL vs REST vs tRPC: Modern API Architecture & Performance Comparison

RB
Rajput BhavinArchitect
Founder, Rajput Bhavin Engineering
24 August 2026•10 min read

Quick Answer: GraphQL vs REST vs tRPC#

⚡ Quick Answer / Executive Summary
The decision between REST, GraphQL, and tRPC depends on client diversity, network bandwidth, and team structure. REST remains the gold standard for public-facing third-party APIs and microservice boundaries due to universal HTTP edge caching. GraphQL excels for complex mobile applications with deeply nested entity graphs, while tRPC is the optimal choice for full-stack TypeScript monoliths (Next.js/React), offering 100% end-to-end type safety with zero code generation overhead.

Technical Comparison Matrix#

Architectural FeatureREST (OpenAPI)GraphQLtRPC (TypeScript)gRPC (Protocol Buffers)
Data Fetching PatternFixed endpoints (/users, /orders)Single endpoint (/graphql) with query shapeRemote procedure calls (trpc.user.get)Binary RPC over HTTP/2
Over/Under-FetchingCommon without specialized query filtersZero — Client requests exact fieldsZero — Inferred from return typesControlled by Protobuf definitions
HTTP Edge CachingExceptional (native CDN & browser cache)Difficult (all queries POSTed to single endpoint)Moderate (via React Query query keys)Not applicable (binary protocol)
N+1 Query ProblemManaged at service layerRequires DataLoader / Batching layersHandled in service layerHandled in service layer
Client Type SafetyRequires OpenAPI code-gen toolsRequires GraphQL Code GeneratorNative & Instant (Compile-time)Compiled from .proto files
Best Used ForPublic APIs, microservices, webhook gatewaysMulti-platform mobile apps (iOS, Android, Web)Full-stack Next.js / React TypeScript SaaSHigh-frequency internal microservices

1. When to Choose REST#

REST remains the standard for web interoperability:

#Major Strengths:

  • ✦Global CDN Caching: Native support for HTTP caching headers (Cache-Control, ETag, Last-Modified) allows edge servers (Cloudflare, Fastly) to serve millions of requests without hitting your origin database.
  • ✦Universal Ecosystem Compatibility: Every programming language, webhook provider, and API gateway understands standard HTTP status codes (200 OK, 201 Created, 404 Not Found, 429 Rate Limited).
  • ✦Simpler Security: Granular endpoint-level rate limiting and firewall rules (WAF) are straightforward to implement compared to analyzing complex recursive GraphQL query depths.

2. When to Choose GraphQL#

GraphQL was engineered by Facebook to solve the over-fetching problem on cellular networks:

#Major Strengths:

  • ✦Declarative Client Queries: A mobile app can fetch a user profile, their 5 most recent orders, and pending shipping notifications in a single round-trip HTTP request:
GraphQL Schema
Production Code
query GetUserDashboard($userId: ID!) {
  user(id: $userId) {
    id
    name
    recentOrders(limit: 5) {
      id
      totalAmount
      status
    }
    unreadNotificationsCount
  }
}

#Critical Pitfall: The N+1 Database Problem

If not engineered carefully, GraphQL resolvers will execute 1 query to fetch the user and N additional queries to fetch related orders. We implement **DataLoader** batching to collapse multiple requests into a single SQL `WHERE id IN (...)` query.

3. The Modern Modern Alternative: tRPC for Full-Stack TypeScript#

For teams building SaaS products with Next.js and React, tRPC has largely replaced GraphQL:

TypeScript
Production Code
// Backend (tRPC Router)
export const appRouter = router({
  getUserOrders: protectedProcedure
    .input(z.object({ userId: z.string().uuid() }))
    .query(async ({ input, ctx }) => {
      return await ctx.db.orders.findMany({ where: { userId: input.userId } });
    }),
});

// Frontend (React Component)
// TypeScript automatically knows the exact shape of `data` with autocompletion!
function OrdersList({ userId }: { userId: string }) {
  const { data: orders, isLoading } = trpc.getUserOrders.useQuery({ userId });

  if (isLoading) return <Skeleton />;
  return <div>{orders?.map(o => <div key={o.id}>{o.totalAmount}</div>)}</div>;
}

Selecting the Right API Protocol with Rajput Bhavin Engineering#

At Rajput Bhavin Engineering, we select API protocols based on real-world engineering constraints rather than hype:

  • ✦Public & Partner APIs: OpenAPI 3.1 REST with strict rate limiting.
  • ✦Internal Full-Stack SaaS: Next.js 15 Server Actions or tRPC for rapid type safety.
  • ✦High-Throughput Microservices: gRPC with Protocol Buffers for sub-millisecond serialization.

Build High-Performance APIs with Rajput Bhavin Engineering#

Architect scalable, type-safe API infrastructure with systems architect Rajput Bhavin.

Software Engineering Consultation

Need help architecting your modern software stack?

Rajput Bhavin Engineering provides hands-on systems architecture, codebase reviews, and custom cloud software development for technology teams in India and worldwide.

RB

Rajput Bhavin

Systems Architect

Founder and Systems Architect at Rajput Bhavin Engineering in Gota, Ahmedabad. Specializes in high-concurrency cloud software, Next.js web applications, multi-tenant SaaS architecture, and autonomous AI systems.

Connect Now