Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Courses›REST API Design›REST vs GraphQL vs gRPC

Interview Prep

REST vs GraphQL vs gRPC

This guide evaluates the architectural paradigms of REST, GraphQL, and gRPC to help you select the right protocol for specific integration needs. Understanding these communication styles allows you to balance performance, strict typing, and developer ergonomics effectively in distributed systems. You will learn to weigh the flexibility of query-based data retrieval against the structural rigor of remote procedure calls and the ubiquity of resource-based web services.

REST: The Resource-Centric Foundation

Representational State Transfer (REST) operates on the principle that the web is a collection of resources, each identified by a unique URI. By utilizing standard HTTP methods like GET, POST, PUT, and DELETE, REST enforces a predictable interface that caches easily and leverages browser infrastructure. The core strength of REST lies in its statelessness and uniform interface, which decouple the client from the server implementation. When designing a public API intended for a wide variety of consumers, REST remains the gold standard because its constraints are universally understood. The lack of strict coupling allows individual components to evolve independently, provided the resource representation remains consistent. However, REST can lead to over-fetching or under-fetching issues, where the client receives excessive data or must make multiple sequential requests to gather related information, leading to high latency in complex applications. Mastery of REST is essential for building scalable, interoperable systems.

// Simple RESTful GET endpoint to fetch a user resource
// The URI represents the resource, while the method defines the action
GET /api/v1/users/123 HTTP/1.1
Host: example.com
Accept: application/json
// Server response: 200 OK with user object body

GraphQL: Precision Through Querying

GraphQL addresses the inefficiencies of REST by shifting the responsibility of data selection from the server to the client. Instead of multiple fixed endpoints, GraphQL exposes a single endpoint that accepts complex queries, allowing the client to specify exactly which fields it requires. This eliminates the 'over-fetching' problem entirely, as the server resolves only the requested data, optimizing network payload size and latency. The underlying schema acts as a strongly typed contract, providing excellent developer tooling and self-documentation. When your application architecture features deeply nested relationships—such as fetching a user, their recent posts, and the comments on those posts in one go—GraphQL excels by collapsing these into a single round trip. The trade-off is increased server-side complexity, as you must implement resolvers that handle efficient data fetching from underlying databases or microservices, often requiring DataLoader patterns to prevent N+1 performance issues.

query GetUserWithPosts($id: ID!) {
  user(id: $id) {
    name
    posts { # Client asks specifically for user name and their posts
      title
      content
    }
  }
}

gRPC: High-Performance RPC Communication

gRPC shifts the paradigm from resource manipulation to remote procedure execution, utilizing binary serialization to maximize network efficiency. By default, gRPC uses a specific format that defines service methods and message structures in a language-agnostic interface definition file. This binary approach makes it significantly faster than the text-heavy formats used in REST or GraphQL. Because gRPC relies on persistent connections, it is ideally suited for microservices communication, real-time streaming, and scenarios where low latency is critical. Unlike REST, which relies on standard browser protocols, gRPC assumes full control over the connection, enabling advanced features like bidirectional streaming and multiplexing. While it is less suitable for public-facing browser clients without a proxy, its strict type safety and high-throughput capabilities make it the superior choice for internal service-to-service orchestration where performance bottlenecks must be avoided at all costs during high-load periods.

service UserService {
  // Defines a strict procedural call structure
  rpc GetUserDetail(UserRequest) returns (UserResponse) {}
}
message UserRequest { string id = 1; }
message UserResponse { string name = 1; int32 age = 2; }

Comparing Architectural Trade-offs

Choosing between these protocols requires an honest assessment of your team's constraints and the application's lifecycle requirements. REST is unbeatable for public APIs where ease of integration and standard caching behaviors are paramount. GraphQL shines in front-end heavy applications where the UI needs to aggregate diverse data sources without cluttering the backend with custom 'view-model' endpoints. gRPC is the tactical weapon for high-scale backend systems, where the overhead of JSON parsing and HTTP/1.1 header negotiation creates unacceptable latency. You must evaluate the cost of implementation: gRPC requires managing protocol files and build-time code generation, whereas REST is often easier to spin up for small tasks. Always prioritize the protocol that fits the frequency of communication and the complexity of the data graph. Remember that these are not mutually exclusive; modern systems often employ a hybrid strategy, using REST for public access and gRPC for high-speed internal service connectivity.

// A conceptual comparison of network headers
// REST uses plain text headers, gRPC uses compressed binary frames
// REST: GET /users/1 HTTP/1.1
// gRPC: [binary_header_frame][binary_data_frame]

Selecting the Right Strategy

When you reach the design phase of a new feature, start by identifying the consumer. If you are building a public interface, stick to REST for its maturity and ease of use. If you are building an internal platform with many consuming microservices, move towards gRPC to minimize infrastructure costs and maximize throughput. If you are building a complex client-side application with dynamic, interlinked data requirements, GraphQL provides the agility required to iterate on features quickly without needing constant backend changes to endpoints. Your design process should revolve around the 'cost of change.' REST is easy to change but can be brittle due to lack of strict contracts. GraphQL and gRPC provide structural integrity through schema definition, making them safer for long-term maintenance in large-scale systems. Ultimately, evaluate whether you need a uniform web resource interface, a precise data query mechanism, or a raw high-performance execution tunnel.

// Decision matrix logic snippet
const protocol = (usageType) => {
  if (usageType === 'PUBLIC') return 'REST';
  if (usageType === 'INTERNAL_BACKEND') return 'gRPC';
  return 'GraphQL'; // For complex UI/data aggregation
};

Key points

  • REST uses standard HTTP methods to interact with resource URIs, making it the most portable and cache-friendly protocol.
  • GraphQL allows clients to request exactly the data they need, reducing over-fetching and minimizing unnecessary network traffic.
  • gRPC leverages binary serialization for extremely fast, low-latency communication between services in internal architectures.
  • REST is best suited for public-facing APIs where ease of discovery and standard browser compatibility are mandatory requirements.
  • GraphQL is the optimal choice when the frontend needs to aggregate multiple data sources with complex nested relationships.
  • gRPC provides strict type safety through interface definition files, which simplifies contract-based development in distributed systems.
  • The choice between protocols depends on whether the priority is ease of integration, frontend data flexibility, or backend performance.
  • Modern distributed systems often use a multi-protocol approach, deploying different tools based on the specific requirements of each service.

Common mistakes

  • Mistake: Choosing GraphQL for every project regardless of scale. Why it's wrong: GraphQL adds significant complexity and caching overhead that isn't needed for simple CRUD operations. Fix: Use REST when your data model is standard and predictable.
  • Mistake: Attempting to treat gRPC like a REST API. Why it's wrong: gRPC uses HTTP/2 and Protobufs, making it unsuitable for public-facing web browsers or standard proxy caches. Fix: Use gRPC for internal service-to-service communication only.
  • Mistake: Over-fetching data in REST to avoid multiple round-trips. Why it's wrong: This bloats payloads and wastes bandwidth. Fix: Use partial responses (sparse fieldsets) or dedicated resource endpoints.
  • Mistake: Misunderstanding GraphQL caching. Why it's wrong: GraphQL uses POST for almost everything, breaking standard HTTP cache mechanisms. Fix: Accept that GraphQL requires client-side caching (like normalized stores) instead of relying on CDN-level HTTP caching.
  • Mistake: Implementing gRPC without considering load balancing requirements. Why it's wrong: Because gRPC is persistent, standard L4 load balancers don't distribute requests effectively. Fix: Use an L7 proxy or client-side load balancing.

Interview questions

What is the core philosophy behind REST, and how does it leverage HTTP?

REST, or Representational State Transfer, is an architectural style that treats everything as a resource identified by a unique URI. The philosophy relies heavily on leveraging standard HTTP methods—GET, POST, PUT, DELETE—to perform actions. Because REST maps perfectly to HTTP verbs, it provides a stateless, uniform interface. This is crucial because it allows intermediate components like proxies and caches to understand the traffic, improving scalability and enabling clients to interact with resources without knowing the internal server implementation details.

Compare the data fetching mechanisms of REST and GraphQL. When would you prefer one over the other?

REST typically uses fixed endpoints like '/users/1' which return a predetermined structure, often leading to over-fetching or under-fetching of data. GraphQL, however, allows clients to request exactly what they need in a single round trip via a query language. You would prefer REST for simpler APIs where caching at the HTTP layer is critical, whereas GraphQL is superior in complex systems where you want to minimize network overhead and allow clients to aggregate data from multiple entities in one request.

Why would an engineer choose gRPC over REST for service-to-service communication?

Engineers choose gRPC for internal microservices because it uses Protocol Buffers instead of JSON, resulting in much smaller payloads and faster serialization. While REST uses human-readable text over HTTP/1.1, gRPC runs on HTTP/2, which supports multiplexing, meaning multiple requests can be sent over a single connection simultaneously. Furthermore, gRPC generates strongly-typed client code, which catches errors at compile time rather than runtime, significantly improving performance and reliability in high-throughput backend-to-backend environments.

How does the handling of 'state' differ between REST and GraphQL, and what are the implications for caching?

In REST, state is tied to specific resources accessible via stable URIs, which makes them highly cacheable by CDNs and browsers using standard HTTP headers like ETag or Cache-Control. GraphQL, however, typically uses a single endpoint for all operations, usually via a POST request. This breaks standard HTTP caching mechanisms because the 'query' is inside the request body, not the URI. Consequently, GraphQL requires more complex, application-level caching strategies compared to the native HTTP caching benefits of REST.

Explain the trade-offs of using strongly-typed contracts in gRPC versus the flexibility of REST.

gRPC requires a strict '.proto' file that defines both the request and response structure, forcing a 'contract-first' design. This rigidity ensures that producers and consumers are perfectly aligned, eliminating 'undefined' property issues. REST is more flexible, often using JSON-schema or openAPI for documentation, but it lacks the built-in binary enforcement of gRPC. The trade-off is that REST allows for rapid prototyping and human-readable debugging, while gRPC offers superior performance and strict schema adherence that prevents breaking changes in distributed architectures.

Discuss the evolution of API design from REST to GraphQL to gRPC in terms of network efficiency.

The evolution is driven by the need for network efficiency. REST was a breakthrough for public-facing resource management but struggled with payload bloat. GraphQL evolved to solve the 'n+1' problem and over-fetching, allowing the client to define the shape of the data, which reduces latency by collapsing multiple requests into one. Finally, gRPC optimizes the transport layer itself by using binary serialization and HTTP/2. The trajectory has moved from human-readable text-based protocols designed for the browser to binary, high-performance protocols designed for machine-to-machine efficiency.

All REST API Design interview questions →

Check yourself

1. When designing a public API intended for consumption by various third-party web clients, which protocol typically offers the best balance of caching, compatibility, and simplicity?

  • A.REST
  • B.gRPC
  • C.GraphQL
  • D.WebSockets
Show answer

A. REST
REST uses standard HTTP methods that work with all browser caches and proxies. gRPC requires Protobufs and HTTP/2 which browsers struggle to support natively. GraphQL has complex caching needs. WebSockets are stateful and not designed for simple resource retrieval.

2. A team needs to perform strict type checking between microservices that require high-performance, low-latency communication. Which approach is most efficient?

  • A.JSON-based REST
  • B.gRPC
  • C.GraphQL over HTTP
  • D.SOAP
Show answer

B. gRPC
gRPC uses binary serialization (Protobuf), which is much faster and smaller than text-based JSON used in REST or GraphQL. SOAP is outdated and verbose. REST and GraphQL suffer from overhead of parsing JSON.

3. In which scenario would GraphQL be definitively superior to REST?

  • A.When the application needs to cache all responses at the CDN level
  • B.When the API is internal and performance is the only metric
  • C.When the client needs to aggregate data from multiple entities in a single, flexible request
  • D.When the server resources are highly constrained and memory is limited
Show answer

C. When the client needs to aggregate data from multiple entities in a single, flexible request
GraphQL allows clients to request exactly what they need from multiple resources, avoiding the 'N+1' or over-fetching issues common in REST. REST excels at CDN caching and simplicity. gRPC is better for pure performance. GraphQL has higher server overhead than REST.

4. Why is it difficult to use standard HTTP caching headers with GraphQL?

  • A.Because GraphQL does not use HTTP
  • B.Because GraphQL queries are often sent via POST, which many caches do not cache by default
  • C.Because GraphQL responses are always encrypted
  • D.Because GraphQL automatically ignores Cache-Control headers
Show answer

B. Because GraphQL queries are often sent via POST, which many caches do not cache by default
Most GraphQL implementations use POST requests for queries to handle large parameters, and standard HTTP caches treat POST as non-idempotent/unsafe. REST and simple GET-based protocols work seamlessly with caches. The other options are incorrect interpretations of how protocols interact.

5. When designing for resource-oriented architecture, why is it considered a best practice in REST to avoid deep nested endpoints?

  • A.Because deep nesting prevents the use of HTTP/2
  • B.Because REST is strictly required to have a flat structure by international standards
  • C.Because resource relationships should ideally be handled via hypermedia or query parameters to keep resources intuitive
  • D.Because deep nesting causes the browser to reject the request
Show answer

C. Because resource relationships should ideally be handled via hypermedia or query parameters to keep resources intuitive
REST promotes resource-based URI design; excessive nesting (e.g., /a/b/c/d) complicates maintenance and doesn't represent true resources well. Hypermedia (HATEOAS) or simple filters are cleaner. The other options refer to non-existent or irrelevant technical limitations.

Take the full REST API Design quiz →

← PreviousREST API Interview Questions

REST API Design

24 lessons, free to read.

All lessons →

Track your progress

Sign in to mark lessons done, score quizzes and keep notes.

Open in the app