VIII. Concurrency

Scale out via the process model

“In the twelve-factor app, processes are a first-class citizen.” – 12factor.net

When to use

Scaling your application.

Why it matters

  • Scalability: You can vertical scale (bigger RAM/CPU) only so much. Horizontal scaling (more processes) is near infinite.

Signs of Violation

  • Creating threads inside the app to handle jobs instead of spawning new worker processes.
  • “Singleton” app design that prevents running multiple instances.

Explanation

Problem

One giant process is a bottleneck.

Solution

Process types. web process handles traffic. worker process handles background jobs. Scale them independently. Need more web throughput? Scale web=5. Need faster job processing? Scale worker=10.

Real world analogy

Checkout lines at a supermarket. If the line gets long, you open more lanes (Processes), you don’t just try to make the one cashier work faster (Threads/Vertical Scale).

Pros and Cons

Pros Cons
  • Granular scaling
  • Fault isolation (one crash doesn’t kill all)
  • More complex orchestration (Kubernetes/Process Managers)
  • Comparison

    • Threads: Threads share memory (dangerous). Processes share nothing (safe).

    Code example

    Typescript

    Bad (Violation)

    Good (Adherence)

    PHP

    Bad (Violation)

    Good (Adherence)