To run our web application, we need an application server.

The purpose of an application server is to take an incoming HTTP request from the web server and pass it to our application. Our application processes the request, builds the response HTML, and hands it back to the application server.

request-response-flow.jpeg

An application server is different from a web server such as Apache, Nginx, or Caddy which accept incoming requests from the Internet and pass them to the application server, which talks to the Rails application.

Typically you start with one web server and one application server, all on a single server instance.

app-servers.jpeg

As your app grows and starts receiving more traffic, you may want to use multiple Rails applications to handle the incoming requests. In such cases, you put the application server, along with Rails application, on multiple servers, which are load balanced by the web server (or a dedicated load balancer, but let's not worry about that for now).

multi-app-setup.jpeg

Rails uses the Puma application server, and we will use the same.

For development, we don't have to worry about the web server. We'll tackle that when we will deploy our application in a future lesson.

puma-logo-large.png

Let's install Puma using bundler.

$ bundle add puma

Now if you go back to the editor and open the Gemfile, you will notice that a new line has been added to it:

# frozen_string_literal: true

source "https://rubygems.org"

gem "puma", "~> 6.4"  # new line (you might have different version)

Let's not worry about the ~> 6.4 part for now. It tells bundler to use a specific version of the Puma gem.

After installing Puma on your machine, the next question is: how will Puma talk to our web application?

For that, we need Rack, which we will install in the next lesson.