Testing a UI feature and estimating · senior
Estimating polling load, offline storage and WebSocket servers
Estimates for requests, storage and connections need assumptions, simple arithmetic and a list of the cuts you would apply. You also name the failure to plan for, such as a reconnect storm.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Polling: 30,000 users x 4 widgets / 5 s = 24,000 requests a second. If about 60% of tabs are hidden and polling pauses when document.visibilityState is hidden, about 9,600 a second remain.
- Batching: one endpoint for all four widgets gives 30,000 x 0.4 / 5 = 2,400 a second. Conditional requests (ETag with If-None-Match returning 304) or "changes since" cursors make most responses tiny. Slow down when idle (5 s active, 30 s idle) with jitter.
- After an outage every client retries at once: use backoff with jitter and Retry-After. Server-sent events or WebSockets move the cost from requests to connection memory and fan-out. Browsers allow about 6 HTTP/1.1 connections per host; HTTP/2 multiplexes.
- Offline storage: 5,000 products x about 2 KB = 10 MB; 2,000 customers x 1 KB = 2 MB; orders 40 a day x 5 KB = 200 KB a day, 30 days about 6 MB. All 5,000 thumbnails at 40 KB is 200 MB, too much; cache the top 500 (about 20 MB) and load the rest on demand. Total about 40 to 50 MB; set a budget of about 100 MB.
- Storage tools: React Native uses SQLite for data and the file system for images (MMKV only for small values). Web uses IndexedDB. Chromium lets one origin use up to about 60% of the disk. Safari deletes script-written storage after 7 days without user interaction unless the site is a home-screen web app. navigator.storage.persist() asks for persistence and navigator.storage.estimate() shows usage. Show usage in settings and handle "storage full".
- WebSockets: 1 million connections plus about 20% headroom; at about 50,000 mostly idle connections per instance (20 to 50 KB each, about 1 to 2.5 GB), that is about 20 to 25 instances plus spare for failures and deploys. One update every 4 s per order is about 250,000 messages a second out, fanned out through pub/sub (Redis, NATS or Kafka) keyed by order id.
- Reconnect storm: a deploy or network blip makes a million clients reconnect at once. Spread them with jittered backoff and drain servers one at a time. Managed limits matter: AWS API Gateway WebSockets default to 500 new connections a second per account per region, a 2-hour maximum connection time and a 10-minute idle timeout, so a million reconnects take about 33 minutes.
- Alternatives: server-sent events for one-way updates, polling every 10 to 15 s for low-priority screens, and push notifications while the app is in the background. On mobile the OS suspends sockets, so reconnect on foreground and fetch the latest state first. Load test with k6 or Artillery and measure p99 delivery delay.
The red pen
Common traps: mistake → fix
Mistake: Polling every 5 seconds is cheap
Fix: multiply by users and widgets; it adds up fast.
Mistake: WebSockets remove server cost
Fix: they move it to connection memory and fan-out.
Mistake: Offline data is small
Fix: images can be 20 times the rest; budget them.
Easy to hard
Questions interviewers ask, easy to hard
- Estimate the requests per second from a polling dashboard with 30,000 users.
- How much local storage does an offline-first sales app need?
- How many servers do you need for 1 million WebSocket connections?
- What is a reconnect storm and how do you prevent it?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.