Solving the N+1 Query Problem in Rails

Introduction If you’ve worked with Rails for some time, you’ve probably seen performance issues that did not make much sense at first. One of the usual suspects is the N+1 query problem. It is easy to miss, and it can quietly slow things down as your data grows. What is the N+1 Problem? In simple terms: You load a list of records (1 query) Then Rails runs one query per record to fetch associated data A quick example: ...

January 21, 2026 · Mausam Pun

Setting Up CI for a Multi-Database Rails App When One DB Is Read-Only

🚨 The Problem Everything worked fine locally, but CI kept failing. I was working on a Rails application that used two databases: A primary database (fully controlled by the app) A secondary database (owned by a different application) The catch was this: 👉 The secondary database was read-only from my app’s perspective. Locally, this was not a problem because the database already existed and had the expected schema. But in CI: ...

December 19, 2025 · Mausam Pun

Optimizing Slack API Usage in a Rails App with Caching

🚨 The Problem I was working on a Rails app that used Slack for two main things: Mapping Slack users to our HR app Sending notifications to Slack users or channels Everything looked fine locally, but in staging and production Slack rate-limit errors (429 Too Many Requests) started showing up: Mapping users required fetching the Slack user list repeatedly Sending notifications in bulk triggered multiple API requests in a short time Some requests failed, causing unreliable notifications and mapping 🔍 Root Cause Slack has strict rate limits for each API method. ...

October 23, 2025 · Mausam Pun