Senior6 questionsFull Guide

Core Web Vitals & Performance — System Design Interview Guide

Master LCP, INP, CLS, and TTFB — what they measure, what causes them to be poor, and exactly how to fix each one. Understand why Google uses Core Web Vitals as ranking signals and how to design for performance from the architecture level down.

The Mental Model

Core Web Vitals measure three aspects of user experience: loading (LCP — how quickly the main content appears), interactivity (INP — how quickly the page responds to input), and visual stability (CLS — how much the layout unexpectedly shifts). Google uses them as ranking signals because they correlate with whether users stay or leave. Improving them is not just a performance exercise — it's a business metric.

The Explanation

LCP — Largest Contentful Paint

Measures the time from navigation to when the largest visible element renders in the viewport. Usually a hero image, banner, or above-the-fold heading. Good: < 2.5s. Needs improvement: 2.5–4s. Poor: > 4s.

Common LCP Causes and Fixes

  • Slow server response (TTFB) → Use CDN, SSG/ISR instead of SSR, optimize database queries
  • Render-blocking resources → Inline critical CSS, defer non-critical scripts
  • Unoptimized LCP image → Use WebP/AVIF, add rel="preload", set proper dimensions, never lazy-load it
  • Client-side rendering → Browser sees blank HTML until JS runs; use SSR/SSG to deliver rendered HTML
<!-- Optimal LCP image setup -->
<link rel="preload" as="image" href="/hero.avif" />
<img
  src="/hero.avif"
  fetchpriority="high"
  width="1200" height="600"
  alt="Hero"
  <!-- NO loading="lazy" — lazy loading kills LCP -->
/>

INP — Interaction to Next Paint

Replaced FID in 2024. Measures the time from user input (click, tap, key press) to when the browser paints the next frame in response. Good: < 200ms. Poor: > 500ms.

Causes and Fixes

  • Long Tasks on the main thread → Break up with scheduler.yield() or setTimeout, use Web Workers for CPU-heavy work
  • Heavy event handlers → Debounce, defer non-critical work, avoid synchronous layout recalculations
  • Large React re-renders → memo, useMemo, useCallback, virtualize long lists (react-virtual)
// Yield to the browser between expensive operations
async function processLargeDataset(items) {
  for (let i = 0; i < items.length; i++) {
    process(items[i]);
    if (i % 100 === 0) {
      await scheduler.yield(); // let browser handle pending interactions
    }
  }
}

CLS — Cumulative Layout Shift

Measures unexpected visual movement of page elements during loading. An image that loads and pushes text down is a CLS violation. Good: < 0.1. Poor: > 0.25.

Causes and Fixes

  • Images without dimensions → Always set width and height on img tags; browser reserves space before the image loads
  • Dynamically injected content → Reserve space with min-height or skeleton placeholders
  • Web fonts causing FOIT/FOUT → Use font-display: swap and preload the font
<!-- Reserve space — no layout shift when image loads -->
<img src="/photo.webp" width="800" height="600" alt="..." />

/* CSS — aspect-ratio maintains space */
.image-container {
  aspect-ratio: 4 / 3;
  width: 100%;
}

TTFB — Time to First Byte

Time from navigation start to the first byte of the HTML response. Affected by server processing time, redirects, and network latency. A slow TTFB affects all other metrics because nothing can render before HTML arrives.

Fix: CDN edge caching (serves HTML from a server near the user), SSG/ISR (serve pre-built HTML instantly), optimize server-side queries.

Measuring and Monitoring

// web-vitals library — report in real user monitoring (RUM)
import { onLCP, onINP, onCLS } from 'web-vitals';

onLCP(({ value, rating }) => analytics.track('LCP', { value, rating }));
onINP(({ value, rating }) => analytics.track('INP', { value, rating }));
onCLS(({ value, rating }) => analytics.track('CLS', { value, rating }));

Common Misconceptions

⚠️

Lighthouse score = Core Web Vitals — Lighthouse is a lab tool (simulated, controlled). Core Web Vitals measured by Google are from real users (field data). A 100 Lighthouse score doesn't guarantee good field CWV.

⚠️

CLS is only caused by images — any element that shifts: ads loading, cookie banners, dynamic content injected above existing content, web fonts swapping — all cause CLS.

⚠️

INP replaced FID and measures the same thing — FID measured only the first interaction and only the input delay. INP measures all interactions throughout the page lifetime and includes processing time and render time.

⚠️

Improving one metric automatically improves others — optimizations can conflict: SSR improves LCP but adds server processing time (TTFB). Heavy JavaScript frameworks hurt INP. Trade-offs must be measured.

Where You'll See This in Real Code

Next.js Image component: sets width/height automatically (fixes CLS), serves WebP/AVIF (improves LCP), lazy-loads off-screen images (improves initial page weight)

News sites after CWV rollout: BBC, Guardian significantly improved LCP by moving from CSR to SSR/SSG and preloading hero images — correlated with ranking improvements

E-commerce: product image CLS is a common issue — fixed by CSS aspect-ratio on image containers; Pinterest improved CLS by 50% this way

web-vitals library used in production by large sites to collect real user metrics and alert on regressions before they affect rankings

Interview Cheat Sheet

  • LCP < 2.5s: optimize hero image (WebP, preload, no lazy), reduce TTFB (CDN, SSG), remove render-blocking resources
  • INP < 200ms: break up long tasks, defer non-critical work, virtualize lists, avoid layout thrashing
  • CLS < 0.1: always set width/height on images, reserve space for dynamic content, preload fonts
  • TTFB < 800ms: CDN edge caching, SSG/ISR, optimize server queries
  • fetchpriority='high': on LCP image (tells browser to prioritize this fetch)
  • font-display: swap: use fallback font while web font loads — prevents FOIT
  • scheduler.yield(): yield main thread between long tasks to maintain INP
  • web-vitals library: measure real user CWV in production
💡

How to Answer in an Interview

  • 1.Know all four metrics cold: LCP (loading), INP (interactivity), CLS (stability), TTFB (server). Explain what each measures and the good/poor thresholds.
  • 2.The connection between rendering strategy and LCP is key: CSR pages have poor LCP because the browser sees blank HTML; SSG serves rendered HTML instantly from CDN
  • 3.Mention real user monitoring vs lab testing — Lighthouse is useful for development, but real user data (field data) is what Google uses for rankings
  • 4.scheduler.yield() is an advanced technique that shows current knowledge — it's the modern replacement for setTimeout-based task yielding

Practice Questions

6 questions
#01

What are the three Core Web Vitals and what does each measure?

EasyCore Web Vitals PRO💡 LCP (loading), INP (interactivity), CLS (visual stability) — Google's user-experience signals that affect search ranking
#02

What are the most common causes of poor LCP and how do you fix them?

EasyCore Web Vitals PRO💡 Slow TTFB, render-blocking resources, unoptimized hero image, lazy-loaded LCP element
#03

What causes CLS (Cumulative Layout Shift) and how do you fix it?

EasyCore Web Vitals PRO💡 Elements without dimensions, late-injected content, web fonts causing FOUT, embeds without aspect-ratio containers
#04

What is INP (Interaction to Next Paint) and how does it differ from FID?

EasyCore Web Vitals PRO💡 FID measured only the first interaction's input delay; INP measures the worst interaction delay across the full page visit
#05

How do you measure Core Web Vitals in a production React app?

EasyCore Web Vitals PRO💡 web-vitals library for field data; Lighthouse and PageSpeed Insights for lab data; Next.js has built-in instrumentation
#06

What techniques reduce INP on a React app with expensive renders?

MediumCore Web Vitals PRO💡 React 18 startTransition, scheduler.yield, virtualization, memoization, Web Workers for off-thread computation

Related Topics

Bundle Optimization (Tree Shaking, Code Splitting) — System Design Interview Guide
Advanced·8–12 Qs
Network Optimization (Prefetch, Preload, HTTP/2) — System Design Interview Guide
Advanced·8–10 Qs
Rendering Strategies (SSR, CSR, SSG, ISR) — System Design Interview Guide
Senior·10–15 Qs
🎯

Can you answer these under pressure?

Reading answers is not the same as knowing them. Practice saying them out loud with AI feedback — that's what builds real interview confidence.

Practice Free →Try Output Quiz