---
title: "Discussion on \"Web Workers vs Shared Workers vs Service Workers: A Practical Guide to Choosing the Right One\" | Hashnode"
description: "Discussion on \"Web Workers vs Shared Workers vs Service Workers: A Practical Guide to Choosing the Right One\". TL;DR: Choose a dedicated Web Worker for expensive work needed by one page, a Shared Worker for live coordination among same-origin tabs, and a Service Worker for request interception and offline behavior. They can work together, but none is a permanent background process or a substitute for persistent storage."
url: "https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Web Workers vs Shared Workers vs Service Workers: A Practical Guide to Choosing the Right One](https://blogs.arunkumarvelu.com/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one?utm_source=hashnode&utm_medium=feed)

TL;DR: Choose a dedicated Web Worker for expensive work needed by one page, a Shared Worker for live coordination among same-origin tabs, and a Service Worker for request interception and offline behavior. They can work together, but none is a permanent background process or a substitute for persistent storage.

Oct 7 · 14 min read · blogs.arunkumarvelu.com  
Updated Oct 8  
Read the article

-   [#webworker](https://hashnode.com/tag/webworker)
-   [#serviceworker](https://hashnode.com/tag/serviceworker)
-   [#sharedworker](https://hashnode.com/tag/sharedworker)
-   [#workers-js](https://hashnode.com/tag/workers-js)

## Written by

[Arun kumar Velu](https://hashnode.com/@arunkumarvelu)

@arunkumarvelu · Chennai, India

  
[View profile](https://hashnode.com/@arunkumarvelu)

#web\_engineer, #frontend

I love to do stuff in web

## Responses 5

Markdown supported · ⌘↵ to post

[Akhila Sharon N.](https://hashnode.com/@akhila-003)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac78ab96036317a6ec56049)

Solid guide on threading models in the browser. Unloading heavy background tasks to keep the main thread free for UI responsiveness makes a massive difference in user experience. I would love to know if you have benchmarked WebAssembly running inside Web Workers for heavy mathematical tasks, and if thread instantiation overhead ever impacted your initial startup time.

[Arun kumar Velu](https://hashnode.com/@arunkumarvelu)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac78ab96036317a6ec56049#reply-6ac78e2fb04c802520c596fe)

I haven’t benchmarked WebAssembly inside a Web Worker for this post, so I wouldn’t claim a performance improvement yet. It would be interesting to measure worker startup, Wasm loading/initialization, and computation separately, then compare them with JavaScript on the main thread and JavaScript in a worker. My expectation is that startup costs matter more for short, one-off tasks, while reusing an initialized worker may make more sense for repeated heavy calculations—but I’d want measurements for the specific workload before drawing a conclusion.

[Jam Yanh](https://hashnode.com/@danagua)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5)

The request-ID example is useful. A cancellation example would be a nice follow-up: in an image tool, a user might choose a second file while the first is still being processed. How would you stop that first job without terminating the worker and losing its other pending jobs?

[Arun kumar Velu](https://hashnode.com/@arunkumarvelu)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5#reply-6ac78cc52f2b39f099cb38b7)

a cancellation message cannot interrupt a synchronous JavaScript loop already running in that worker. The worker must divide expensive work into chunks and yield between them, giving its event loop a chance to receive the cancellation message. setTimeout() is one way to schedule the next chunk; repeatedly awaiting Promise.resolve() is not an equivalent yield to incoming message events because microtasks run before the next task.

[Jam Yanh](https://hashnode.com/@danagua)

[Oct 9](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5#reply-6ac8c9505292935f39485a14)

Thanks, the distinction between yielding to a new task and only flushing microtasks is especially helpful. For an image-processing example, measuring cancellation delay alongside total processing time would make the chunk-size tradeoff easier to see.
