The PDF that eats a core
OCR, transcoding, big parses — CPU-bound work runs in its isolate while the main event loop keeps serving traffic.
Run untrusted or CPU-heavy logic in dedicated V8 isolates. A crash in a worker never crashes the host. When a worker stops, the OS reclaims 100% of its memory — we call it the Guillotine.
Each worker runs in its own Node.js worker thread with a private V8 heap. Variables are private, memory is isolated, and thread death is not process death — reliability and responsiveness stop competing with your business logic.
A strict state machine governs every instance: INACTIVE → ACTIVE_FOREGROUND / ACTIVE_BACKGROUND → SUSPENDED → TERMINATING → TERMINATED. Each instance has a pid and an alias, addressable globally or by name. Spawn, activate, suspend, resume, signal, stop — the lifecycle is the API.
Communication uses a correlation-ID protocol: every command carries a monotonic message id, and responses resolve their exact promise. Multiple commands can be in flight without ever mixing up their answers.
class InvoiceWorker extends BaseWorker {
async activateBackground(ctx) {
const { payload, logger } = ctx;
logger.info('Processing…');
const result = await this.settle(payload);
return { ok: true, data: result, port: 'done' };
}
}
// spawn → activate → stop. Memory returns to zero. OCR, transcoding, big parses — CPU-bound work runs in its isolate while the main event loop keeps serving traffic.
Run integration logic in a worker. If it leaks, loops or dies, the guillotine cleans up and the host never notices.
Ephemeral workers spawn, run and terminate. Because memory reclaim is total, the ten-thousandth job runs like the first.