Nginx · The edge of your stack

How do you size worker_connections and worker_processes?

Mediumworker_connectionscapacityfile descriptorsUpdated Oct 2026
Quiz this track

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.

nginx
worker_processes auto;
worker_rlimit_nofile 65535;

events {
    worker_connections 4096;
}

http {
    upstream backend {
        server 127.0.0.1:3000;
        keepalive 128;
    }
}
auto sizes workers to available CPUs; worker_rlimit_nofile must cover client and upstream sockets.

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
Raising worker_connections without raising the file descriptor limit produces errors such as too many open files. Check both ulimit and worker_rlimit_nofile.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does a proxied request consume two connections?
  2. 2Is worker_connections a global or per-worker limit?
  3. 3What error appears when file descriptors run out?
  4. 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.