▶What are Core Web Vitals and why do they matter?
Core Web Vitals are Google's metrics for page quality: Largest Contentful Paint (LCP, <2.5s), First Input Delay (FID, <100ms), Cumulative Layout Shift (CLS, <0.1). Mobile-first: 60% of mobile users abandon sites that take >3s. Ranking factor: Google Search prioritizes fast sites. Career: optimizing these = $20k-$40k salary boost (frontend specialists).
▶Profiling vs guessing, why not just 'make it faster'?
Most developers optimize the wrong code path (80/20 rule). Profiling: CPU time, memory, allocations. Flamegraphs show where time IS spent (not where you think). Result: 10x speedups by fixing the real bottleneck, not guess-and-check. 80% of optimization time is bottleneck-finding; 20% is the fix.
▶Bundle size strategies, how do I keep JavaScript lean?
Code splitting: split by route, lazy-load heavy libraries (React, D3). Tree-shaking: unused code removal (requires ES modules). Compression: gzip (standard), brotli (30% smaller). Minification: terser removes comments/whitespace. Metrics: LCP matters more than bundle size (code splitting for LCP). Target: <100KB gzipped initial JS; <50KB per route.
▶Database query optimization, N+1 problem and what else?
N+1: 1 query + N follow-up queries. Fix: JOIN or fetch all IDs upfront. Indexes: fastest optimization (10x queries). Missing index = full table scan. Query profiling: EXPLAIN PLAN. Denormalization: duplicate data to avoid joins (when appropriate). Query caching: Redis for repeated queries. Shard-aware queries: if sharded, fetch from one shard only.
▶Caching strategies, browser, CDN, application, database?
4-tier caching: (1) Browser: static assets, max-age=1 year; (2) CDN: Cloudflare/CloudFront, edge location; (3) Application: Redis, hot data; (4) Database: query cache, prepared statements. Cache invalidation: time-based (TTL) or event-based (purge on update). Trade-off: stale data vs cache complexity. Rule: cache-first, then fix cache busting.
▶Performance budgets, how do I prevent regressions?
Budget = max bytes per asset (JS/CSS/images). Example: 100KB JS budget; if new code pushes to 105KB, build fails. Tools: bundlebudget, size-limit, bundlewatch. Include in CI. Prevents performance death-by-a-thousand-cuts. Real example: Slack's JS grew 2MB over 3 years with no budget.
▶Should I optimize for latency or throughput?
Latency (P95, P99) = user experience (single request time). Throughput (RPS) = system capacity (requests/second). Optimize latency first (users care). Then throughput (scaling). Example: 50ms per request * 1000 RPS = need 50 servers (cost). 1ms per request = 1 server. Latency improvements save millions in infrastructure.