Performance
Core Web Vitals: LCP, INP, and CLS
A team spends two sprints optimising their API response times. Server P99 drops from 400 ms to 90 ms. Google Search Console shows LCP is still “Poor” for 40% of mobile users. The API was not the bottleneck. The 800 KB JS bundle blocking the main thread was.
The three metrics and what they measure
Google’s Core Web Vitals are three field metrics — collected from real Chrome users via the CrUX dataset — that quantify distinct dimensions of user experience.
LCP (Largest Contentful Paint) — the time from navigation start to when the largest visible element above the fold is rendered. This is usually a hero image, an H1, or a background block. Target: under 2.5 s is “Good”; 2.5-4.0 s is “Needs Improvement”; above 4.0 s is “Poor”. Heavy JavaScript that blocks the main thread delays when the browser can paint — LCP suffers directly.
INP (Interaction to Next Paint) — introduced in March 2024, replacing FID. INP measures the worst-case latency from any user input (click, keypress, tap) to the next visual update during the full page lifetime. Target: under 200 ms is “Good”; 200-500 ms is “Needs Improvement”; above 500 ms is “Poor”. Long JS execution tasks on the main thread — including large bundle parse and execution — drive INP up.
CLS (Cumulative Layout Shift) — how much visible content shifts unexpectedly during load. Target: under 0.1 is “Good”; 0.1-0.25 is “Needs Improvement”; above 0.25 is “Poor”. Bundle size does not directly cause CLS; layout shifts come from unsized images, late-loading fonts, and JS that inserts above-fold content after initial paint.
| Metric | Good | Needs Improvement | Poor | Bundle lever? |
|---|---|---|---|---|
| LCP | < 2.5 s | 2.5 – 4.0 s | > 4.0 s | Strong — JS parse/execute blocks paint |
| INP | < 200 ms | 200 – 500 ms | > 500 ms | Strong — long tasks from large bundles |
| CLS | < 0.1 | 0.1 – 0.25 | > 0.25 | Indirect — JS that inserts above-fold content |
The 100-170 KB rule of thumb
Google’s Web Fundamentals guidance recommends keeping the initial JS under 100-170 KB gzip’d for fast first interactive on mid-range mobile. The math: 170 KB gzip’d decompresses to roughly 500 KB. V8 parses at 200-400 KB/sec on mid-range Android, so parse alone takes 1.5 s. Add compile and execute and the total is 2-2.5 s CPU cost. Add a 4G download at ~500 ms and you arrive at roughly 3 s to interactive — the upper bound that keeps LCP under 2.5 s. Every additional 100 KB beyond that adds roughly 300-500 ms to LCP on the median device.
Different routes can carry different budgets: a marketing homepage should be tight (50-100 KB), a dashboard medium (150-250 KB), admin tools more relaxed (300-500 KB). The homepage carries the tightest cap because it is the conversion entry point.
Three tools: Lighthouse, PageSpeed Insights, RUM
These tools measure the same metrics but from different vantage points.
Lighthouse runs a synthetic test — DevTools or CLI — with CPU throttling on the tester’s machine. Reliable for catching regressions in PRs. Not field data; it represents a single synthetic run.
PageSpeed Insights runs a Google-managed Lighthouse test plus overlays field data from the CrUX dataset — real aggregated metrics from Chrome users on your domain. Useful for public-facing analysis. Updates once per day.
Real User Monitoring (RUM) — your own sampling of real users via the Web Vitals JS library, Sentry, Datadog RUM, or similar. Most accurate, but requires setup and budget. Senior pattern: Lighthouse in CI for catching regressions before merge; RUM in production for regressions that CI misses; PageSpeed Insights quarterly for cross-reference. Each catches a different class of problem; none replaces the others.
Why this works
INP replaced FID (First Input Delay) in March 2024. FID measured only the first interaction; INP measures the worst across the full session. A page where the first click is fast but the fifth is sluggish scored “Good” on FID and “Poor” on INP. The change makes it harder to game the metric with a fast handler for the first event while hiding slow handlers everywhere else.
A team's P75 LCP is 3.2 s on mobile. Server TTFB is 80 ms. Most likely cause?
A route's INP is 380 ms. The bundle is 900 KB uncompressed. After code splitting the bundle to 200 KB for this route, INP drops to 150 ms. What improved and why?
Why does CLS (Cumulative Layout Shift) NOT improve much from reducing JS bundle size?
- 01What do LCP, INP, and CLS each measure? Give the 'Good' threshold for each.
- 02Why does a fast server TTFB (80 ms) not guarantee a good LCP?
- 03What is the difference between Lighthouse and RUM for catching CWV regressions?
Core Web Vitals are field metrics collected from real Chrome users. LCP and INP both improve as JS bundle size decreases — parse and execute time set the floor for how fast a page can paint and respond. The 100-170 KB gzip’d rule of thumb maps to the math: each 100 KB beyond that adds 300-500 ms to LCP on mid-range mobile. CLS has its own separate root causes (unsized images, fonts, dynamic insertion). Lighthouse catches regressions pre-merge; RUM catches production drift. The next lesson covers code splitting — the primary technique for reducing per-route bundle size.
appears again in159
- The journey of a request: seven stops from socket to responsejunior
- Accept and parse: from kernel queue to a typed requestmiddle
- Routing and middleware: choosing what runs, and in what ordermiddle
- Handler and response: from business logic to bytes on the wiremiddle
- Streaming and backpressure: when the client reads slower than you writesenior
- Timeouts and tail latency: budgets, deadlines, and the fan-out trapsenior
- Middleware and DI: the two patterns that shape every backendjunior
- Writing middleware: signatures, next(), and the three framework modelsmiddle
- Inversion of control: how dependencies reach a classmiddle
- DI scopes and lifecycles: singleton, request, transientmiddle
- DI as a testing seam: fakes, mocks, and the boundary that matterssenior
- DI containers in production: resolution graphs, circular deps, and when not tosenior
- Blocking vs non-blocking I/O: two ways to waitjunior
- The event loop: one thread, ordered phasesmiddle
- What blocks the loop: CPU work and sync callsmiddle
- Offloading CPU work: worker threads and the libuv poolmiddle
- Backpressure and bounded concurrencysenior
- Throughput under load: tail latency and saturationsenior
- Why pool: the cost of creating a connectionjunior
- Pool sizing: why bigger is not fastermiddle
- Acquisition and timeouts: the wait queue is the real latency dialmiddle
- Retry strategies: backoff, jitter, and thundering herdmiddle
- Observability, production failures, and global-scale designsenior
- Tasks, microtasks, and scheduler.yield()middle
- Timer accuracy, throttling, and idle workmiddle
- Node.js event loop: phases, nextTick, and loop lagsenior
- Rendering strategies: SSG, SSR, ISR, streaming, and hydrationjunior
- SSG, SSR, ISR, streaming, and RSC — how each worksmiddle
- Hydration cost: selective, progressive, islands, resumabilitymiddle
- Core Web Vitals: what LCP, INP, and CLS measurejunior
- LCP: four phases, one dominant costmiddle
- INP: input delay, processing, presentationmiddle
- Lab vs field: why the two disagree and how to use eachmiddle
- Metric tradeoffs, RUM attribution, and the CI+field loopsenior
- The full picture: URL to LCP to INP as a relay racejunior
- Eight layers traced: from the service worker to the second navigationmiddle
- Five canonical breaks: where production reliably diessenior
- The three-track method: reading traces and building a monitored systemsenior
- What an index is and how it speeds up queriesjunior
- The leading-column rule and composite index designmiddle
- Partial, expression, and covering indexesmiddle
- Index types: GIN, GiST, BRIN, Hash, Bloom, and HOT updatesmiddle
- Index-only scans, the Visibility Map, and INCLUDEsenior
- Production failure modes and the index audit playbooksenior
- Index design exercise: full-text search strategysenior
- EXPLAIN and execution plans: what the planner decides and whyjunior
- Scan types: Seq, Index, Bitmap, Index-Onlymiddle
- Join algorithms and the row-estimate cascademiddle
- pg_statistic, ANALYZE, and production observabilitymiddle
- Extended statistics: fixing correlated-column estimate failuressenior
- Plan cache, cost-constant tuning, and planner internalssenior
- Production failure modes and plan stabilitysenior
- Connection pools: amortising the cost of a Postgres backendjunior
- PgBouncer session, transaction, and statement modesmiddle
- Pool sizing: the (cores × 2) + spindles formula and the two-layer stackmiddle
- Pool exhaustion and idle-in-transaction: the 3 AM failure modemiddle
- Migrating to transaction mode: rollout playbook and PgBouncer 1.21 prepared statementsmiddle
- The Postgres process model and why raising max_connections degrades throughputsenior
- Pooler landscape 2026, serverless connection storms, and the full failure-mode taxonomysenior
- ADD COLUMN: instant in PG 11+ vs rewrite in older Postgresjunior
- The lock-queue failure mode: why instant DDL can freeze the databasemiddle
- Safe DDL patterns: NOT VALID, CONCURRENTLY, and unsafe-op fixesmiddle
- Migration failure taxonomy and production disciplinesenior
- Shard-key selection: hash, range, list, and directory strategiesmiddle
- Co-location and Citus: the invariant that makes sharding usablemiddle
- The hot-shard failure mode: detection, isolation, and durable policymiddle
- Online resharding, 2PC, and the operational cost of shardingsenior
- The seven acts: from CREATE TABLE to Citusjunior
- Acts 1–3 in depth: schema, indexes, and planner statisticsmiddle
- Acts 4–6 in depth: MVCC bloat, connection pooling, and safe migrationsmiddle
- Act 7 in depth: sharding, co-location, and the seven-tier tradeoff cascademiddle
- Observability, anti-patterns, and production triagesenior
- Bits on the wirejunior
- Latency mathmiddle
- Bufferbloat and congestionsenior
- The physical frontiersenior
- Sequence numbers and connection statemiddle
- Flow control and congestion controlmiddle
- BBR, production observability, and beyond TCPsenior
- CDN: putting content next doorjunior
- Anycast and GeoDNS: routing to the nearest edgemiddle
- Tiered cache and Cache-Controlmiddle
- Vary header and cache keysmiddle
- Stale-while-revalidate and cache stampedesenior
- Edge workers and edge-side compositionsenior
- CDN operations and observabilitysenior
- WebSocket: the HTTP upgrade handshakejunior
- WebSocket vs SSE vs long-polling: choosing the right transportmiddle
- WebSocket backpressure: when clients can''''t keep upmiddle
- Reconnection: jittered backoff, thundering herd, message resumptionsenior
- WebSocket at scale: HTTP/2 multiplexing, permessage-deflate, C10Msenior
- WebSocket in production: proxies, security, and distributed architecturesenior
- What reverse proxies dojunior
- Balancing algorithms: round-robin to power-of-two-choicesmiddle
- L4 vs L7 load balancing and client-IP preservationmiddle
- Health checks, connection draining, and slow startmiddle
- Retry storms, circuit breakers, and load sheddingsenior
- Resilient LB architecture: anycast, zone-aware routing, and observabilitysenior
- Why QUIC and not TCP+TLSjunior
- QUIC streams and head-of-line blockingjunior
- Integrated handshake and 1-RTTmiddle
- Connection IDs and network migrationmiddle
- Loss detection and congestion controlmiddle
- 0-RTT resumption and packet encryptionsenior
- Deployment tradeoffs and CPU costsenior
- DDoS: what it is and why it worksjunior
- Amplification attacks and state exhaustionmiddle
- Rate limiting: algorithms and architecturemiddle
- WAFs, firewalls, mTLS, and HSTSmiddle
- DNS cache poisoning and BGP hijackingsenior
- Defense-in-depth architecture and attack economicssenior
- The twelve layers: one URL, seven actorsjunior
- DNS, TCP, TLS in sequence: where the milliseconds gomiddle
- Critical render path and Core Web Vitalsmiddle
- Proxy intercepts and security gates: rate limiters, WAF, mTLSmiddle
- Alternate paths: QUIC 0-RTT, WebSocket upgrade, connection migrationmiddle
- Observability: distributed traces, USE/RED, and samplingsenior
- Resilience: cascading retries, circuit breakers, and error budgetssenior
- What the three signals are: logs, metrics, and tracesjunior
- Metrics and cardinality: the cost model of a time-series databasemiddle
- Logs and volume: the cost model of structured loggingmiddle
- Traces and sampling: the cost model of distributed tracingmiddle
- Join keys and exemplars: making the three signals composemiddle
- Observability 2.0: wide events and the cost shiftsenior
- Failure modes and engineering practice: cardinality budgets, PII, and samplingsenior
- Why structured logs exist: the diary vs the spreadsheetjunior
- The production log schema: fields every line must carrymiddle
- Log levels and alert routingmiddle
- Sampling strategies and log costmiddle
- PII redaction and log injectionsenior
- Trace context propagation in logssenior
- OTel Logs Data Model and audit logs as a subsystemsenior
- OTel signals, Semantic Conventions, and the OTLP wire formatmiddle
- Auto-instrumentation and manual spans: the 80/20 of OTelmiddle
- The OTel Collector: receivers, processors, exporters, and deployment patternsmiddle
- Sampling strategies: head, tail, and parent-basedmiddle
- Vendor neutrality, eBPF instrumentation, the Operator, and browser/serverless OTelsenior
- Operating the OTel Collector: reliability, version skew, failure modes, and governancesenior
- RED and USE: two checklists, one triage disciplinejunior
- Instrumenting RED in Prometheus: counters, histograms, and cardinality disciplinemiddle
- USE on Linux: CPU, memory, disk, network, and PSImiddle
- Golden signals, dashboard layout, and service mesh auto-REDmiddle
- Cardinality as a cost driver: labels, PII, exemplars, and samplingmiddle
- Native histograms, SLO tie-in, and production failure patternsmiddle
- Choosing SLIs and SLO targets: ratios, not feelingsmiddle
- Multi-window multi-burn-rate alerting: why AND beats ORmiddle
- Error budget policy, latency SLOs, and composite journeysmiddle
- Iceberg SLIs, composite SLO math, and SLA vs SLOsenior
- Flame graphs: reading the picture that shows where time goesjunior
- Sampling vs instrumentation profiling: why 99 Hz wins in productionmiddle
- Profile types: CPU, memory, off-CPU, mutex — which one to reach formiddle
- Continuous profiling: always-on flame graphs with eBPF and trace-id correlationmiddle
- How flame graphs are built from samples, and the production workflows that use themmiddle
- Linux perf, eBPF internals, PGO, and the limits of samplingsenior
- Profiling in production: security, war stories, OTel profiles, and the infrastructure designsenior
- The debugging funnel: SLO → RED → trace → profilejunior
- OTel architecture: one SDK, four signals, one wire formatmiddle
- Cost discipline: keeping observability under 5% of infra spendmiddle
- Scale, security, and the ROI of observable systemssenior