Choosing Between Threads and Processes
Choose Processes When Safety Matters
Running code you do not trust? Put it in a separate process. Browser tabs run untrusted JavaScript. Each tab gets its own process so a malicious site cannot steal data from other tabs.
Need to contain crashes? Use processes. If a web server worker crashes handling a bad request, only that request fails. Other workers keep serving.
Choose Threads When Speed Matters
Need to share big data? Use threads. A database has gigabytes of cached data. All query handlers need access. Copying that between processes would be absurdly slow.
Doing parallel math? Use threads equal to your CPU cores. 8 cores means 8 threads. More threads just waste time switching.
Real Systems Use Both
Chrome: Process per tab (isolation) + threads within each tab (efficiency). Nginx: Worker processes (isolation) + async IO within each. Databases: Shared buffer pool via threads + separate processes for crash isolation.