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
What is Idempotency in REST APIs, and how should HTTP methods and status codes be structured?
Intermediate level • 9 views
Compare Microservices Architecture with Monolithic Architecture: Trade-offs, Scalability, and Distributed Challenges.
Advanced level • 8 views
How should client-side and server-side form validation work together?
Easy level • 6 views
What responsibilities belong to the browser, application server, and database?
Easy 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 • 4 views