01 / 05

What is GraphQL, and how does it differ from REST?

Difficulty: 5/10
query flexibility, over‑fetching vs under‑fetching, schema evolution

GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your data. The GraphQL specification was open-sourced in 2015 and has since been implemented in a variety of programming languages. GraphQL has been released simply as a specification, for a query language for APIs that allows clients to request exactly the data they need, nothing more and nothing less.

  1. 1

    GraphQL server can be implemented in any preferred programming language.

  2. 2

    Unlike REST, where multiple endpoints provide fixed data structures, GraphQL has a single endpoint and lets clients define the structure of the response.

  3. 3

    This reduces the over-fetching and under-fetching of data.

  4. 4

    It is strongly typed using Schema Definition Language

Scenario Questions

0-2 years experience

  1. 1How would you fetch a list of users with their posts using GraphQL compared to a typical REST endpoint?
  2. 2If a client only needs a user's name and email, what would the GraphQL query look like and how does that avoid over‑fetching?
  3. 3What happens if you request a field that doesn't exist in the GraphQL schema?

2-5 years experience

  1. 1We added a new field to the User type but some clients started receiving errors; how would you debug the issue?
  2. 2When deciding between GraphQL and REST for a new feature that requires pagination and filtering, what trade‑offs would you consider?
  3. 3If a GraphQL resolver is causing N+1 queries, how would you identify and fix it?

5-8 years experience

  1. 1Design a gateway that serves both GraphQL and existing REST services; how would you handle authentication and caching across the two?
  2. 2At scale, what are the performance implications of deeply nested GraphQL queries and how would you mitigate them?
  3. 3How would you implement rate limiting for a public GraphQL API without impacting existing REST clients?

8+ years experience

  1. 1Our organization wants to migrate a large monolithic REST API to GraphQL over several years; outline a migration strategy that minimizes disruption for multiple product teams.
  2. 2When multiple teams own different parts of the schema, how do you enforce versioning and backward compatibility?
  3. 3What governance model would you set up to manage schema evolution and avoid breaking changes across services?

Follow-up Questions

  • Can you give an example of a query that would be inefficient in GraphQL?
  • How does caching differ between GraphQL and REST?
  • What are the security considerations unique to GraphQL?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.