Ruby On Rails
11 min

TL;DR: Most slow Rails apps don't need more servers. They need diagnosis in the right order. Start with frontend and HTTP (compression, cache headers, asset optimization). Then fix database queries (N+1 patterns, missing indexes). Then view rendering (collection rendering, fragment caching). Then background jobs and external service calls. Server tuning (Puma workers, threads, Ruby runtime) comes last. This order matters because each layer masks the ones below it.
Your Rails app worked fine six months ago. Then features accumulated, the database crossed a million rows, and traffic grew. Now the dashboard takes four seconds. Checkout times out during peaks. API responses that used to feel instant now drag.
The instinct is to start randomly optimizing. Throw caching at a view, add an index, bump Puma workers. But scattered fixes without diagnosis waste time and hide the real bottleneck. You end up paying for more servers instead of fixing the code that's making them work too hard.
This is a diagnostic order guide. Not a random checklist. The order matters because each layer masks the ones below it. Fixing a slow query won't help if uncompressed frontend assets add 3 seconds before the browser even renders. And tuning Puma threads is pointless if N+1 queries are generating 300 database calls per request.
We follow this exact layered approach at Essence Solusoft when optimizing Rails applications: measure first, fix the highest-impact layer, then move deeper.
Why should you profile before touching any code?
Premature optimization is the classic trap. A developer notices a slow page, rewrites a query, ships it, and the page is still slow. Because the bottleneck was actually in view rendering. Or uncompressed assets. Or an inline API call to a third-party service.
Before you change anything, establish a baseline. Capture current response times for your top 5-10 most-visited endpoints. Use your Rails logs and APM traces (tools like New Relic or Rack Mini Profiler) to find the slowest controller actions.
For each problematic endpoint, collect: how many database queries it executes, the average query duration, Active Record time versus view rendering time, how many partials get rendered, whether external API calls happen during the request, and the total page load time in the browser. This baseline is your measure of success. Without it, you're guessing whether your fixes actually helped.
Investigate high-frequency endpoints first (the pages users hit most), then high-value business endpoints (checkout, signup, dashboards), then background workers with long execution times. This priority order ensures the biggest user-facing impact comes first.
Is the slowness actually on the frontend?
Users feel frontend and network delays first. Even when your Ruby backend responds in 200ms, unoptimized assets can make the entire experience feel broken.
Start with the basics: enable gzip or Brotli compression for all text-based responses, set proper cache-control headers for static assets (JavaScript, CSS, images), and use HTTP/2 multiplexing where your web server supports it.
One app we reviewed served uncompressed CSS and JavaScript bundles totaling 2.4 MB. The backend responded in 180ms, but total page load was 3.8 seconds. After compressing assets, lazy-loading images, and adding cache headers, load time dropped to 1.1 seconds. No Ruby code changed. The perceived performance problem was entirely a frontend problem wearing a backend mask.
Use browser DevTools waterfall charts to separate backend response time from asset download and rendering time. If your server response is under 500ms but the page takes 3 seconds, the problem is in the last mile, not your Rails code. Fix this layer first because it's fast, cheap, and immediately visible to users.
Are N+1 queries and missing indexes killing your database?
In most slow Rails apps, the main bottleneck is database access. Not Ruby. Not Rails itself. Queries.
The N+1 problem: you load a collection of records, then loop over each one and trigger a separate query for an association. Loading 200 orders and separately fetching each order's customer generates 201 SQL queries instead of 2.
# Bad: 1 query for orders + N queries for customers
orders = Order.all
orders.each { |o| puts o.customer.name }
# Good: 2 queries total with eager loading
orders = Order.includes(:customer)
orders.each { |o| puts o.customer.name }
One endpoint we profiled executed over 300 queries per request and took 3.1 seconds. After adding proper eager loading, it dropped to 8 queries and 120ms. That's not a micro-optimization. That's a 25x reduction in query count.
Detect N+1 issues through development logs (look for repeated SELECT statements), the Bullet gem which alerts you in development, and APM traces that show hundreds of queries in a single request.
Once N+1 patterns are fixed, look at missing indexes. Any query consistently taking over 100-200ms deserves investigation. Add single-column indexes on foreign keys (user_id, account_id) and columns in WHERE clauses (status, created_at). Add composite indexes like [:account_id, :status] when queries filter on multiple columns together. Use EXPLAIN ANALYZE to verify indexes are actually being used by the query planner.
One concrete example: replacing WHERE LOWER(name) LIKE '%search_term%' on an unindexed text column with a trigram index cut a 1,200ms query down to 15ms on a table with 400,000 rows. Missing indexes are one of the most common and most fixable causes of slow response times.

Is view rendering the hidden bottleneck?
After database optimization, many slow pages are held back by heavy rendering. Rendering partials inside loops is expensive. Switching from partial-in-loop to collection rendering cuts render time by 50-70%:
# Slow: renders partial individually for each item
<% @items.each do |item| %>
<%= render partial: "item", locals: { item: item } %>
<% end %>
# Fast: collection rendering
<%= render partial: "item", collection: @items %>
Wrap slow-changing components (navigation, product cards, dashboard widgets) in cache blocks to skip recomputation on every request. Fragment caching can reduce render time by 80-90% for cached views.
For nested structures like blog lists with comments or product catalogs with variants, Russian doll caching lets each item maintain its own cache key. Inner caches expire independently, keeping invalidation localized. You update one comment and only that comment's cache (and its parent's) gets busted. Everything else stays warm.
Combine eager loading, pagination, and fragment caching on a listing page and you can turn a 600ms render into a sub-100ms response. The gains compound because you're fixing fewer queries AND caching the rendered output of those queries.
Are background jobs and external services adding hidden latency?
If your controller sends emails, generates PDFs, syncs with payment gateways, or calls third-party APIs inline, your users are waiting for work they never asked for. Every millisecond spent on a Stripe API call or a SendGrid request inside a web request is latency the user absorbs.
Offload non-interactive work to background jobs: email delivery, PDF and report generation, external API synchronization, webhook processing. The request enqueues the job, returns immediately, and the UI polls or uses ActionCable to push the result when it's ready.
Set explicit timeouts on all external HTTP calls. Implement retries with exponential backoff. Consider circuit-breaker patterns so a slow third-party service doesn't cascade into your app's response times. A payment gateway that takes 8 seconds to respond shouldn't make your checkout page take 8 seconds.
Monitor job queues through APM and logs. Stuck or backed-up workers silently reintroduce the same performance problems you just fixed in the web layer. If Sidekiq queues are growing faster than workers can clear them, that's a capacity problem you need to see before users feel it.
When should you tune Puma, threads, and the Ruby runtime?
After fixing database and view issues. Not before. Most teams reach for Puma worker counts and thread settings too early, trying to outscale a problem that's caused by inefficient code.
Puma uses workers (OS processes) and threads for concurrency. Under MRI Ruby's GVL, threads provide concurrency only during I/O wait. More threads improve throughput for I/O-bound work, but when requests are CPU-bound, extra threads cause contention and increase latency instead of reducing it.
A practical starting point: one Puma worker per CPU core with 3-5 threads per worker. Then adjust based on measured throughput and memory usage. Use find_each or find_in_batches for large dataset processing to prevent memory bloat within workers.
Many production apps benefit from switching to jemalloc as the memory allocator to reduce fragmentation. Ruby 3.3+ ships with YJIT, which offers faster code execution at the cost of additional memory. Worth testing in your environment. And upgrading to current Ruby and Rails versions can yield significant performance improvements without changing any application code, which is one reason we always recommend keeping Rails versions current.
How do you keep performance from degrading again?
Performance optimization isn't a one-off project. Without ongoing attention, every new feature risks reintroducing the problems you just fixed.
Set performance budgets and SLOs. Something concrete: 95% of HTML responses under 500ms, 99% under 1 second. Track drift in P95/P99 latency, not just averages. Add basic performance checks to your CI or staging environment: automated request timing, query count assertions, rendering time benchmarks. Catch regressions before they reach production.
Revisit older queries, indexes, and caches quarterly. A query that was fast at 10,000 rows becomes a bottleneck at 500,000. Data grows, product behavior changes, and performance work that held up six months ago can silently degrade.
Some problems genuinely need specialist help: complex reporting across multi-tenant databases, years of accumulated technical debt, or scaling demands that outpace in-house experience. If you've followed this diagnostic order, fixed what you can measure, and still hit walls, our maintenance and support team can help with the deeper architectural work.

Frequently Asked Questions
Why is my Rails application slow even though the server has enough resources?
Most slow Rails apps aren't resource-constrained. They're code-constrained. N+1 queries, missing indexes, uncompressed assets, and inline external API calls are the usual causes. Adding servers or upgrading hardware amplifies inefficiency instead of fixing it. Profile first, then fix the bottleneck the profiling reveals.
What's the fastest way to speed up a Rails app?
Fix N+1 queries. It's almost always the highest-impact, lowest-effort change. One endpoint dropping from 300 queries to 8 can cut response time by 90% or more. Use the Bullet gem in development and check APM traces in production to find them.
Should I add caching before fixing database queries?
No. Fix the queries first. Caching a slow query means you're still slow on cache misses, and you've added invalidation complexity. Once queries are optimized, caching the rendered output of those fast queries compounds the gains.
How do I know if Puma needs more workers or threads?
Measure before tuning. If your APM shows requests spending most of their time in queue (waiting for a Puma thread), you may need more threads or workers. If requests spend most of their time in Active Record or view rendering, adding threads won't help. Fix the slow code first.
How often should I review Rails application performance?
Quarterly at minimum for production apps with growing data. Set automated performance budgets in CI to catch regressions on every deploy. Review slow query logs, P95/P99 trends, and background job queue depth weekly as part of your sprint process.

Written by
Ashok Damaniya
Chief Technical Officer (CTO)
Ashok Damaniya is the Chief Technology Officer at Essence Solusoft. He leads the technical team, guides architecture and development decisions, and helps deliver reliable, scalable software solutions.
Reader guide
Use the links below to jump into next reading without leaving the article flow.
Blog categories
Recent posts
Slow Rails Application? Diagnose Performance Problems in the Right Order
11 min
Rails Application Security: How SaaS Platforms Stop Bots, Spam, and Abuse
12 min
Solid Queue vs Sidekiq: When Removing Redis From Rails Is the Wrong Decision
10 min
What We've Built: Essence Solusoft's Journey as a Ruby on Rails Development Company
10 min
Similar Blogs






