REST vs GraphQL in System Design Interviews: When to Use It and What to Say
When an interview asks you to design a data-driven service, the first architectural decision is often how the client talks to the backend. REST and GraphQL are the two dominant styles. Both solve the same core problem – moving data between a client and a server – but they do it in very different ways. Knowing when each shines, and being able to articulate that in a concise way, can turn a vague answer into a focused design.
One-Sentence Definitions
- REST: An architectural style where each resource is exposed through a fixed URL and standard HTTP verbs (GET, POST, PUT, DELETE) define the operation.
- GraphQL: A query language and runtime that lets the client describe exactly what fields it needs, and the server resolves that shape in a single request.
The Problem It Solves: Data Over-fetch / Under-fetch
Imagine you are building a social feed that shows a post, its author, and a list of recent comments. With a classic REST API you might need three separate calls: /posts/123, /users/45, and /posts/123/comments. The client either over-fetches (gets extra fields it never shows) or under-fetches (needs another round-trip). GraphQL solves this by letting the client ask for { post(id:123){ id title author{name} comments(limit:5){ text author{name}} } } in one shot.
Step-by-Step Walkthrough
Below is a tiny worked example that you can describe in an interview.
- Client builds a query – The front-end constructs a GraphQL query string that lists the fields it wants.
- HTTP POST to /graphql – The request body contains the query and any variables.
- Router forwards to GraphQL engine – The server receives the query and parses it into an abstract syntax tree (AST).
- Resolver chain – Each field has a resolver function. For
postthe resolver fetches the post row from a relational DB. Forauthorit may call a user service (perhaps via gRPC). Forcommentsit queries a comment store. - Aggregation – The engine stitches together the results according to the AST, preserving the requested shape.
- Response – The server returns a JSON payload that mirrors the query structure.
In a pure REST design, the same flow would involve three separate HTTP GETs, each hitting a different endpoint, and the client would have to merge the results.
Where It Shows Up in Classic Design Questions
| Design Question | Typical Spot for REST vs GraphQL | Why It Matters |
|---|---|---|
| Design a Social Media Feed | At the API layer that serves the feed to mobile/web clients | Determines if the feed can be built in one request (GraphQL) or needs aggregation (REST). |
| Build an E-commerce Product Catalog | When exposing product details, inventory, and pricing to the storefront | GraphQL can let the UI request only the fields needed for a specific page, reducing payload size. |
| Create a Monitoring Dashboard | In the data-exposure service that feeds charts and tables | REST’s cache-friendly URLs make it easy to CDN static metric snapshots, while GraphQL offers flexible ad-hoc queries. |
Trade-offs and the Follow-Up Question
| Aspect | REST | GraphQL |
|---|---|---|
| Caching | Simple URL-based caching (CDN, browser) works out of the box. | Requires explicit cache keys or persisted queries; otherwise caching is harder. |
| Flexibility | Fixed endpoints; adding a new field often means a new version or endpoint. | Clients can ask for any combination of fields without server changes. |
| Complexity | Low; each endpoint is a small, self-contained handler. | Higher; you need a schema, resolvers, and often a query-optimization layer. |
| Over-fetch / Under-fetch | Prone to both; you may return whole objects or need multiple calls. | Eliminated; the response matches the request exactly. |
| Tooling | Mature HTTP tooling, easy to test with curl. | Rich IDE support for schema introspection, but debugging can be less straightforward. |
Interviewers often follow the initial choice with a question like “How would you handle caching for this API?” or “What happens if the query becomes too expensive?” Be ready to discuss cache strategies for GraphQL (e.g., persisted queries, response caching at the resolver level) and the simplicity of HTTP cache headers for REST.
30-Second Spoken Pitch
“I’d choose GraphQL when the client needs a flexible view over several services, like a social feed that pulls posts, authors, and comments in one request. It prevents over-fetch and under-fetch, but we have to add a resolver layer and think about caching. For simpler CRUD or when we want to leverage CDN caching, REST with well-named endpoints is still the cleanest choice.”
Common Mistakes Candidates Make
- Treating the choice as binary – Saying “always use GraphQL” or “always use REST” ignores the problem context.
- Ignoring caching – Claiming GraphQL solves all performance problems without addressing how you’ll cache expensive resolvers.
- Over-engineering the schema – Adding dozens of nested types before the interview even asks for them makes the design noisy.
- Forgetting versioning – Assuming GraphQL eliminates versioning entirely; in practice you still need to deprecate fields gracefully.
- Mis-stating the request flow – Mixing up where the client sends the query (usually POST) and where it would send a REST GET, leading to confusion about idempotency.
How to Practice This
- Study the worked design in the System Design AI library. It is an API gateway design, the layer where REST routes or a GraphQL endpoint sit in front of your services.
- Draw your own diagram on the canvas: start with the client, show the API gateway, then branch into either fixed REST endpoints or a GraphQL resolver tree.
- Record a 30-second pitch and replay it. Make sure you mention the problem, the flow, and at least one trade-off.
Questions people ask
When should I default to REST in a design interview?
Use REST when the data model is simple, you need strong cacheability, or the service will be consumed by many third-party clients that expect stable URLs.
Can I mix REST and GraphQL in the same system?
Yes. It’s common to expose a GraphQL endpoint for internal UI teams while keeping public REST APIs for external partners.
How do I avoid the N+1 query problem in GraphQL?
Batch resolvers or data-loader patterns collect all needed keys and issue a single query per service, preventing one query per object.
What is a good way to version a GraphQL schema?
Deprecate fields with the @deprecated directive, add new fields, and communicate changes through schema introspection rather than URL versioning.