Nginx
Nginx (pronounced "engine-x") is a web server that is far more often used as the thing in front of your web servers: a reverse proxy, load balancer, TLS terminator, HTTP cache and rate limiter, all in one small, fast process configured with a text file. It was written in the early 2000s to solve the "C10K problem" (serving ten thousand concurrent connections from one machine), and its architecture is still the reason it shows up everywhere.
The properties that matter:
- Event-driven and non-blocking: A handful of worker processes each handle thousands of connections with an event loop, instead of one thread or process per connection. Idle connections cost a few kilobytes of memory, not a thread.
- Reverse proxy first: Clients connect to Nginx; Nginx connects to your application servers. It hides, protects and balances the servers behind it.
- Swiss army knife at layer 7: Routing by host and path, TLS, HTTP/2 and HTTP/3, compression, caching, rate limiting, WebSocket and gRPC proxying, all built in.
- Also layer 4: The
streammodule proxies and balances raw TCP and UDP for databases, MQTT brokers and other non-HTTP protocols. - Simple, declarative configuration: A short config file, validated with
nginx -tand applied with a graceful reload that drops no connections.
You'll rarely be asked to design Nginx itself, but it's the most common concrete answer to "what's the box between the internet and your app servers?" In interviews it comes up as the load balancer or API gateway in a high-level design, as the edge cache in a read-heavy system, as the place to enforce rate limits, and in questions about handling many concurrent connections. Knowing how it works lets you justify those boxes instead of just drawing them.
Architecture: Why It Handles So Many Connections
But what is actually happening under the hood? Nginx runs as one master process and several worker processes, usually one per CPU core.
- The master reads configuration, opens listening sockets, starts and supervises workers, and handles signals such as reload and upgrade. It handles no traffic.
- Each worker is single-threaded and runs an event loop. It asks the kernel (through
epollon Linux orkqueueon BSD and macOS) "which of my thousands of sockets are ready to read or write?", handles each ready socket for as long as it can make progress without blocking, and moves on. A worker never waits on one slow client; it simply doesn't look at that socket until the kernel says data has arrived.
Compare that with the classic thread-per-connection model (Apache's prefork and worker modes, many older app servers). Each connection holds a thread and its stack, often hundreds of KB to a few MB, and the OS scheduler has to context-switch between thousands of mostly idle threads. At 10,000 slow mobile clients, a thread-per-connection server is exhausting memory and spending its time switching; an Nginx worker is just tracking 10,000 small structs.
The limit per worker is worker_connections (often set to thousands or tens of thousands), and every proxied request uses two connections: one from the client and one to the upstream. Total capacity is roughly workers × worker_connections, also bounded by the OS's file descriptor limit (worker_rlimit_nofile).
The catch is that anything blocking stalls every connection on that worker. That's why Nginx does disk I/O for static files with sendfile (the kernel copies straight from the page cache to the socket) and can offload blocking reads to thread pools, and why heavy application logic belongs in upstream servers, not inside Nginx.
When an interviewer asks "how do you handle 100,000 concurrent WebSocket or long-poll connections?", the event-loop model is the answer to name. The same idea powers Node.js, Netty, Envoy and Redis: a few threads, non-blocking sockets, and the kernel telling you which ones are ready.