Nginx · The edge of your stack
How do you size worker_connections and worker_processes?
Short answer
Total concurrent connections are roughly worker_processes multiplied by worker_connections, but a proxied request uses a client connection and an upstream connection. File descriptor limits must be high enough for both.
worker_connections is per worker, not global. When Nginx proxies a request, it holds one connection to the client and one to the upstream, so the effective request capacity is lower than the raw connection count.
worker_processes auto;
worker_rlimit_nofile 65535;
events {
worker_connections 4096;
}
http {
upstream backend {
server 127.0.0.1:3000;
keepalive 128;
}
}Sizing considerations
- A rough upper bound is workers times worker_connections, minus overhead
- Proxied traffic consumes two connections per active request
- Keepalive connections and WebSocket streams stay open and count against the limit
- The OS file descriptor limit must exceed the process limit or accepts will fail
- More workers than cores can increase context switching without adding throughput
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why does a proxied request consume two connections?
- 2Is worker_connections a global or per-worker limit?
- 3What error appears when file descriptors run out?
- 4How do long-lived WebSockets affect capacity planning?
Say it in the interview
worker_connections is per worker, so the raw capacity is workers times connections. For proxied traffic I roughly halve that because each request holds a client and an upstream connection. I set worker_processes to auto, raise worker_rlimit_nofile above the expected socket count, and monitor actual connection usage. Long-lived WebSockets and keepalive sockets count against the same limits.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Nginx mock interview and get scored feedback on depth, clarity and confidence.