Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
49

Frontend System Design · Lesson 49 of 86 · 4 min

REST and GraphQL for Frontend Engineers

This is not about memorizing definitions; it's about articulating the trade-offs when an interviewer asks, "Which would you use here, and why?"

How REST Structures Data Access

REST (Representational State Transfer) isn't a protocol; it's a set of conventions for building APIs. Think of it as an agreed-upon way to model your backend as a collection of resources, accessed via URLs.

For you as a frontend developer, this means predictable patterns. You fetch a list of users from /users. You fetch a specific user from /users/123. You create a user by sending a POST request to /users. You use standard HTTP verbs (GET, POST, PUT, DELETE) to signal your intent.

The key benefit is simplicity and leveraging the web's existing infrastructure. HTTP caching works out of the box with GET requests, which can dramatically improve performance without any client-side logic.

// A typical RESTful GET request
async function fetchUsers(): Promise<User[]> {
  const response = await fetch('https://api.example.com/v1/users');

  if (!response.ok) {
    throw new Error(`HTTP error! Status: ${response.status}`);
  }

  const users = await response.json();
  return users;
}

The trap: Candidates often just say REST uses HTTP methods. Go deeper. Mention that REST's stateless nature and use of GET for reads makes it perfectly suited for caching at multiple layers (browser, CDN, proxy), which is a significant performance win.

The Problem GraphQL Solves

The rigidity of REST endpoints creates two common problems: over-fetching and under-fetching.

Over-fetching is when you get more data than you need. The /users/123 endpoint might return a 50-field user object, but your UI only needs the user's name and avatar. The other 48 fields are wasted bandwidth.

Under-fetching is when you don't get enough data, forcing you to make more requests. To build a user's profile page, you might need to call GET /users/123, then GET /users/123/posts, and then GET /users/123/followers. This "chatty" interaction adds latency.

These problems are especially painful on mobile clients with limited network bandwidth and higher latency.

How GraphQL Gives the Frontend Control

GraphQL is a query language for your API. Instead of hitting multiple, fixed endpoints, you send a single query to a single endpoint (usually /graphql) that describes exactly the data you need. The server responds with a JSON object that mirrors the shape of your query.

This gives the frontend control. If you need the user's name and the titles of their last three posts, you ask for just that.

query GetUserWithPosts($id: ID!) {
  user(id: $id) {
    id
    name
    posts(last: 3) {
      id
      title
    }
  }
}

Under the hood, this is still just an HTTP request. You send a POST request with the query and any variables in the body.

// A typical GraphQL request using fetch
async function fetchUserWithPosts(userId: string) {
  const response = await fetch('https://api.example.com/graphql', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      query: `
        query GetUserWithPosts($id: ID!) {
          user(id: $id) {
            id
            name
            posts(last: 3) {
              id
              title
            }
          }
        }
      `,
      variables: { id: userId },
    }),
  });

  if (!response.ok) {
    throw new Error(`HTTP error! Status: ${response.status}`);
  }

  const { data } = await response.json();
  return data.user;
}

The GraphQL server parses the query and fetches the data from various sources—databases, microservices, other APIs—before assembling the final response.

Articulating the Trade-offs

This is the core of the interview question. Your ability to discuss trade-offs shows seniority.

In an interview, show you can weigh these factors. Start your answer with "It depends on the project's needs..." then explain what those needs might be. For a simple CRUD app with a well-defined resource model, REST is often the right call due to its simplicity. For a complex dashboard aggregating data from three microservices, GraphQL is a strong contender.

Choose REST when:

  • You have a simple, resource-centric API (e.g., a basic blog).
  • You want to heavily leverage HTTP caching.
  • The project is small, and the overhead of setting up a GraphQL server is not justified.
  • You are building a public API and want the lowest possible barrier to entry for consumers.

Choose GraphQL when:

  • You have complex UIs with varied and nested data requirements.
  • You need to minimize network requests (e.g., mobile apps).
  • You are building a frontend on top of multiple existing services (an "API gateway").
  • The frontend team is evolving rapidly and wants to avoid waiting for backend changes to add or remove fields.

Be aware of GraphQL's challenges:

  • Caching is harder. Since most queries are POST requests to a single endpoint, you can't rely on standard HTTP caching. Caching logic moves to the client (e.g., Apollo Client, urql).
  • Performance pitfalls. A poorly-implemented GraphQL server can suffer from the "N+1 problem," where a query for a list of N items results in N+1 database queries. This is solved on the backend with tools like dataloader, but you should know the problem exists.
  • Complexity. It introduces a new language, a type system (the schema), and more complex server-side logic (resolvers). This can be overkill for simple projects.

Try it

Take 15 minutes. For a component that displays a blog post with its author's name and a list of comments, write down: 1. The sequence of REST API calls you might need. 2. The single GraphQL query that would get the same data.

Next: Batching, Throttling and Debouncing API Calls.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Video Streaming: HLS, DASH, Adaptive Bitrate

Next

Batching, Throttling and Debouncing API Calls