DEV Community

Dang Hoang Nhu Nguyen
Dang Hoang Nhu Nguyen

Posted on

[BTY] Day 4: Event Driven Architecture behind NGINX

Most of these contents are taken from this blog: https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/.

Many web servers and application servers use a simple threaded or process‑based architecture, NGINX stands out with a sophisticated event‑driven architecture that handles multiple connections within a single process. 🤭

The mentioned article describes:

  • Why is architecture important?
  • How Does NGINX Work?
  • Inside the NGINX Worker Process
  • Scheduling the State Machine
  • Updating Configuration and Upgrading NGINX

Some key notes I found very exciting about NGINX after reading this article:

  1. The state machine is essentially the set of instructions that tell NGINX how to process a request.
    Image description

  2. Most web servers and web applications use a process‑per‑connection or thread‑per‑connection model. It mean each process or thread contains the instructions to process the request through to the end. During the time the process is run by the server, it spends most of its time ‘blocked’ – waiting for the client to complete its next move.
    Image description
    The important point to remember is that every active HTTP connection requires a dedicated process or thread (a grandmaster). However, there’s a huge imbalance: the rather lightweight HTTP connection, represented by a file descriptor and a small amount of memory, maps to a separate thread or process, a very heavyweight operating system object. It’s a programming convenience, but it’s massively wasteful.

  3. NGNIX has solved this problem by an event driven architecture:
    Image description
    (Figure out the reason why it's aster than a Blocking, Multiprocess Architecture here).
    With appropriate system tuning, NGINX can scale to handle hundreds of thousands of concurrent HTTP connections per worker process, and can absorb traffic spikes without missing a beat.

  4. Updating Configuration and Upgrading NGINX on the fly, without any dropped connections, downtime, or interruption in service!

Image description
Image description

You can find a brief of all things I have mentioned about in this infographic.

Top comments (0)