Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Process vs Thread
Engineering~9 min readComparison
Head to Head

Process vs thread: isolated, or shared memory?

ProcessvsThread

Both let a program do more than one thing at a time, but they differ on the single most consequential question in systems: do they share memory? A process gets its own private world — safe, but expensive to talk across. Threads share one world — fast to coordinate, until two of them touch the same thing at the same time.

01

The one distinction that decides everything

A process is an independent running program with its own isolated memory space — one process cannot read or corrupt another’s memory, and they communicate only through explicit channels (pipes, sockets, shared-memory segments). A thread is a unit of execution inside a process, and all threads in a process share the same memory — the same heap, the same globals, the same open files. That one difference — isolated versus shared memory — cascades into everything: how expensive they are to create, how they communicate, and what happens when one of them crashes.

→ The rule

Want isolation, fault tolerance, or true multi-core parallelism (especially where a runtime lock limits threads)? Reach for processes. Want cheap, fast, shared-memory concurrency where the tasks cooperate closely? Reach for threads. Isolation vs shared state is the whole trade.

02

Head to head

DimensionProcessThread
MemoryOwn private, isolated spaceShared with sibling threads
IsolationStrong — can’t touch others’ memoryNone — shares everything
Creation costHeavy (new address space)Light (within an existing one)
Context-switch costHigher (swap address space, TLB)Lower (same address space)
CommunicationIPC — pipes, sockets, shared mem (serialize)Direct — just read/write shared memory
If one crashesOnly that process diesCan take down the whole process
SynchronizationRarely needed (isolated)Required — locks, races, deadlocks
Multi-core parallelismYes, alwaysYes — unless a runtime lock (e.g. Python GIL) blocks it
03

When to use each

Reach for processes

  • You need isolation — a crash or bug must not spread
  • Security boundaries (sandbox untrusted work in its own process)
  • CPU-bound parallelism, especially under a GIL (Python)
  • Independently deployable/restartable workers
  • When simplicity of "no shared state" beats communication cost

Reach for threads

  • Tasks that share a lot of data and coordinate closely
  • IO-bound work (waiting on network/disk) needing concurrency
  • Low creation/switching overhead matters (many short tasks)
  • A responsive UI thread plus background workers
  • When cheap, direct shared-memory communication is a win
04

The answer is usually a mix (plus a third option)

Real systems combine them. A common shape: run several worker processes for isolation and true multi-core parallelism (one crashing worker doesn’t kill the rest), and within each worker use threads (or async) to handle many concurrent IO-bound connections cheaply. This is exactly how many production web servers are structured — a pool of processes, each running an event loop or thread pool. There’s also a third concurrency model that sidesteps both: a single-threaded event loop (async/await) that interleaves many IO-bound tasks on one thread with no locks and no context-switch cost — great for IO-bound work, useless for CPU-bound work (which still wants processes).

→ The cheap default

IO-bound and cooperative? Threads or async — cheap and shared. CPU-bound, needs isolation, or fighting a runtime lock? Processes. Big systems layer them: processes for isolation and cores, threads/async for concurrency within.

05

The shared-memory double edge (and the GIL)

Threads’ shared memory is their superpower and their curse. Communication is nearly free — one thread writes a variable, another reads it, no serialization, no copying. But that same sharing is why threads need synchronization: two threads touching the same data at once cause race conditions, so you add locks — and locks bring their own hazards (contention, and deadlock if two threads grab locks in different orders). Processes avoid all of this by construction: with isolated memory there’s nothing to race on, but you pay for communication with IPC and serialization overhead. You’re choosing between "fast to talk, dangerous to share" and "safe by isolation, costly to talk."

One infamous wrinkle: in CPython, the Global Interpreter Lock (GIL) lets only one thread execute Python bytecode at a time, so multithreading does not give you CPU parallelism in pure-Python code — threads still help IO-bound work (the GIL is released during IO), but CPU-bound Python needs multiprocessing to actually use multiple cores. This is why "use processes for CPU-bound work" is near-gospel in Python, while languages without a GIL (Java, Go, C++, Rust) get real multi-core parallelism from threads directly.

→ The trade you’re actually making

Threads trade safety for cheap, direct communication (and demand locks). Processes trade communication cost for isolation and guaranteed multi-core parallelism. The GIL tilts Python hard toward processes for CPU-bound work.

06

A worked scenario: a web server

You’re serving thousands of simultaneous HTTP requests. Handling each in its own process would be safe but wasteful — processes are heavy to create and switch, and thousands of them would exhaust memory. Handling all of them as threads in one process is cheap and lets them share caches directly, but one bad request that segfaults or leaks could take down every connection at once, and in Python the GIL would cap CPU throughput anyway.

So production servers layer both: a small pool of worker processes (one per core, for isolation and true parallelism — a crash kills one worker, and the manager restarts it without dropping the others), and within each worker, threads or an async event loop to juggle many IO-bound connections concurrently at low cost. Processes give you fault isolation and cores; threads/async give you cheap concurrency. Neither alone is right — the architecture uses each for what it’s good at.

→ The pattern generalizes

Need isolation, security, or CPU parallelism (or you’re in Python) → processes. Need cheap, closely-coordinated, IO-bound concurrency → threads (or async). Most serious systems run processes on the outside and threads/async on the inside.

The picture

The picture: who can see whose memory

two processes: separate memory one process, three threads: shared process A code heap stack process B code heap stack IPC: pipe or socket, data is copied process C shared: code, heap, globals, filescounter += 1 from 2 threads = race T1own stack T2own stack T3own stack
Everything on the page follows from this split. Processes A and B each own a full address space, so a bug in one cannot touch the other, and every message between them is copied through the kernel. The threads in process C share all of it except a stack and a set of registers each. That makes passing data free, because they all hold the same pointers. It also means two threads can update the same counter at once, so shared data needs a lock. Isolation on the left is enforced by the hardware and the kernel; safety on the right is enforced only by the discipline of your own code.
Trade-offs

Cost and trade-offs, operation by operation

No timings here, because they vary by kernel and hardware. Time is the work the operation does. Space is the memory it takes or copies.

CaseTimeSpaceWhy
Create a process (Linux fork)Copies the page tables, not the pagesPages are shared copy-on-write and duplicated only when one side writesCheaper than it sounds, until the child or parent writes to most of its memory.
Create a process (Python spawn, the default on macOS and Windows)Starts a fresh interpreter and re-imports your main moduleA whole interpreter per workerWhy worker code must sit under if __name__ == "__main__":, and why pools are created once and reused.
Create a threadNo new address space; the kernel adds a schedulable taskA stack, commonly 8 MB of reserved virtual memory on Linux1,000 threads reserve about 7.8 GiB of address space, but only the pages they touch become real memory.
Switch between threads of one processSaves and restores registersNothing extraThe address space and its TLB entries stay valid.
Switch between processesRegisters plus a switch of page tablesNothing extraCached address translations from the old process stop helping.
Share data, threadsA read or write, plus a lock for anything shared and mutableOne copyFast to share; every unguarded shared write is a possible race.
Share data, processesSerialize, copy through the kernel, deserializeTwo copies, plus the encoded form in transitShared-memory segments avoid the copy and bring the locking problem back.
CPU-bound pure-Python code, 8 coresThreads: about one core’s worth under the GIL. Processes: all 8Processes: 8 interpretersCPython 3.13 adds an optional free-threaded build without the GIL; the default build still has it.
An async taskSwitches only at an await, in user spaceA small object per task, no stack of its ownCheapest of all for waiting on I/O. One blocking call stalls every task on the loop.
One worker crashesThread: a segfault ends the whole process and every thread in it. Process: only that one exitsProcess: the parent sees the exit status and can start a replacementThis is how pre-fork servers survive a bad request: a supervisor restarts the dead worker.
Stopping a stuck workerProcess: send it a signal; the kernel reclaims its memory, files and sockets. Thread: most runtimes give no safe way to kill one (Python has no API for it)A killed thread could leave a lock held or data half-writtenWork you may need to cancel by force belongs in a process, or must check a stop flag itself.
Forked Python workers sharing memoryReading an object updates its reference count, which writes to its pageCopy-on-write pages get duplicated even though your code only readsShared memory erodes over a worker’s life. gc.freeze() (Python 3.7+) before forking keeps the garbage collector from touching the inherited objects, which helps.

The pattern: processes pay up front (creation, copying, an interpreter each) and get isolation and every core. Threads pay later, in locks and in bugs, and get cheap sharing. Async is cheaper still for I/O, at the price of never blocking. That is why the page’s web server ends up with all three: processes per core, and threads or an event loop inside each. The last three rows add the operational side. A process can crash, be killed and be replaced without harming its neighbours, which is what a supervisor needs. A thread cannot be stopped from outside without risking a held lock. So when you are unsure, ask what happens when one unit of work goes wrong. If the answer must be “only that unit fails”, the work belongs in a process.

Watch for

Common mistakes

  • Forking a process that already has threads

    The child gets a copy of all memory but only the thread that called fork. A lock another thread held at that moment is copied in its locked state, and nobody in the child will ever release it, so the child hangs on its first malloc or log call. Fork before starting threads, or use a spawn-style start.

  • Assuming counter += 1 is atomic

    It is a read, an add and a write. Two threads can both read 41 and both write 42. This happens in Python too: the GIL keeps the interpreter consistent, not your counter. Guard it with a lock, or give each thread its own count and add them at the end.

  • One thread or process per task, with no cap

    A burst of 10,000 requests becomes 10,000 threads or processes, each with its own stack or interpreter, and the machine spends its time switching and swapping. Use a fixed pool sized to cores for CPU work, and to the downstream’s limits for I/O.

  • Shipping big data to every worker

    Each task sent to a process pool is serialized and copied. Passing a 500 MB array with every task can cost more than the work itself. Send a file path, an index range or a shared-memory name, and let the worker read the data where it lives.

  • Blocking inside an event loop

    One synchronous call (a time.sleep, a blocking database driver, a big CPU loop) inside an async handler freezes every other task on that loop, because the loop only switches at an await. Move the call to a thread or process pool, or use an async client.

Your call

Which would you pick?

Three situations. Pick the side you'd actually build — the explanation follows.

A CPU-bound numeric workload in Python that must use all 16 cores.

A server handling thousands of concurrent connections that spend nearly all their time waiting on network IO.

A plugin system running untrusted third-party code inside your application.

Frequently asked

Quick answers

What's the difference between a process and a thread?

A process is an independent program with its own isolated memory space; a thread is a unit of execution inside a process that shares the process’s memory with sibling threads. Processes are isolated (safe, but expensive to create and they communicate via IPC), while threads share memory (cheap and fast to communicate, but they require synchronization and one thread crashing can take down the whole process).

Which is faster, a process or a thread?

Threads are cheaper to create and switch between, and they communicate faster because they share memory directly rather than copying data through IPC. That makes threads lighter-weight for closely-cooperating, IO-bound work. Processes cost more per operation but buy isolation and guaranteed multi-core parallelism, which threads can’t always provide (for example under Python’s GIL).

Why does Python use multiprocessing for CPU-bound work?

Because of the Global Interpreter Lock (GIL): in CPython only one thread can execute Python bytecode at a time, so multithreading does not give CPU parallelism for pure-Python code. Threads still help IO-bound work (the GIL is released during IO), but to actually use multiple cores for CPU-bound Python you use multiprocessing, which runs separate processes each with their own interpreter and GIL.

When should I use processes over threads?

Use processes when you need isolation (a crash or bug must not spread), a security sandbox for untrusted work, true multi-core parallelism (especially under a runtime lock like the GIL), or independently restartable workers. Use threads when tasks share a lot of data and coordinate closely, the work is IO-bound, and cheap creation and direct shared-memory communication matter.

▶  Watch it explained

Process vs Thread: your own house, or a shared one

Process vs Thread · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextThe Linux Internals Handbook Next on the “How computers actually work” ladder · rung 5 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks