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
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
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.
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
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
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
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
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.
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
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
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
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
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.
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
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