Prev Next

Web / NGINX Interview questions

Why doesn't NGINX use a thread-per-request model like Apache's prefork MPM?

A thread- or process-per-request model has to pay fixed overhead for every connection: allocating a stack, and having the OS scheduler context-switch between threads as it decides which gets CPU time next. That overhead is manageable at low concurrency but grows painfully as connection counts rise into the thousands - this is the C10k problem NGINX was explicitly designed to solve.

NGINX instead uses a small, fixed number of worker processes, each handling many connections through non-blocking I/O and an event loop. Because a connection that's idle - waiting on network I/O or a slow backend - doesn't tie up a dedicated thread, memory and CPU use scale far more gently as concurrent connections increase.

The trade-off is architectural complexity: code has to be written in a non-blocking style, and CPU-heavy work inside a request can stall every other connection that worker is handling, since there's no separate thread to isolate it. That's a deliberate design choice in exchange for dramatically better concurrency at scale.

What is the main trade-off NGINX accepts by avoiding a thread-per-request model?
What problem was NGINX explicitly designed to solve with this architecture?

More Related questions...

What is NGINX? What is the purpose of NGINX as a reverse proxy? What are the main features of NGINX? What are the types of context blocks in NGINX configuration? Define upstream in NGINX? What is the master-worker process model in NGINX? List common NGINX configuration directives? How do you install NGINX on Ubuntu? How do you start, stop, and reload NGINX? What is the nginx.conf file? What are server blocks in NGINX? What is a location block in NGINX? How do you serve static files with NGINX? What is load balancing in NGINX? What are the types of load balancing methods in NGINX? Define a virtual host in NGINX? What is SSL termination in NGINX? How do you enable Gzip compression in NGINX? What is caching in NGINX? What is the purpose of the events block in NGINX? What is the difference between NGINX and Apache HTTP Server? What is the difference between proxy_pass and rewrite in NGINX? What is the difference between a forward proxy and a reverse proxy? How does NGINX handle concurrent client connections? How does NGINX's event-driven architecture work? Why is NGINX considered more performant than process-per-connection servers? Why do we use upstream blocks with multiple servers? When should you use NGINX purely as a reverse proxy versus also as a load balancer? When would you choose round robin over least_conn load balancing? What happens when an upstream server fails a health check? How is SSL/TLS termination configured in NGINX? How can you optimize NGINX for high-traffic websites? How do you troubleshoot a 502 Bad Gateway error in NGINX? How do you troubleshoot high memory usage in NGINX worker processes? Explain the lifecycle of an HTTP request in NGINX? Explain the execution flow of NGINX's request processing phases? Explain the internal working of NGINX worker processes and the event loop? Why doesn't NGINX use a thread-per-request model like Apache's prefork MPM? Why should location block matching order matter between regex and prefix matches? What is the difference between try_files and rewrite directives? How does NGINX handle SSL session caching for performance? How can you optimize NGINX buffer settings for large file uploads? What is the difference between active and passive health checks in NGINX? How do you troubleshoot NGINX configuration errors before reloading? Why is the worker_connections directive important for concurrency limits? When should you use NGINX caching instead of a dedicated CDN? What is the difference between limit_req and limit_conn for rate limiting? How does NGINX handle WebSocket proxying? Explain the internal working of NGINX's keepalive connection pooling to upstream servers? Why do we use try_files with a fallback to PHP-FPM in WordPress-style setups?
Show more question and Answers...


Comments & Discussions