Generated by GPT-5-mini| Rack (software) | |
|---|---|
| Name | Rack |
| Title | Rack |
| Developer | Evan Phoenix; Rack contributors |
| Released | 2007 |
| Programming language | Ruby (programming language) |
| Operating system | Unix-like; Microsoft Windows |
| License | MIT License |
Rack (software) is a modular interface specification for web servers and web applications written in Ruby (programming language). It provides a minimal, standardized API that connects web servers, application servers, and frameworks such as Ruby on Rails, Sinatra (web framework), and Padrino (web framework), enabling interoperability across diverse deployment environments like Heroku and Amazon Web Services. Rack's influence extends to tools and libraries including Rack::Test, Thin (web server), Puma (web server), and Unicorn (web server), shaping the Ruby web ecosystem.
Rack originated in 2007 through collaboration between developers associated with projects such as Merb (web framework), Ruby on Rails, and contributors like Evan Phoenix and members of the Ruby community. Early adoption occurred around the time of shifts in web architecture driven by platforms like Heroku and hosting providers such as Engine Yard, prompting standardization similar to efforts seen with WSGI in Python (programming language) and PSR-7 in PHP. Rack's specification and reference implementation evolved alongside middleware patterns popularized by Rack::Builder and implementations in servers including Mongrel and Thin (web server), influencing web frameworks such as Sinatra (web framework) and Rails (web framework).
Rack defines a simple calling convention: an application is an object that responds to call and returns a three-element array: status, headers, and body. The design echoes concepts from WSGI and PSR-7 while aligning with object model idioms found in libraries like Rack::Response and adapters for CGI and FastCGI. Rack's environment hash contains request data mirrored in libraries like Rack::Request, and interoperates with servers such as Puma (web server), Unicorn (web server), and Thin (web server). The architecture emphasizes composability through middleware chains implemented by constructs similar to Rack::Builder, allowing applications to be composed much like pipelines used in Unix and inspired by middleware patterns in Java Servlet ecosystems and ASP.NET Core.
Middleware in Rack is a layer that wraps an application, implementing cross-cutting concerns seen in projects like ActionDispatch::ShowExceptions and gems such as Rack::Attack and Rack::Deflater. Common components include logging middleware comparable to tools used by Apache HTTP Server, session middleware analogous to Memcached adapters, and authentication middleware paralleling implementations in Devise (software). Developers use middleware to integrate services like Redis, PostgreSQL, and authentication providers such as OAuth 2.0 gateways, often combining middleware for compression, caching, and security in stacks managed by frameworks including Rails (web framework), Sinatra (web framework), and Hanami (web framework).
Multiple server implementations and adapters provide Rack compatibility: Puma (web server), Unicorn (web server), Thin (web server), and Passenger (application server) each implement the Rack protocol to host applications. Adapters enable integration with environments such as CGI, FastCGI, and platforms like Heroku and AWS Elastic Beanstalk. Rack-based adapters exist for reverse proxies like Nginx and HAProxy and integrate with process managers such as systemd and Upstart. Specialized adapters bridge to other ecosystems, echoing compatibility efforts like WSGI bridges in Python (programming language) and PSR-7 integration in PHP (programming language).
Typical usage shows a minimal app object responding to call and returning status, headers, and body, patterns mirrored in many tutorials from Ruby on Rails guides and Sinatra (web framework) documentation. Rack enables testing with tools like Rack::Test and integration into CI systems provided by services such as Travis CI and CircleCI. Deployment examples use servers including Puma (web server) behind Nginx on platforms like Heroku or containerized with Docker (software), orchestrated by systems such as Kubernetes or Docker Swarm. Ecosystem libraries such as Rack::Session::Cookie and Rack::Static provide common functionality used across applications from small services to large sites hosted by providers like GitHub and Shopify.
Rack's lightweight interface minimizes overhead, enabling high-performance servers like Puma (web server) and Unicorn (web server) to optimize concurrency and process models used by services at scale such as Heroku and Engine Yard. Performance considerations involve evented architectures exemplified by EventMachine and thread-pool strategies used by Puma (web server), while horizontal scaling commonly leverages reverse proxies like Nginx and load balancers like HAProxy in front of Rack servers. Benchmarks and profiling integrate tools such as New Relic, Datadog, and ab (ApacheBench) to tune middleware cost, garbage collection in MRI (Matz's Ruby Interpreter), and concurrency limits for production deployments at companies like Shopify and Basecamp.
Category:Ruby (programming language) software