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
34

Frontend System Design · Lesson 34 of 86 · 5 min

Hydration and Time to First Byte (TTFB)

This is where you connect rendering theory to real-world performance bottlenecks and show you can diagnose why a "fast" page feels slow.

The "uncanny valley" of Server-Side Rendering

With Server-Side Rendering (SSR), the browser gets HTML quickly and paints pixels almost immediately. The page looks ready. But if the user clicks a button and nothing happens for two seconds, you've created a frustrating experience. This gap between a visually complete page and an interactive one is the "uncanny valley" of SSR.

Hydration is the process that closes this gap. It's the client-side JavaScript running, finding the server-rendered HTML, and "bringing it to life" by attaching event listeners, initializing state, and making the application interactive.

Until hydration is complete, your app is just a static painting.

The trap: Many candidates can define SSR but fail to articulate this core trade-off: SSR optimizes for a fast First Contentful Paint (FCP) but can delay Time to Interactive (TTI). Your ability to explain this tension and how to resolve it is what interviewers are listening for.

How hydration works in code

In an interview, you should be able to walk through the lifecycle of a component from server to interactive client. The key is that the same component code runs in both environments.

First, the server uses a library like react-dom/server to render the component to a string. It fetches any necessary data and injects it into the HTML.

// server/renderer.ts
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { App } from '../src/App';

// In an Express.js route handler
async function handleRequest(req, res) {
  // 1. Fetch critical data on the server
  const initialData = { user: 'Interview Candidate' };

  // 2. Render the React tree to an HTML string
  const appHtml = ReactDOMServer.renderToString(
    <App initialData={initialData} />
  );

  // 3. Embed the HTML and initial data into a full document
  const html = `
    <!DOCTYPE html>
    <html>
      <head><title>SSR App</title></head>
      <body>
        <div id="root">${appHtml}</div>
        <script>
          window.__INITIAL_DATA__ = ${JSON.stringify(initialData)}
        </script>
        <script src="/client.bundle.js"></script>
      </body>
    </html>
  `;
  res.send(html);
}

Next, the client-side script executes. Instead of rendering into an empty DOM node, it hydrates the existing HTML.

// client/index.tsx
import React from 'react';
import { hydrateRoot } from 'react-dom/client';
import { App } from './App';

// 1. Grab the server-rendered HTML root
const rootElement = document.getElementById('root');

// 2. Read the initial data injected by the server
const initialData = window.__INITIAL_DATA__;

// 3. Hydrate: React takes over the existing HTML instead of creating it
if (rootElement) {
  hydrateRoot(
    rootElement,
    <App initialData={initialData} />
  );
}

React expects the client-rendered tree to be identical to the server-rendered HTML. If it's not (a "hydration mismatch"), React will discard the server's work and perform a full client-side render, losing most of the performance benefits of SSR.

Why your fast page still feels slow: TTFB

Before the browser can even start painting HTML, it has to receive the first byte of the response. The time it waits is the Time to First Byte (TTFB).

TTFB is the latency floor for your entire page load. If your TTFB is 800ms, your Largest Contentful Paint (LCP) can never be better than 800ms, even if your frontend code is perfect.

It measures the combined time of:

  1. Redirects, DNS lookups, and connection setup (TCP/SSL).
  2. The time your server spends processing the request (running business logic, querying databases, calling APIs).
  3. The time it takes for the first packet of the response to travel back to the client.

The trap: Focusing exclusively on frontend metrics like bundle size while ignoring the server. A candidate who says "we'll reduce our bundle size" to fix a slow initial load might be missing the real problem. A high TTFB points to a backend or infrastructure bottleneck, not a frontend one.

Diagnosing and fixing hydration bottlenecks

When a page has a high TTI despite a fast FCP, hydration is the likely culprit.

In an interview, you might be asked: "You've shipped an SSR feature and users are complaining the page feels frozen for a few seconds after loading. How do you investigate?"

Your answer should cover these common causes:

  1. The monolithic bundle: The browser can't hydrate until it has downloaded, parsed, and executed your JavaScript. If you ship a single 2MB app.js, you're forcing the user to wait, blocking the main thread and delaying interactivity. The fix is aggressive code-splitting. Send only the code needed for the current page to become interactive.
  2. Over-hydration: You're hydrating the entire page, including static parts like the header, footer, or a blog post's text content. This is wasted effort. The fix is partial or selective hydration. Modern frameworks are moving towards this model (e.g., Astro Islands, React Server Components), where you explicitly mark which components are interactive "islands" that need hydration.
  3. Heavy client-side logic: Your component's useEffect or top-level module code might be running expensive computations or fetching non-critical data synchronously upon load. This blocks the main thread and delays hydration. Defer this work until after hydration or until the user actually interacts with the component.

How to attack a high TTFB

A high TTFB is almost always a server-side or network problem. Your strategy should focus there.

  1. Cache aggressively. The fastest database query is the one you don't make. Use an in-memory cache like Redis or Memcached to store the results of expensive queries or API calls. For content that is the same for all users, you can even cache the fully-rendered HTML page itself.
  2. Use a Content Delivery Network (CDN). A CDN moves your server closer to the user. It terminates the TLS connection at an edge location near them, drastically reducing round-trip time for the initial request. It can also cache static assets and full-page responses, serving them directly from the edge without ever hitting your origin server.
  3. Optimize server-side logic. Profile your request handler. Are you making multiple database calls in series that could be parallelized? Is there a single slow query that needs an index? Any synchronous file I/O?
  4. Stream the response. Instead of waiting for the entire HTML document to be generated before sending it, streaming SSR sends it in chunks. The browser can receive the <head>, start downloading CSS, and begin rendering the top of the page while the server is still busy fetching data for components further down. This directly improves TTFB for the initial chunk.

Try it

Take a key page from an application you've worked on (e.g., a product detail page, a dashboard). Whiteboard its component structure. Identify which components are purely static and which are interactive. For the interactive ones, what client-side state do they manage? To render the page on a server, what data would you need to fetch, and what's your caching strategy for that data to ensure a low TTFB?

Next: We'll look at how to avoid the server and hydration altogether for certain types of content with Static Site Generation (SSG) for Speed and SEO.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

SSR vs CSR: Rendering Trade-offs

Next

Static Site Generation (SSG) for Speed and SEO