Context
At companies like Netflix, backend services often need concurrency for handling many requests, doing background work, or parallelizing CPU-heavy tasks. Choosing between processes and threads affects performance, safety, and operational complexity.
Question
Explain the difference between a process and a thread.
In your answer, cover:
- Resource model: what is shared vs isolated (address space, file descriptors/handles, heap/stack).
- Scheduling and overhead: creation cost, context switching, and how this impacts throughput/latency.
- Failure and security boundaries: what happens when one unit crashes or misbehaves.
- Communication: how processes coordinate (IPC) vs threads coordinate (shared memory + synchronization).
- When to use which: give 2–3 concrete scenarios (e.g., CPU-bound work, I/O-bound work, sandboxing/untrusted code, avoiding global interpreter locks).
Scope guidance
Assume a modern OS (Linux/macOS/Windows). You don’t need kernel-level implementation details, but you should be precise about isolation, synchronization primitives, and practical trade-offs in real systems.