
Ruby on Rails has powered thousands of successful products thanks to its convention-over-configuration philosophy and developer-friendly tooling. Building a Rails app locally is enjoyable, but moving it to production introduces new responsibilities: configuring environment variables, provisioning a database, compiling assets, running background workers, and keeping the application secure and observable. This guide walks you through each step of deploying a Ruby on Rails web application, whether you choose a platform-as-a-service, a container-based workflow, or your own virtual private server.
How AAMAX.CO Helps Launch and Maintain Rails Applications
Production deployments benefit from experienced hands, and AAMAX.CO offers exactly that. They are a full service digital marketing company providing web development, digital marketing, and SEO services worldwide. Their engineers can help you prepare a Rails codebase for production, choose the right hosting environment, configure databases and background jobs, and implement monitoring and backups. Beyond launch, they assist with performance tuning and ongoing maintenance, so your application remains stable as traffic grows. Businesses that rely on them gain a dependable partner for both technical and growth needs.
Prepare Your Application for Production
Start by reviewing your Gemfile and moving development-only gems into the development and test groups. Ensure your Ruby version is specified in the .ruby-version file and the Gemfile so the server installs the correct interpreter. Run your test suite and fix any failing tests. Check config/environments/production.rb to confirm settings such as force_ssl, log levels, and caching. Rails credentials or environment variables should store secrets like API keys and the secret key base, never hard-coded values in the repository.
Choose a Hosting Approach
There are three common ways to deploy a Rails app:
- Platform as a Service: Providers such as Heroku, Render, and Fly.io handle servers, scaling, and networking so you can deploy with a Git push or a simple command.
- Containers with Kamal: Rails now ships with Kamal, a tool that deploys Docker containers to any server with zero-downtime switching.
- Traditional VPS: You manage the operating system, web server, application server, and database on a virtual machine from providers such as DigitalOcean, Linode, or AWS.
Platforms offer simplicity, containers offer portability, and a VPS offers maximum control. Choose based on your team's skills, budget, and scaling requirements.
Set Up the Production Database
Most Rails apps in production use PostgreSQL or MySQL. Provision a managed database if possible, as it handles backups, updates, and failover. Configure config/database.yml to read the connection string from the DATABASE_URL environment variable. During deployment, run rails db:migrate to apply schema changes. For new apps, rails db:prepare creates the database and loads the schema when needed. Always back up the database before running migrations on a live system.
Compile Assets
Rails applications need their CSS, JavaScript, and images precompiled for production. Run rails assets:precompile as part of your build. Depending on your setup, this step uses Propshaft or Sprockets, along with tools such as importmap, jsbundling, or cssbundling. Serve the compiled assets through a CDN or configure your web server to deliver them efficiently with long cache headers. Platforms usually run asset compilation automatically during deployment.
Configure the Application Server
Puma is the default application server for Rails and handles concurrent requests using threads and worker processes. Tune the number of workers and threads in config/puma.rb based on available CPU cores and memory. On a VPS, place Nginx in front of Puma as a reverse proxy to handle SSL termination, compression, and static files. Newer Rails versions also include Thruster, a lightweight proxy that adds caching and compression in container deployments.
Run Background Jobs
Email delivery, image processing, and data imports should run outside the request cycle. Active Job integrates with backends such as Solid Queue, Sidekiq, or GoodJob. In production, run job workers as separate processes, containers, or platform dynos. Monitor queue sizes and failed jobs so problems are caught early. If you use Sidekiq, provision a Redis instance; Solid Queue uses your existing database instead.
Deploy with Kamal
Kamal has become a popular choice for modern Rails deployments. After installing it, configure config/deploy.yml with your server IP addresses, container registry, and environment variables. Running kamal setup installs Docker on the server and deploys the application for the first time. Subsequent releases use kamal deploy, which builds a new image, pushes it to the registry, and swaps containers without downtime. This approach gives you platform-like simplicity on your own infrastructure.
Secure Your Application
Enable force_ssl so all traffic uses HTTPS, and obtain certificates through Let's Encrypt or your hosting platform. Keep Ruby, Rails, and all gems updated to receive security patches. Use tools like Brakeman to scan for vulnerabilities and bundler-audit to check dependencies. Restrict database access to application servers only and configure firewalls to block unnecessary ports. A secure foundation is a core part of professional web application development.
Monitor and Log
Production apps need visibility. Use structured logging and send logs to a centralized service. Add error tracking with tools such as Sentry, Honeybadger, or AppSignal so exceptions are reported immediately. Application performance monitoring helps identify slow database queries and endpoints. Set up uptime checks and alerts so your team knows about problems before users report them.
Plan for Scaling
As traffic grows, scale horizontally by adding more application servers behind a load balancer. Use caching with Solid Cache, Redis, or Memcached to reduce database load. Optimize queries with proper indexes and eager loading to avoid N+1 problems. A CDN can offload static assets and improve global response times.
Conclusion
Deploying a Ruby on Rails web application involves preparing the codebase, choosing a hosting strategy, configuring the database and assets, running background jobs, and securing and monitoring the system. Whether you use a managed platform, Kamal with containers, or a traditional server, following these steps will help you launch a reliable, fast, and maintainable Rails application ready for real users.
