Compare REST APIs with GraphQL: Architectural differences, advantages, trade-offs, and when to use which.
Quick Revision Summary
REST uses multiple HTTP endpoints with native caching but suffers from over/under-fetching. GraphQL uses a single endpoint with precise client-specified payloads.
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
REST (Representational State Transfer):
- Resource-oriented architecture relying on standard HTTP verbs (GET, POST, PUT, DELETE) and fixed URL endpoints.
- Strong browser-level caching (HTTP 304, ETag).
- Drawbacks: Over-fetching (fetching unwanted fields) and under-fetching (requiring N+1 roundtrips to retrieve nested associations).
GraphQL:
- Query-oriented architecture where clients query a single POST endpoint requesting exact schema fields.
- Solves over-fetching and under-fetching in a single request.
- Drawbacks: Complex caching (cannot easily rely on URL-based HTTP caching), complex query parsing overhead, vulnerability to malicious nested queries.
Interviewer Evaluation Points & Scoring Rubric
- 1 1. Highlights over-fetching and under-fetching issues. 2. Discusses HTTP caching in REST vs GraphQL complexity. 3. Recommends appropriate architectural choice.
Related Questions in Full Stack Web Development
Compare Microservices Architecture with Monolithic Architecture: Trade-offs, Scalability, and Distributed Challenges.
Advanced level • 5 views
What is Idempotency in REST APIs, and how should HTTP methods and status codes be structured?
Intermediate level • 5 views
What is the difference between synchronous and asynchronous code in Node.js, and how does the Event Loop manage them?
Intermediate level • 1 views
How does React's Virtual DOM work and what is the Reconciliation process in React 18 Fiber?
Intermediate level • 1 views
What is Cross-Origin Resource Sharing (CORS), and when does the browser trigger a Preflight OPTIONS request?
Intermediate level • 1 views