Event-Driven vs. Thread-per-Request: Top 3 Scalability Differences

Event-driven architectures like Nginx can handle hundreds of thousands to millions of concurrent connections with significantly lower memory per connection (e.g., ~1MB) by using non-blocking I/O and reducing context switching, while thread-per-request models typically consume more resources per connection.

The top 3

  1. Memory Footprint: Event-Driven's Lean Advantage: Event-driven architectures typically use significantly less memory per connection, often megabytes versus kilobytes, allowing them to handle hundreds of thousands or even millions of concurrent connections on a single server with greater efficiency.
  2. Concurrency Handling: Thread-per-Request's Context Switching Cost: Thread-per-request models create a new thread for each client, leading to high context switching overhead and increased CPU contention as the number of concurrent connections grows, whereas event-driven systems manage thousands of connections with a few OS threads, minimizing these performance bottlenecks.
  3. Failure Isolation: Event-Driven's Single Point Risk: While efficient, a critical difference is that a single blocking operation or unhandled error in an event-driven system's main loop can halt all processing for all clients, a risk mitigated in thread-per-request models where failures are typically isolated to individual threads.

Sources

Open the full topic