A process is a running program with its own virtual address space, open files and other operating system resources. A thread is a path of execution inside a process; every process has at least one, and all threads of a process share its memory and file descriptors while keeping their own stack and registers. Processes are isolated from each other, so a crash in one does not corrupt another, and they talk through inter-process communication such as pipes, sockets or explicitly shared memory. Threads are cheaper to create and to switch between, and they talk by reading and writing the same memory, which is fast but needs locks or atomics to stay correct. Reach for processes when you need isolation and fault containment, and for threads when you want cheap concurrency over shared state.
A process and a thread both run your code. The difference is what they share. A process gets its own address space. Here are two processes, each with its own copy of a counter. When one changes it, the other never sees the change. That isolation is the point. If one process crashes, the other keeps running. To talk, they need a pipe, a socket, or memory they share on purpose.
Threads live inside one process. Each thread has its own stack and registers, but they all share the heap. So two threads can both read the counter at 41, both add one, and both write back 42. One update is lost. That is a race condition. A lock fixes it. One thread holds the lock, the other waits its turn, and the counter correctly reaches 43.
And because threads share everything, one bad pointer in any thread can take down the whole process. So, use processes for isolation, like PostgreSQL with a process per connection, or a browser isolating sites. Use threads to share memory cheaply, like a Java server with a thread pool. Isolation, or cheap sharing. That is the trade.
| Aspect | Process | Thread |
|---|---|---|
| Memory | Own virtual address space | Shares the address space of its process; own stack and registers |
| Creation cost | Higher: new address space and page tables (fork uses copy-on-write to soften this) | Lower: a stack and a kernel scheduling entity |
| Context switch | Switches address space, which also disturbs the TLB and caches | Cheaper between threads of the same process, since memory mappings stay the same |
| Communication | Pipes, sockets, message queues, shared memory segments | Shared variables, guarded by mutexes, atomics or channels |
| Failure isolation | A crash usually stays inside the process | A segfault or fatal error in one thread takes down the whole process |
| Security boundary | Yes: the OS enforces separation and can apply different privileges | None between threads of the same process |
| Real examples | PostgreSQL forks a backend process per connection; browsers isolate sites in renderer processes | Java servers run requests on a thread pool; MySQL serves each connection on a thread |
Use processes when
You run untrusted or crash-prone code and one failure must not take the others down.
Use threads when
Tasks share large in-memory state such as caches, connection pools or a model loaded once.
Many runtimes add a lighter layer on top of operating system threads. Go schedules goroutines onto a small pool of OS threads, and each goroutine starts with a stack of a few kilobytes, so a server can hold far more goroutines than it could hold OS threads. Node.js and Python asyncio go further and run many tasks on a single thread, switching only when a task waits on I/O.
These are still threads or processes underneath. The question an interviewer cares about is the same: how much memory does each in-flight request cost, what happens when one of them blocks, and what is shared between them.
PostgreSQL uses a process per client connection. That gives strong isolation, but each connection carries real memory overhead, which is why busy PostgreSQL deployments put a pooler such as PgBouncer in front and keep the server-side connection count modest. MySQL serves connections on threads instead, which makes each connection cheaper. Knowing this lets you explain why a fleet of stateless app servers should share a connection pool rather than each opening hundreds of connections.
You will rarely be asked to define a process in a system design round. The distinction shows up when you size a server, choose a worker model, or explain why a component falls over. Interviewers listen for whether you know what each in-flight unit of work costs and what a single failure takes down with it.
“Each fetcher host runs a few worker processes, one per core, and each process runs an async event loop with a few hundred in-flight requests. Processes give us isolation if a parser crashes on a bad page, and the event loop keeps memory per request small because most of the time is spent waiting on the network.”
Yes. Every process starts with one thread, and it can create more. All of them share the process memory and open files, and each has its own stack, registers and program counter.
In most runtimes a fatal error such as a segmentation fault terminates the entire process, so every thread in it dies. Some managed runtimes let an uncaught exception end only the thread that threw it, but shared state may be left inconsistent.
Most production servers use both. A common layout is one worker process per CPU core for isolation and parallelism, with threads or an event loop inside each worker to handle many concurrent requests.
Threads of one process can run at the same time on different cores. The exception is a runtime with a global lock, such as the standard CPython build, where only one thread executes Python bytecode at a time.
How the OS schedules threads, what a context switch costs, and why thread count is not throughput.
A real process-per-connection server and the shared memory its backends coordinate through.
How one thread serves thousands of sockets.
What goes wrong when threads share memory without coordination.
Worker processes, fetch concurrency and per-host politeness.
Model processes, threads and scheduling policy as classes.
Distributed workers, leases and what happens when a worker dies.
Millions of long-lived connections and the memory each one costs.
Knowing the trade-off is half of it
Practise saying it under follow-up questions: a timed system design interview with an AI interviewer that probes your choices and grades against a rubric.