Skip to content

    Frontend System Design

    Front-End Estimation and Capacity Drills

    Practise six back-of-envelope front-end estimates: transfer time, payload size, request rate, DOM size and polling versus push, each with a low and high case.

    By Published 12 min read

    • frontend-system-design
    • estimation
    • capacity
    • interview
    • performance-budgets
    Share

    Standard lessonintermediateFrontend System Design

    Before this: The Front-End Architect Interview Framework, Performance Budgets and Profiling

    What you'll learn: By the end of this lesson you will be able to run the six estimates a front-end design round asks for (page transfer time, payload size, request rate, cache offload, DOM size, polling versus a pushed stream), label every input as an assumption, measure one number instead of guessing it, and show how wrong an estimate can be by running a low, base and high case.

    Think of a builder asked "how much paint for this house?" A good one takes the wall area, divides by the coverage on the tin, adds a margin, and says "about twelve litres, and I would buy fifteen". The answer is a little wrong, and the working lets anyone correct it. Front-end estimation is the same habit applied to bytes, requests and DOM nodes.

    The running example is the product list and flash-sale banner of a grocery marketplace (the ShopStream front end used across this course). Every input below is an illustrative assumption, chosen so the arithmetic is easy to follow. None of it is a benchmark. In an interview or a design review you replace each input with the number you were given, or say which one you would measure first.

    The core idea

    1. An estimate is a formula plus labelled inputs. The formula is what the reviewer checks; the inputs are what they argue about. Write both down, in that order.
    2. Estimate to choose between designs, not to predict. "Polling is ten times more requests than we can afford" settles a decision even if the ten is really six or fourteen.
    3. Measure what you can cheaply measure, and bound the rest. A payload size takes one line of code to measure. A peak factor cannot be measured before launch, so it gets a range.

    The performance-budget idea sits underneath this. web.dev defines a performance budget as a set of limits imposed on metrics that affect site performance, and lists three kinds: quantity-based (sizes and counts), milestone timings, and rule-based scores. The six drills mostly produce quantity-based numbers you can turn into a budget; see Performance Budgets and Profiling for how a budget is enforced.

    Figure 1. The estimation loop

    flowchart LR accTitle: The estimation loop accDescr: Five steps in a loop. State the question and the decision it feeds, list inputs and label each as given, measured or assumed, write the formula, compute a low, base and high case, then decide and name the input to measure next. Q["1. Question
    and the decision it feeds"] --> I["2. Inputs
    given, measured or assumed"] I --> F["3. Formula
    units written out"] F --> R["4. Low, base, high
    run the arithmetic"] R --> D["5. Decide
    name the input to measure next"] D -.->|"new data"| I

    How to read this: the loop starts with the decision, not with a number. Step 2 is where interviews are won, because each input carries a label. Step 5 ends by naming what to measure, which turns a guess into a plan.

    Where each drill applies

    Figure 2. Six estimates along one request path

    Where each estimate sits between the user and the originBrowser page to Network link (request); Network link to Shared cache; Shared cache to Origin API (misses); Payload to Network link (size)Browser page: D4 DOM size, D5 connectionsBrowser pageD4 DOM size, D5connectionsNetwork link: D1 transfer timeNetwork linkD1 transfer timeShared cache: D3 offloadShared cacheD3 offloadOrigin API: D3 request rateOrigin APID3 request ratePayload: D2 bytes per rowPayloadD2 bytes per rowrequestmissessize

    How to read this: drills 1 and 2 size what crosses the link, drill 3 counts requests and what the cache removes before the origin sees them, and drills 4 and 5 are about the browser itself. Drill 6 is not a place on the path: it is the habit of running every drill three times.

    Drill 1: transfer time for one page

    The formula has two parts: the time to move the bytes, and the time lost to round trips.

    time = bytes x 8 / bits per second + round trips x RTT

    A byte is 8 bits, and the script uses decimal units (1 KB is 1,000 bytes, 1 Mbit/s is 1,000,000 bits per second) so the sums can be checked by hand. The inputs are assumptions: 300 KB of compressed bytes on the critical path, 4 round trips before the last of those bytes arrives, and two links, a slow mobile one (4 Mbit/s, 150 ms RTT) and a fast home one (50 Mbit/s, 30 ms RTT).

    // Estimation drills. Every input below is ILLUSTRATIVE: replace it with a measurement before you rely on it.
    const KB = 1000; // decimal units, so the arithmetic is easy to check by hand
    const show = (label, value) => console.log(label.padEnd(42), value);
    
    console.log("--- Drill 1: transfer time for one page");
    const link = { name: "slow mobile", mbitPerSec: 4, rttMs: 150 };
    const fast = { name: "fast home", mbitPerSec: 50, rttMs: 30 };
    const transferMs = (bytes, l, roundTrips) => (bytes * 8) / (l.mbitPerSec * 1_000_000) * 1000 + roundTrips * l.rttMs;
    const critical = 300 * KB; // illustrative: compressed bytes on the critical path
    for (const l of [link, fast]) {
      const ms = transferMs(critical, l, 4); // illustrative: 4 round trips before the last byte of the critical path arrives
      show(`${l.name} (${l.mbitPerSec} Mbit/s, ${l.rttMs} ms RTT)`, `${Math.round(ms)} ms`);
    }
    const lcpBudgetMs = 2500; // the "good" LCP threshold published on web.dev
    show("slow link: left of 2500 ms budget", `${Math.round(lcpBudgetMs - transferMs(critical, link, 4))} ms`);

    Output, from running the whole script (all six drills in one file) in Node 26.13.1:

    --- Drill 1: transfer time for one page
    slow mobile (4 Mbit/s, 150 ms RTT)         1200 ms
    fast home (50 Mbit/s, 30 ms RTT)           168 ms
    slow link: left of 2500 ms budget          1300 ms

    By hand: 300,000 bytes is 2.4 Mbit, which takes 0.6 s at 4 Mbit/s; four round trips at 150 ms add 0.6 s, so 1,200 ms. The same page is 168 ms on the fast link (48 ms of transfer plus 120 ms of round trips). Notice that on the fast link the round trips are most of the time: halving the bytes barely helps there, while removing a round trip does.

    The 2,500 ms comes from web.dev, which says LCP should occur within 2.5 seconds of when the page first starts loading, measured at the 75th percentile of page loads, segmented across mobile and desktop. Its guidance on LCP also splits the time into four parts and suggests roughly 40% for time to first byte, under 10% for resource load delay, about 40% for resource load duration and under 10% for element render delay. That is a guideline, not a rule, but it is a quick sanity check: if transfer alone eats 1,200 ms of 2,500 ms, the rest of the chain has 1,300 ms. LCP Optimization goes through each part.

    Figure 3. One illustrative latency budget

    flowchart LR accTitle: An illustrative latency budget for the slow link accDescr: The 2500 millisecond LCP budget on the slow link. Transfer and round trips take 1200 milliseconds in the estimate, leaving 1300 milliseconds for the server response, render delay and everything else the estimate left out. B["LCP budget
    2500 ms"] --> T["Transfer + 4 round trips
    1200 ms (estimate)"] B --> L["Left for server time,
    render delay, everything not modelled
    1300 ms"]

    How to read this: the estimate does not predict LCP. It shows how much of a fixed budget one known cost uses, which is what tells you whether to attack bytes, round trips or the server first.

    Drill 2: measure one payload instead of guessing

    Row size is a number a few lines of code can measure. Build a representative list item, serialise it, and count the UTF-8 bytes: MDN says TextEncoder encodes a string using UTF-8 and encode() returns a Uint8Array, so its length is the byte count. Then compress it. Servers send compressed bodies with a Content-Encoding header such as gzip, and MDN notes that compressing already-compressed media such as images is usually not appropriate because it can increase the size.

    console.log("--- Drill 2: measure one payload instead of guessing");
    const rows = Array.from({ length: 50 }, (_, i) => ({
      id: `P-${String(1000 + i)}`,
      name: `Product ${i} with a short description`,
      priceCents: 199 + i * 7,
      inStock: i % 3 !== 0,
      tags: ["grocery", i % 2 ? "organic" : "bulk"],
    }));
    const json = JSON.stringify(rows);
    const rawBytes = new TextEncoder().encode(json).length;
    const { gzipSync } = await import("node:zlib");
    const gzBytes = gzipSync(json).length;
    show("50 rows, JSON bytes (UTF-8)", rawBytes);
    show("bytes per row", (rawBytes / rows.length).toFixed(1));
    show("same JSON after gzip", gzBytes);
    show("page of 200 rows, raw (linear)", Math.round((rawBytes / rows.length) * 200));
    --- Drill 2: measure one payload instead of guessing
    50 rows, JSON bytes (UTF-8)                6033
    bytes per row                              120.7
    same JSON after gzip                       593
    page of 200 rows, raw (linear)             24132

    These 50 rows are synthetic and repetitive, so the gzip ratio (6,033 to 593 bytes) says nothing about a real catalogue; real data compresses less. What the run gives you is a method and a per-row figure for this row shape: about 121 bytes. The Node documentation notes that the compression level trades speed for ratio, so the ratio also depends on server configuration.

    Drill 3: request rate and what a cache removes

    Daily totals hide the number that sizes a service: the busy second. The formula chain is users x sessions x pages x calls per page, divided by the seconds in the active window, times a peak factor.

    console.log("--- Drill 3: request rate and what a cache removes");
    const traffic = { dailyUsers: 200_000, sessionsPerUser: 2, pagesPerSession: 6, apiCallsPerPage: 4 };
    const callsPerDay = traffic.dailyUsers * traffic.sessionsPerUser * traffic.pagesPerSession * traffic.apiCallsPerPage;
    const activeSeconds = 12 * 3600; // illustrative: traffic is spread over 12 busy hours
    const avgRps = callsPerDay / activeSeconds;
    const peakFactor = 4; // illustrative: the busiest second is 4 times the average
    const peakRps = avgRps * peakFactor;
    show("API calls per day", callsPerDay.toLocaleString("en-US"));
    show("average calls per second", avgRps.toFixed(1));
    show("peak calls per second (x4)", peakRps.toFixed(1));
    for (const hit of [0.5, 0.9, 0.99]) show(`origin peak at ${hit * 100}% cache hits`, (peakRps * (1 - hit)).toFixed(1));
    --- Drill 3: request rate and what a cache removes
    API calls per day                          9,600,000
    average calls per second                   222.2
    peak calls per second (x4)                 888.9
    origin peak at 50% cache hits              444.4
    origin peak at 90% cache hits              88.9
    origin peak at 99% cache hits              8.9

    The cache line is the point: going from a 90% to a 99% hit ratio cuts the origin's peak tenfold, so a small improvement in hit ratio is worth more than it looks. The ratio itself is an input you cannot know before launch; see CDN and Edge Caching for what decides it. The server-side half of this arithmetic, with headroom and saturation, is in Capacity Planning; the front end's job is the call count per page, which the browser controls.

    Drill 4: rows on screen versus rows in the DOM

    Memory and layout cost follow the number of DOM elements, so count them. Lighthouse's DOM-size audit warns when the body element has more than about 800 nodes and errors above about 1,400; its page gives memory and style recalculation as reasons large DOMs hurt. Those thresholds are for the whole body, so a list is only part of the budget.

    console.log("--- Drill 4: rows on screen versus rows in the DOM");
    const dom = { rows: 10_000, elementsPerRow: 12, windowRows: 30, overscanRows: 10 };
    const allNodes = dom.rows * dom.elementsPerRow;
    const windowNodes = (dom.windowRows + dom.overscanRows) * dom.elementsPerRow;
    show("elements, every row rendered", allNodes.toLocaleString("en-US"));
    show("elements, windowed (30 + 10 spare)", windowNodes);
    show("windowed versus Lighthouse warn (~800)", windowNodes <= 800 ? "under" : "over");
    show("full list versus Lighthouse error (~1400)", allNodes > 1400 ? `${(allNodes / 1400).toFixed(0)}x over` : "under");
    --- Drill 4: rows on screen versus rows in the DOM
    elements, every row rendered               120,000
    elements, windowed (30 + 10 spare)         480
    windowed versus Lighthouse warn (~800)     under
    full list versus Lighthouse error (~1400)  86x over

    The estimate gives no milliseconds; that needs a profile on a real device. It does show that only the windowed list can fit the audit's range, which justifies List Virtualization before building anything.

    Drill 5: polling versus a pushed stream

    Take 5,000 people watching the flash-sale banner, 2 updates per second, 300 bytes per update, 800 bytes of request and response headers (all assumptions), and a poll every 5 seconds. A poll reply carries every update since the last poll, 10 updates here.

    console.log("--- Drill 5: polling versus a pushed stream");
    const live = { watchers: 5000, pollEverySec: 5, headerBytes: 800, updateBytes: 300, updatesPerSec: 2 };
    const pollRps = live.watchers / live.pollEverySec;
    const pollBytesPerSecPerUser = (live.headerBytes + live.updateBytes * live.updatesPerSec * live.pollEverySec) / live.pollEverySec; // one reply carries every update since the last poll
    const pushBytesPerSecPerUser = live.updateBytes * live.updatesPerSec;
    show("polling: requests per second", pollRps);
    show("polling: bytes/s per user", pollBytesPerSecPerUser.toFixed(0));
    show("push: messages per second, total", live.watchers * live.updatesPerSec);
    show("push: bytes/s per user (no framing)", pushBytesPerSecPerUser);
    show("push: open connections", live.watchers);
    show("slowest fresh data: polling", `${live.pollEverySec} s`);
    --- Drill 5: polling versus a pushed stream
    polling: requests per second               1000
    polling: bytes/s per user                  760
    push: messages per second, total           10000
    push: bytes/s per user (no framing)        600
    push: open connections                     5000
    slowest fresh data: polling                5 s

    Three readings. Bytes per user are close (760 against 600, and the push figure leaves out message framing, which the script does not model), so the stream does not save bandwidth; it saves 1,000 requests per second and up to 5 seconds of staleness. Push has its own bill: 10,000 messages per second to fan out and 5,000 open connections to hold. And a browser limit can decide the question before any arithmetic does: MDN warns that without HTTP/2, server-sent events are limited to about 6 open connections per browser and domain, shared across tabs, while over HTTP/2 the negotiated stream limit defaults to 100. Polling, SSE and WebSockets and Server-Sent Events in Depth cover the transports.

    Figure 4. Same viewers, two bills

    5,000 watchers: polling versus a pushed stream (illustrative inputs)Polling clients to Poll endpoint (request + reply); Stream clients to Fan-out service (one long request)Polling clients: every 5 sPollingclientsevery 5 sPoll endpoint: 1,000 requests/sPoll endpoint1,000 requests/sStream clients: 5,000 open connectionsStream clients5,000 openconnectionsFan-out service: 10,000 messages/sFan-outservice10,000 messages/srequest + replyone long request

    How to read this: the warning boxes are where each design pays. Polling pays in request rate and staleness, the stream pays in held connections and fan-out. The estimate tells you which bill your team can afford.

    Drill 6: how wrong can the answer be?

    Run every estimate with a low, base and high set of inputs. The same chain as drill 3, with visitors, pages per session and calls per page varied:

    console.log("--- Drill 6: how wrong can the answer be?");
    for (const [label, users, pages, calls] of [["low", 150_000, 5, 3], ["base", 200_000, 6, 4], ["high", 300_000, 8, 5]]) {
      const perDay = users * traffic.sessionsPerUser * pages * calls;
      show(`${label}: peak calls per second`, ((perDay / activeSeconds) * peakFactor).toFixed(1));
    }
    --- Drill 6: how wrong can the answer be?
    low: peak calls per second                 416.7
    base: peak calls per second                888.9
    high: peak calls per second                2222.2

    Three inputs, each moved modestly, move the answer more than fivefold from low to high. That spread is the finding: say "about 900, between 400 and 2,200", and name the input that drives it (here, calls per page, which the front-end team controls).

    Trade-offs

    Choice Gain Cost
    Estimate with round numbers Fast, easy to check aloud Hides error; keep the range visible
    Measure a sample payload A real per-row figure The sample may not be representative
    Use decimal units (1 KB = 1,000 bytes) Easy mental arithmetic A few percent off tools that report 1,024
    Quote a published threshold Shared vocabulary with the reviewer It is a guideline for a stated condition, not your users
    Present one number Short Sounds precise, and invites an argument about the wrong thing

    Build it

    This lesson has no lab. The six drills are one Node file, run as a script with no install (node drills.mjs). It was run twice with byte-identical output, and the output blocks above are that text, split by drill. The only measured values are the JSON and gzip sizes of the synthetic rows in drill 2.

    Verified. The arithmetic of drills 1, 3, 4, 5 and 6 was also checked by hand. Browser timings, real traffic and real compression ratios were not measured.

    In practice: sizing a flash-sale page

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    The marketplace plans a flash-sale page with a countdown and a live "units left" figure for each of 40 products. Product asks for "real time". Engineering has a day to say whether the existing polling pattern is enough or a stream is needed, and whether the list needs windowing.

    Starting architecture

    Figure 5. Today: every client polls

    Starting architecture: client pollingSale page to Shared cache (poll); Shared cache to Stock API (misses)Sale page: 40 productsSale page40 productsShared cache: short expiryShared cacheshort expiryStock API: units leftStock APIunits leftpollmisses

    How to read this: the warning box is the part whose load depends on an input nobody has measured, the cache hit ratio for a one-second-fresh response.

    Options considered

    Option What the estimate says What it costs Risk
    Poll every 5 s 1,000 requests per second at 5,000 watchers No new infrastructure Depends on the hit ratio; data up to 5 s old
    One stream per page 5,000 connections, 10,000 messages per second A fan-out service Connection limits, reconnect storms
    Poll one batched endpoint for all 40 products One request per poll instead of 40 A new response shape The batch is a single point of failure

    The decision

    Field Decision record
    Context 5,000 expected watchers and 40 products, all inputs assumed; the estimate spread (low to high) is above 5x.
    Decision Poll one batched endpoint every 5 s behind the shared cache, window the product list, and measure the hit ratio and calls per page in a pre-launch test.
    Consequences, good No new service; the call count per page falls from 40 to 1; staleness is bounded and stated.
    Consequences, bad Up to 5 s old data; a flash-sale spike can exceed the high case.
    Revisit when The measured hit ratio is under what the origin can absorb at the high case, or product needs fresher data than 5 s.

    Rollout and verification

    1. Write the inputs as a table, each labelled given, measured or assumed, with low, base and high values.
    2. Measure what is cheap: the batched response size from a real sample and the rendered element count.
    3. Load-test the origin at the high case and record the hit ratio the cache really delivers.
    4. Re-run the drills with measured values and update the decision record.

    The 2 a.m. failure

    The sale opens and traffic is at the high case, above the base by more than the peak factor assumed. The cache hit ratio is far below the assumed value because every response carries a per-user header that makes it uncacheable, so the origin takes the full call rate.

    First three checks: (1) compare the measured hit ratio with the one in the estimate; (2) check which response headers vary the cache key; (3) look at calls per page in the real client. Mitigation: serve the batched response without per-user fields and lengthen the poll interval. Follow-up: add the hit ratio to the launch checklist as a measured input.

    Architect's notes

    • Label every input. A reviewer who cannot tell assumed from measured cannot help you.
    • Estimate the busy second, not the day. Daily totals hide the number that sizes things.
    • Move the range, not just the point. If the high case breaks the design, the base case was never the question.
    • Prefer a drill that points at a decision. "Windowed list fits the DOM budget" beats "120,000 elements".

    Common mistakes

    • Mixing units, such as megabytes with megabits per second.
    • Quoting a published threshold as if it were your users' behaviour.
    • One number, no range.
    • Forgetting round trips, which dominate on fast links.
    • Treating a synthetic sample's compression ratio as the production ratio.
    • Missing a browser limit that decides the design, such as the per-domain cap on server-sent events over HTTP/1.1.

    Key takeaways

    • An estimate is a formula with labelled inputs; the working matters more than the answer.
    • bytes x 8 / bits per second + round trips x RTT explains most page-transfer questions.
    • Measure cheap numbers (payload bytes, element counts) and bound expensive ones (peak factor, hit ratio).
    • Size for the busy second and the high case.
    • Polling and push trade requests and staleness against held connections and fan-out.
    • Say the spread: "about 900, between 400 and 2,200".

    Practice exercises

    Exercise 1: Starter (30 min). Change the slow link in drill 1 to 10 Mbit/s with the same RTT and 4 round trips. Predict the transfer time by hand, then run it. How much of the change came from bytes and how much from round trips?

    Exercise 2: Intermediate (2 hours). Replace the synthetic rows in drill 2 with a response from a public API of your choice. Report bytes per row, gzip size and what you could not conclude from one sample.

    Exercise 3: Advanced (half day). Write the estimate for a chat page with 20,000 concurrent users: connections, messages per second, bytes per user and one browser limit that matters. Label each input and give a low, base and high case.

    In this course:

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments