Skip to main content

Command Palette

Search for a command to run...

Process-based vs Thread-based: The Isolation Dilemma

Published
2 min read
L

Backend Engineer with experience building and scaling PHP applications in production environments.

I focus on performance, system behavior, and understanding how backend systems actually work beyond the framework layer.

Currently writing about PHP, backend performance, and production engineering.

Every backend runtime must answer a fundamental question: "How do we handle two users at the same time?"

The answer defines the stability of your entire platform.

Process-based Models (The "Apartment" Approach)

PHP-FPM uses processes. Each request gets its own dedicated process. It has its own memory space. It shares nothing with other requests.

  • Isolation: If one request crashes (Segfault), only that user is affected. The rest of the server stays alive.

  • Memory: No race conditions on global variables because there are no shared global variables.

  • Cost: High. Creating processes is slow and consumes more RAM.

Thread-based Models (The "Roommates" Approach)

Java, Go, and Node.js (internal libuv) use threads. Threads live inside a single process and share the same memory heap.

  • Efficiency: Extremely fast to spawn. Low memory footprint.

  • Communication: Easy to share data between requests (e.g., a global in-memory cache).

  • The Danger: Shared State.

    • If one thread corrupts the memory, the entire application can crash.

    • If one thread blocks the loop (in single-threaded async like Node), everyone waits.

Why this choice dictates architecture

This is why PHP is famously stable in messy codebases. You can write terrible code, memory leaks, and fatal errors—and the runtime simply recycles the process after the request. The server stays up.

In a thread-based runtime (like Java or a long-running Node app), a memory leak is a ticking time bomb that eventually kills the whole instance.

The Takeaway: Process models prioritize Safety and Isolation. Thread models prioritize Efficiency and Shared State.

Understanding this helps you decide not just which language to use, but how much you need to trust your own code.

The Execution Layer

Part 4 of 4

Frameworks evolve, runtimes persist. This series moves beyond syntax to explore the "Execution Layer". Master the architectural concepts that define production behavior: Runtime constraints, CPU vs I/O, and Concurrency models.

Start from the beginning

Runtime vs. Framework: The Abstraction Trap

When backend developers talk about systems, frameworks dominate the conversation. Laravel. Spring. Express. Django. But frameworks are liars. They provide a clean abstraction that hides the dirty reality of how code actually executes. Every backend a...

More from this blog

B

Backend in Production

14 posts

Short articles about backend engineering, PHP, performance, and how systems behave in production. Written from real-world experience, focused on clarity and trade-offs.