<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Astm</title>
    <description>The latest articles on DEV Community by Astm (@astmdesign).</description>
    <link>https://dev.to/astmdesign</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F508595%2F4667ccc3-370a-4674-bfda-9c6f135e6b05.jpeg</url>
      <title>DEV Community: Astm</title>
      <link>https://dev.to/astmdesign</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/astmdesign"/>
    <language>en</language>
    <item>
      <title>The Silent Performance Killer in Rails: Understanding and Fixing N+1 Queries</title>
      <dc:creator>Astm</dc:creator>
      <pubDate>Tue, 16 Jun 2026 08:44:45 +0000</pubDate>
      <link>https://dev.to/astmdesign/the-silent-performance-killer-in-rails-understanding-and-fixing-n1-queries-2ibb</link>
      <guid>https://dev.to/astmdesign/the-silent-performance-killer-in-rails-understanding-and-fixing-n1-queries-2ibb</guid>
      <description>&lt;p&gt;If you've ever investigated a slow Rails endpoint, chances are you've encountered one of the most common performance problems in the Rails ecosystem:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;N+1 Queries.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The scary part?&lt;/p&gt;

&lt;p&gt;Your application can appear perfectly healthy during development, pass all tests, and work flawlessly in production for months.&lt;/p&gt;

&lt;p&gt;Then one day your dataset grows, traffic increases, and suddenly an endpoint that used to respond in 100ms now takes several seconds.&lt;/p&gt;

&lt;p&gt;No infrastructure changes.&lt;/p&gt;

&lt;p&gt;No database outages.&lt;/p&gt;

&lt;p&gt;No major code deployments.&lt;/p&gt;

&lt;p&gt;Just a silent performance killer hiding inside your ActiveRecord relationships.&lt;/p&gt;

&lt;p&gt;In this article we'll explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What N+1 Queries are&lt;/li&gt;
&lt;li&gt;Why they happen so frequently in Rails applications&lt;/li&gt;
&lt;li&gt;How they impact performance&lt;/li&gt;
&lt;li&gt;Techniques to prevent them&lt;/li&gt;
&lt;li&gt;Tools that can help detect them before they reach production&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  What Is an N+1 Query?
&lt;/h1&gt;

&lt;p&gt;An N+1 Query occurs when your application executes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One query to fetch a collection of records&lt;/li&gt;
&lt;li&gt;One additional query for each record in that collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's imagine a simple blog application.&lt;/p&gt;

&lt;p&gt;Each Post belongs to an Author.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:author&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance this looks innocent.&lt;/p&gt;

&lt;p&gt;However, Rails may execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of executing two queries, the application executes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 + 100 = 101 queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern is known as an N+1 Query.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Does This Happen?
&lt;/h1&gt;

&lt;p&gt;The answer lies in one of Rails' most powerful features:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Loading.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ActiveRecord delays loading associated records until they are actually needed.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;author&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;does not load the author when the post is fetched.&lt;/p&gt;

&lt;p&gt;It loads the author only when that line is executed.&lt;/p&gt;

&lt;p&gt;This behavior is incredibly convenient because it reduces unnecessary database access.&lt;/p&gt;

&lt;p&gt;However, when used inside loops, it can accidentally create hundreds or even thousands of additional queries.&lt;/p&gt;

&lt;p&gt;The framework is doing exactly what we asked it to do.&lt;/p&gt;

&lt;p&gt;The problem is that we didn't realize how many times we were asking.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why N+1 Queries Are Dangerous
&lt;/h1&gt;

&lt;p&gt;Many engineers focus on query execution time.&lt;/p&gt;

&lt;p&gt;The real problem is query volume.&lt;/p&gt;

&lt;p&gt;Imagine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;10 users → 11 queries&lt;/li&gt;
&lt;li&gt;100 users → 101 queries&lt;/li&gt;
&lt;li&gt;1,000 users → 1,001 queries&lt;/li&gt;
&lt;li&gt;10,000 users → 10,001 queries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As your data grows, the number of database round trips grows with it.&lt;/p&gt;

&lt;p&gt;This creates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increased database load&lt;/li&gt;
&lt;li&gt;Higher application CPU usage&lt;/li&gt;
&lt;li&gt;More network overhead&lt;/li&gt;
&lt;li&gt;Longer request times&lt;/li&gt;
&lt;li&gt;Reduced scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What worked perfectly in staging may become a production nightmare months later.&lt;/p&gt;




&lt;h1&gt;
  
  
  How to Avoid N+1 Queries
&lt;/h1&gt;

&lt;p&gt;The most common solution is eager loading.&lt;/p&gt;

&lt;p&gt;Rails allows you to preload associations before they are accessed.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:author&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rails now loads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(...);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only two queries.&lt;/p&gt;

&lt;p&gt;No matter how many posts are returned.&lt;/p&gt;

&lt;p&gt;This is one of the easiest performance wins available in Rails.&lt;/p&gt;




&lt;h1&gt;
  
  
  Common Places Where N+1 Queries Hide
&lt;/h1&gt;

&lt;p&gt;Many engineers look only at controllers.&lt;/p&gt;

&lt;p&gt;In reality, N+1 issues often appear in:&lt;/p&gt;

&lt;h3&gt;
  
  
  API Serializers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;PostSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Jbuilder Templates
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;author_name&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  GraphQL Resolvers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:author&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  View Templates
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Background Jobs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plan&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any place that loops through records and accesses associations can potentially create N+1 Queries.&lt;/p&gt;




&lt;h1&gt;
  
  
  Helpful Tools for Detecting N+1 Queries
&lt;/h1&gt;

&lt;p&gt;One of the best investments a Rails team can make is detecting N+1 Queries early.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bullet Gem
&lt;/h3&gt;

&lt;p&gt;The most popular N+1 detection tool in the Rails ecosystem.&lt;/p&gt;

&lt;p&gt;It automatically alerts developers when associations should be eager loaded.&lt;/p&gt;

&lt;p&gt;Example notification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USE eager loading detected
Add to your query: .includes(:author)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Rack Mini Profiler
&lt;/h3&gt;

&lt;p&gt;Provides detailed request analysis.&lt;/p&gt;

&lt;p&gt;Helps identify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slow queries&lt;/li&gt;
&lt;li&gt;Query counts&lt;/li&gt;
&lt;li&gt;Rendering bottlenecks&lt;/li&gt;
&lt;li&gt;Performance hotspots&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Skylight
&lt;/h3&gt;

&lt;p&gt;Excellent for production monitoring.&lt;/p&gt;

&lt;p&gt;It helps visualize database activity and identify endpoints suffering from excessive query counts.&lt;/p&gt;




&lt;h3&gt;
  
  
  New Relic
&lt;/h3&gt;

&lt;p&gt;Provides detailed transaction tracing and database monitoring.&lt;/p&gt;

&lt;p&gt;Very useful for identifying performance degradation caused by query-heavy endpoints.&lt;/p&gt;




&lt;h3&gt;
  
  
  Datadog APM
&lt;/h3&gt;

&lt;p&gt;Widely used in large-scale Rails environments.&lt;/p&gt;

&lt;p&gt;Offers visibility into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL execution&lt;/li&gt;
&lt;li&gt;Request traces&lt;/li&gt;
&lt;li&gt;Database latency&lt;/li&gt;
&lt;li&gt;Application bottlenecks&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;N+1 Queries are dangerous because they don't usually break functionality.&lt;/p&gt;

&lt;p&gt;Your tests pass.&lt;/p&gt;

&lt;p&gt;Your code looks clean.&lt;/p&gt;

&lt;p&gt;Users may not notice the problem immediately.&lt;/p&gt;

&lt;p&gt;But as data grows, the hidden cost grows with it.&lt;/p&gt;

&lt;p&gt;Understanding N+1 Queries is one of the first steps toward becoming a performance-conscious Rails engineer.&lt;/p&gt;

&lt;p&gt;And the good news?&lt;/p&gt;

&lt;p&gt;Many N+1 issues can be fixed with a single line of code.&lt;/p&gt;

&lt;p&gt;In the next article, we'll dive deeper into advanced eager loading strategies, compare &lt;code&gt;includes&lt;/code&gt;, &lt;code&gt;preload&lt;/code&gt;, and &lt;code&gt;eager_load&lt;/code&gt;, and discuss how to detect N+1 Queries in production environments before your users notice them.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>performance</category>
      <category>database</category>
    </item>
    <item>
      <title>Why your Ruby on Rails application has high CPU usage?</title>
      <dc:creator>Astm</dc:creator>
      <pubDate>Sun, 14 Jun 2026 10:45:13 +0000</pubDate>
      <link>https://dev.to/astmdesign/why-your-ruby-on-rails-application-has-high-cpu-usage-3o58</link>
      <guid>https://dev.to/astmdesign/why-your-ruby-on-rails-application-has-high-cpu-usage-3o58</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Have you ever received an alert saying:&lt;br&gt;
CPU usage is above 90%&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or maybe one of your production servers suddenly became slow, requests started timing out, and users began reporting performance issues.&lt;/p&gt;

&lt;p&gt;As Rails engineers, one of the most common production incidents we face is unexpectedly high CPU utilization.&lt;/p&gt;

&lt;p&gt;The tricky part?&lt;br&gt;
High CPU usage is rarely the actual problem.&lt;/p&gt;

&lt;p&gt;It's usually a symptom of something else happening inside your application, infrastructure, database, background jobs, or even your code architecture.&lt;/p&gt;

&lt;p&gt;I will explore the most common reasons behind high CPU consumption in Ruby on Rails applications. &lt;br&gt;
won't go too deep into each topic because every single one deserves.&lt;/p&gt;

&lt;p&gt;Let's get started with the reasons:&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;&lt;a href="https://dev.to/astmdesign/the-silent-performance-killer-in-rails-understanding-and-fixing-n1-queries-2ibb"&gt;1. N+1 Database Queries&lt;/a&gt;&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slow API responses&lt;/li&gt;
&lt;li&gt;Increased database load&lt;/li&gt;
&lt;li&gt;High application CPU usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;2. Missing Database Indexes&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slow endpoints&lt;/li&gt;
&lt;li&gt;High database CPU&lt;/li&gt;
&lt;li&gt;Increasing request latency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;3. Inefficient ActiveRecord Queries&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Excessive memory consumption&lt;/li&gt;
&lt;li&gt;Long request execution times&lt;/li&gt;
&lt;li&gt;CPU spikes during large queries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;4. Expensive Background Jobs&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU spikes during scheduled jobs&lt;/li&gt;
&lt;li&gt;Delayed Sidekiq queues&lt;/li&gt;
&lt;li&gt;Increased worker execution times&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;5. Memory Pressure and Garbage Collection&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU spikes without increased traffic&lt;/li&gt;
&lt;li&gt;Slow request processing&lt;/li&gt;
&lt;li&gt;High GC activity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;6. Excessive JSON Serialization&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API endpoints slower than expected&lt;/li&gt;
&lt;li&gt;High CPU during response generation&lt;/li&gt;
&lt;li&gt;Large response payloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;7. Traffic Spikes and Uneven Load Distribution&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only specific nodes experience high CPU&lt;/li&gt;
&lt;li&gt;Random server crashes&lt;/li&gt;
&lt;li&gt;Uneven infrastructure metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;8. External Service Bottlenecks&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Growing request queues&lt;/li&gt;
&lt;li&gt;Increased response times&lt;/li&gt;
&lt;li&gt;Thread pool saturation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;9. Inefficient Caching Strategies&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repeated database queries&lt;/li&gt;
&lt;li&gt;CPU spikes during peak traffic&lt;/li&gt;
&lt;li&gt;Reduced cache hit ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;10. Ruby Code That Doesn't Scale&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typical Symptoms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU increases with data growth&lt;/li&gt;
&lt;li&gt;Slow batch operations&lt;/li&gt;
&lt;li&gt;Performance degradation over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
When CPU usage becomes high, avoid jumping directly to conclusions.&lt;br&gt;
The real challenge isn't reducing CPU usage.&lt;br&gt;
The real challenge is identifying what's consuming the CPU.&lt;br&gt;
In future articles, we'll dive deeper into each of these topics, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detecting N+1 queries in production&lt;/li&gt;
&lt;li&gt;Database indexing strategies for Rails applications&lt;/li&gt;
&lt;li&gt;Sidekiq performance tuning&lt;/li&gt;
&lt;li&gt;Ruby Garbage Collection optimization&lt;/li&gt;
&lt;li&gt;API serialization best practices&lt;/li&gt;
&lt;li&gt;Infrastructure troubleshooting techniques&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember:&lt;br&gt;
High CPU is usually a symptom. Your job as an engineer is to find the disease.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
