Classic case studies · senior
Case study: poll/quiz widget and embeddable widgets
A strong embeddable-widget design picks the embed method (script SDK, iframe or web component) for isolation, keeps the host page fast and safe, lets the server enforce one vote per user and compute results, and shows live results without trusting the client.
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
- Embed options: a tiny async loader script with a command queue (window.widget = window.widget || []), an iframe (strong isolation of styles, scripts and data; resize via postMessage), or a Web Component with Shadow DOM (style isolation, same JS realm).
- Host-page safety: one global namespace only, no CSS leaks, CSP and SRI, strict postMessage origin checks both ways, a size budget, lazy load when the widget scrolls into view.
- Poll data: { pollId, question, options: [{ id, text, votes }], totalVotes, endsAt, userVote }. API: GET /polls/:id, POST /polls/:id/votes with an idempotency key; the server enforces one vote per user or device.
- Results: show percentages that add up to 100 (largest-remainder rounding); update live with polling + backoff or SSE; throttle UI updates.
- Optimistic vote with rollback; disable double submit; show results after voting (or after the poll ends).
- Quiz: use server time for the timer, check answers on the server, never send answer keys to the client.
- Accessibility: options as a radio group, results as text not only bars and colours, a polite live region for result changes.
- Analytics and versioning: impressions and votes via sendBeacon; versioned CDN URLs with semver so embedders aren't broken.
The red pen
Common traps: mistake → fix
Mistake: Count votes on the client
Fix: trivially faked.
Mistake: Inject widget CSS into the host page
Fix: it breaks the host's styles (and vice versa).
Mistake: Send quiz answers with the questions
Fix: anyone can read them in DevTools.
Mistake: Accept postMessage from any origin
Fix: any page can drive your widget.
Easy to hard
Questions interviewers ask, easy to hard
- Design a poll widget that publishers embed on their articles.
- Script tag, iframe or web component? Why?
- How do you stop one person voting 100 times?
- Results update live for 1 million readers. How?
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.