I wondered, “What is the difference between a web server and an application server?”
What is a server?
First of all, what is a server? The story. The server is a server in English, that is, it supplies and provides. According to the IT Glossary, a server is another computer network. A computer that provides its own functions, services, data, etc. to a computer. When we browse a web page, we ask the server “I want to see this page!” From our PC. Then the server returns a page saying “Yes, this!”. Now you can see the happy web page. Normally, each server machine or server software has a fixed function or service to be provided to the outside, and a supported data format or protocol (communication protocol). Then, it is called “○○ server” with the types of functions to be provided, such as “DB server”, “web server”, and “application server”.
The role of the web server is to receive content requests from the browser and return a response to the browser. If the request at this time is static web content (content that displays the same display content unless updated, such as HTML, CSS, and image files), the web server processes it and returns a response. In the case of dynamic web content that requires processing to change the display content for each client, the web server sends a request to the application server. Then, the result returned from the application server is returned as a response. Well-known web servers include Nginx and Apache.
The application server runs the applications we create. The request sent from the web server is transmitted from the application server to the application, and the result processed by the application is returned to the web server. In the case of development in a local environment, only the application server is set up, but in the production environment, by placing the web server in front of the application, it is often the case that the processing of static content is burdened.
For example Rails
Typical Rails application servers are Unicorn, Thin, Rainbows, Puma, etc. The request sent from the web server is transmitted from the application server to the Rails application, and the result processed by the Rails application is returned to the web server. When developing in a local environment, set up only an application server for Rails such as Puma (the one that is usually done in the development environment). On the other hand, in the production environment, the web server is often placed in front of the Rails application to bear the burden of static content processing. This allows the web server to process multiple applications at once, render assets quickly, and handle many of the things that happen with each request.
Let’s touch on Rack here. Rack goes between the Ruby framework and the application server and acts as a link between them. By using Rack, the server converts the sent HTTP request into a form that can be understood by the application. On the contrary, the response from the application is converted to HTTP through Rack and returned to the server. Rack allows you to freely combine servers and frameworks.
I will summarize the contents so far. The web server receives the request sent from the browser, and if it is static web content, returns a response to the browser. However, if the request is dynamic web content, it is not processed by the web server and sent to the application server. Then, the application server tells the application through the middleware. When the process is complete, return the results to the browser in the reverse order.