Reading Time: 4 mins
One of the heated debates over the years now would be which is the best web server to go with, Apache or Nginx? Both of them are popular and handles almost half of the internet traffic. At the same time, a high traffic e-commerce site built on top of Magento (written using PHP) is altogether different from other sites (which demands much efficient, reliable and faster architecture), in such a case, what would be the best option to go with?
Let us explore the best-to-go-with web server for e-commerce websites by breaking down the pros and cons of both the Apache and Nginx web servers.
Apache vs. Nginx
Apache, one of the pioneering software in the web server legacy and highly-popular due to its historical presence. Reputed for its speed, security and reliability, 67% of all the web servers runs using the Apache server. It is a process-driven approach and which enables it to create new threads for each new request.
- Since it is configured in Pre-fork mode by default, it can only serve a single request at a time.
- It means, it cannot handle concurrent requests and thereby ends in utilizing more RAM and often rejects requests at the time of heavy loads.
- Nonetheless, this architecture of Apache leads to the consumption of high resource. When comes to cross-platform support, it runs on all systems and gives full-support to Windows.
- It allows even the under-privileged users to do additional configuration and is flexible enough to configure via dynamic modules.
Nginx is now becoming a dominant web server and hosts around 75% of all the web servers worldwide. Unlike Apache, it follows an event-driven approach and can handle multiple requests within a single processing thread. It is because of this reason the Nginx web server is widely used as a reverse proxy and load balancer to manage the high-traffic.
- This module of Nginx makes it effortless to predict fluctuating and heavy loads with regard to latency, RAM and CPU usage. Means to say, it doesn’t fix an extra worker processor per requests.
- Though Nginx runs almost on all Unix-like systems, it only gives partial support for Windows.
- It doesn’t allow additional configuration and does not support dynamic loading.
Today, Nginx carries out a spectrum of server tasks such as mail proxy, reverse proxy, load balancer and HTTP caching.
Why we go with Nginx?
Even though Apache and Nginx both give a tough fight, there are certain factors which makes Nginx more influential and dominant over Apache. They are,
- Event-driven approach
- Lightweight and faster architecture
- Performs 2.5 times faster in fetching static content
- Speed and quick request interpretation (essential to e-commerce sites)
- Advanced media streaming modules
Further, Nginx can manage thousands of concurrent requests and owns the capacity to power 50% of the traffic sites on the web.
Comparing the Performance of Nginx with Apache
According to the recent years’ survey, Nginx is reported to be an advancing server and robust for websites, hitting aside the traditional Apache server by progressing 1% of overall business every year.
Requests Per Second (RPS)
Handling concurrent users or managing hundreds and thousands of users at the possible shortest time forms critical to every other e-commerce sites. Requests per second (rps) measures at what rate the server can accept and serve a request during the time of the different levels of concurrency. Ultimately, the time taken to accept and serve a request must be less, so as to reduce the latency. From the given graph, it is obvious that Nginx is the one which serves faster than Apache.
Time to First Byte (TTFB)
Time to first byte is the measurement of the time spent by the user in waiting for the initial response from the server-side. It is a useful metric to analyse the responsiveness of web server and network resources. According to Google’s recommendation, the ideal TTFB for a site must be less than 200 ms. Thus, lesser the time taken (here in ms) means better the site’s performance.