Operations | Monitoring | ITSM | DevOps | Cloud

N+1 Queries in Rails: A Guide to Detection and Prevention

N+1 queries are the most common performance problem in Rails applications. ActiveRecord’s lazy loading means every belongs_to, has_many, and has_one association is a potential N+1 waiting to happen. The good news is that Rails gives you multiple ways to fix them, and tools like Scout can find them automatically. This guide covers everything a Rails developer needs to know about N+1 queries: what they are, how to fix them, how to prevent them in CI, and how to detect them in production.

What is Application Performance Monitoring (APM)?

A modern web application is not a single thing. A single user request may touch a web server, a database, a cache layer, and several third-party APIs before a response comes back. And as AI tools generate more and more application traffic (API calls, background jobs, automated workflows), the volume and unpredictability of that traffic is growing. When something goes wrong, it could be any of it. When something is slow, it could be all of it at once.

The 9 Application Performance Metrics You Need to Measure and Why

The tension between shipping speed and application performance has not changed much since this post was first published in 2020. What has changed is how quickly a team can detect, diagnose, and fix a problem. That difference is significant enough to warrant a revisit. The scenario from the original still plays out every week. Sales brings a priority feature that might degrade performance for some customers. The developer ships it and watches what happens.

How We Do Support at Scout

Today, we are taking a break from your regularly scheduled technical programming to talk about support. Here at Scout, we consider support one of our differentiators, and even as we adopt AI as a human multiplier behind the scenes, we are committed to keeping it real on the human-interaction side. It will be a long time, if ever, that you reach out to us and get a response from an AI agent. Would it be cheaper? Sure, but it isn’t up to our standards, and we won’t compromise on that.

Stop Starting Your Day in a Stack Trace

Most teams triage errors the same way. Check the error tracker in the morning, skim the stack traces, pick the ones that look urgent, start investigating. The rest pile up. By the time anyone gets to the long tail of production errors, the context is stale and the motivation is gone. What if that first pass happened automatically? We’ve been experimenting with a workflow that connects Scout’s error data to AI assistants through our MCP server.