Although web-server adapters and the Rack application API revolutionized the way Ruby web frameworks are developed, you’re probably more familiar with another term related to Rack: middleware.
A middleware wraps around a Rack application. It lets us manipulate both the request sent down to the application and the response the application returns. By piling up many middleware before an application, we create a middleware stack. Any request to an action in a Rails controller passes through three middleware stacks, as the following figure shows.