Trade-offs: Isolation vs Performance at Scale
The Isolation vs Performance Spectrum
Running everything in a single thread gives maximum performance for shared data but zero isolation. Running each task in its own process gives maximum isolation but incurs IPC overhead for every interaction. Real systems choose based on communication frequency, crash impact, and code trust level.
Quantifying the Communication Tax
Threads communicate in nanoseconds; processes via sockets in microseconds, roughly 1000x slower. At one million messages per second:
With threads: 1M × 100ns = 100ms overhead per second.
With processes: 1M × 5μs = 5 seconds overhead, consuming 500% of a CPU core.
Below 10,000 messages per second, IPC overhead is under 5% of a core. Above 100,000, IPC becomes a significant bottleneck.
Crash Containment Math
Thread crashes kill the entire process. At 1000 RPS with 500ms restart time, one crash drops 500 in flight requests.
With 10 process workers at 100 RPS each, a crash drops only 50 requests, 10x fewer.
Security Boundaries
Threads share all memory; any thread can read any data. Processes provide actual security boundaries enforced by the OS. For multi tenant systems, processes offer stronger isolation guarantees.