Questions
6 of 20
1What is a Web Worker and why do we need it? What problem does it solve in the browser?
2What are the three types of Web Workers? How do they differ from each other?
3How do you create a Web Worker and communicate with it?
4What is the postMessage / onmessage pattern? Is communication synchronous or asynchronous?
5What APIs and features are not available inside a Web Worker? (e.g., DOM, window, document)
6What is the Structured Clone Algorithm? How is it different from JSON serialization? What types can and cannot be cloned?
7What are Transferable Objects? How does transferring an ArrayBuffer differ from cloning it, and why does it matter for performance?
8How do you handle errors inside a Web Worker? What events are available and what information do they expose?
9What is a Shared Worker? How can multiple browser tabs communicate through one? What are its limitations?
10How do you terminate a Web Worker? What's the difference between worker.terminate() and self.close()?
11How would you architect a thread pool using Web Workers to process a large task queue efficiently?
12What is SharedArrayBuffer and Atomics? How do they enable true shared memory between the main thread and workers? What security headers are required to use them?
13What are the performance trade-offs of using Web Workers? When can they actually hurt performance (e.g., small tasks, frequent postMessage calls)?
14How would you use Web Workers with WebAssembly (WASM) for CPU-intensive tasks? What makes this combination powerful?
15How do Module Workers work (type: 'module')? What advantages do they offer over classic workers?
16In a React or Vue app, how would you integrate a Web Worker cleanly without breaking the component lifecycle? Have you used libraries like comlink — how does it simplify the worker communication model?
17What is the lifecycle of a Service Worker (install → activate → fetch)? How do you handle cache versioning and old worker cleanup?
18What is the difference between cache.put(), cache.add(), and cache.addAll()? How do you implement a cache-first vs network-first strategy?
19How do you communicate between a Service Worker and the main thread? What is the role of BroadcastChannel vs postMessage here?
20Can Web Workers access localStorage?
06 / 20

What is the Structured Clone Algorithm? How is it different from JSON serialization? What types can and cannot be cloned?

Difficulty: 5/10
structured clone, serialization, data types

Structured cloning copies complex objects recursively, preserving cycles and supporting more types than JSON (e.g., Map, Set, Date, RegExp). Cannot clone Function, DOM nodes, Error objects.

postMessage uses structured clone, which handles cyclical references, typed arrays, and many built-in objects. JSON serialization fails on cycles and unsupported types (e.g., undefined, Map, Set). Structured clone is more powerful but cannot clone functions, DOM elements, or certain system objects.

Scenario Questions

0-2 years experience

  1. 1You need to send an object containing a Date and a Map from a Web Worker back to the main thread using postMessage. How would you do it, and what would happen if you tried to use JSON.stringify instead?
  2. 2Given an array with a nested Set, you want to clone it for local manipulation without affecting the original. Which API would you use and why?

2-5 years experience

  1. 1Your team added a feature that stores user preferences in IndexedDB using structuredClone before saving. After a recent update, some preferences are missing. Walk me through how you'd debug the issue.
  2. 2We need to transfer a complex object (including Blob, RegExp, and circular references) between an iframe and its parent. Explain the trade‑offs between using structured cloning via postMessage versus manually serializing to JSON.

5-8 years experience

  1. 1Design a cross‑origin messaging layer that synchronizes state between multiple browser tabs. How does the choice of structured clone affect performance and memory, and what fallback would you provide for environments that lack it?
  2. 2Our real‑time collaboration service serializes operation objects to send over WebSocket. Some operations include functions and prototype methods. How would you redesign the serialization strategy, considering structured clone limitations?

8+ years experience

  1. 1We are migrating a legacy codebase that heavily relies on JSON.stringify for persisting objects to a new architecture that uses the structured clone algorithm for worker communication and IndexedDB storage. What architectural changes, testing strategies, and migration steps would you propose to ensure data integrity across the system?
  2. 2At a platform level, we need to support both browsers that implement the structured clone algorithm and older ones that don't. How would you design an abstraction layer that gracefully degrades, and what are the long‑term maintenance implications?

Follow-up Questions

  • Can you name a type that structured clone supports but JSON.stringify cannot?
  • What happens to prototype chains when an object is cloned with the structured clone algorithm?
  • Are there any security concerns when cloning objects across origins?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.