FirstDEV blog
  • Home
  • Ruby
  • Ruby On Rails
  • Tips
  • Solutions
  • About
Subscribe
cdrrazan

Rajan Bhattarai

Full Stack Software Developer! 💻 🏡 Grad. Student, MCS. 🎓 Class of '23. GitKraken Ambassador 🇳🇵 2021/22. Works with Ruby / Rails. Photography when no coding. Also tweets a lot at TW / @cdrrazan!

195 posts •
Developer tips

Environment Variables Done Right — dotenv Patterns and Production Pitfalls

ENV["STRIPE_KEY"] returns nil in production and the app boots anyway, quietly using no key, until the first payment fails four hours later. Environment variables are the simplest configuration mechanism available and the one

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Bulk Insert Records With Insert_all And Skip Duplicates In Rails

Importing thousands of rows one create! at a time issues one INSERT per record plus validations and callbacks. insert_all sends a single multi-row INSERT, which is orders of magnitude faster for imports and

Rajan Bhattarai Rajan Bhattarai 2 min read
Developer tips

Reading a Stack Trace Like a Senior Engineer

A junior developer sees a stack trace and copies the top line into Google. A senior developer sees the same trace and knows within fifteen seconds which of their own files to open.

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Prevent Duplicate Form Submissions In Rails With An Idempotency Key

A user double-clicks Submit, or a mobile client retries after a timeout it thought had failed. Two identical requests arrive and you create two orders. Disabling the button in JavaScript does not solve

Rajan Bhattarai Rajan Bhattarai 2 min read
Ruby 3

Memoization at Depth — Where ||= Works, Where It Quietly Breaks

@value ||= expensive_call is the first optimization most Ruby developers learn and the one they keep using long after it stops being correct. It works beautifully for a non-nil, non-false result computed from

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Background Job Architecture — Retries, Dead Queues, and Idempotency in ActiveJob

ChargeCustomerJob.perform_later(order) looks like a function call and behaves like a distributed system. It runs on another machine, at an unknown time, possibly more than once, possibly never. Most job bugs come from writing

Rajan Bhattarai Rajan Bhattarai 11 min read
Developer tips

Load Testing Locally With wrk — Know Your App's Ceiling Before Deploy

“It’s fast enough” is a claim about a single request from one browser on a warm cache. It says nothing about what happens at fifty concurrent users, which is the number that actually

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Query Records Created Or Updated In The Last N Hours In Rails

Dashboards, digest emails, and sync jobs all need “what changed recently”. Rails’ duration helpers plus a beginless or endless range make this readable and, crucially, index-friendly.

Rajan Bhattarai Rajan Bhattarai 1 min read
Rails

Strict Loading in Rails — Eliminating N+1 at the Framework Level

Every Rails team has the same conversation eventually. Someone adds bullet to the Gemfile, fixes the twelve N+1 queries it finds, and six weeks later there are eight new ones. Detection tools tell

Rajan Bhattarai Rajan Bhattarai 9 min read
Developer tips

Git Bisect — Find the Regression-Introducing Commit in Under 10 Minutes

Something worked last month. It doesn’t work now. Between then and now there are four hundred commits, three of them yours, and nobody remembers touching that code. The instinct is to start reading

Rajan Bhattarai Rajan Bhattarai 10 min read
Ruby-code

Retry A Block N Times With Exponential Backoff In Ruby

Network calls, external APIs, and flaky I/O fail intermittently. Retrying immediately usually fails again — the remote service needs a moment. Exponential backoff spaces retries out so each attempt has a better chance

Rajan Bhattarai Rajan Bhattarai 2 min read
Developer tips

Tmux for Persistent Dev Sessions — The Setup That Survives Reboots

You have six terminal tabs open: server, console, test watcher, logs, git, and one you’ve forgotten the purpose of. Your laptop restarts for an update and all six are gone, along with the

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Paginate Activerecord Results Without A Gem Using Limit And Offset

Kaminari and Pagy are excellent, but a JSON API or an internal admin screen often needs nothing more than a page number and a page size. ActiveRecord gives you that in two methods.

Rajan Bhattarai Rajan Bhattarai 2 min read
Ruby 3

Writing Cleaner Ruby — The Terser Syntax Patterns Worth Adopting

Ruby has quietly accumulated a set of shorthands over the 3.x series — numbered block parameters, hash value omission, rightward assignment, anonymous argument forwarding. Each removes a small amount of ceremony. Adopted carelessly

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails

Solid Cache — Replacing Redis With Your Database, and When Not To

Every Rails app reaches the point where it needs a cache store, and the reflex answer has been Redis for a decade. Solid Cache challenges that by putting the cache in the database

Rajan Bhattarai Rajan Bhattarai 10 min read
« Newer Posts Page 5 of 13 Older Posts »
FirstDEV blog © 2026
Proudly published with Jekyll & using Jasper2
Latest Posts Twitter
FirstDEV blog

Check viewARU - Brand Newsletter!

Newsletter to DEVs by DEVs - boost your Personal Brand & career! 🚀