Blog
Thoughts on software engineering, web development, and technology
When Your SDK Does Too Much (And Not Enough)
Refactored a shared API client gem to separate payload signing from HTTP transport, added Faraday with retry and rate-limiting, and built backward compatibility into the breaking change so existing callers keep working during migration.
When Turbo Stream Replace Kills Your Search Input
Every keystroke in a search bar was resetting the cursor because one big Turbo Stream replace was swapping the entire container — including the input. Splitting the stream into targeted update and replace actions for metrics and table separately fixed it.
The Unbounded Query That Took Down an Endpoint
An endpoint was loading every row in a table because the controller used Model.all instead of scoping by the profile parameter already in the URL. Scoping the query, eager loading, and handling orphaned attachments and a Turbo Frame mismatch brought it from 228 queries and 504 timeouts to 30 queries and fast loads.
The N+1 That Was Hiding Next to Its Own Fix
The dashboard fired about 48 queries per load—one per active subscription. The batch preloader and resolver logic already existed 15 lines away for a sibling feature. Wiring the same pattern and fixing missing-hash keys dropped it to one query.
Why EXISTS Beats JOIN When You Just Need to Filter
Was JOINing a table just to filter by it, which created duplicate rows and needed DISTINCT. Switched to EXISTS — no extra rows, no deduplication, and moved N+1 lookups into a single SQL subselect.
When Your Filter Logic Fights Your Archival Logic
A dashboard filter used INNER JOIN on archived records to list items. A separate feature intentionally archived those records for a specific user type. Result: those users saw nothing.
How PostgreSQL Actually Runs a Query
A practical mental model for how PostgreSQL reads data, uses shared_buffers and work_mem, and decides when a large query has to spill to disk
Why Index Only Scan Still Hits the Heap
Why PostgreSQL sometimes reads the main table millions of times even when the query plan says Index Only Scan
Why Autovacuum Defaults Stop Working on Large Tables
PostgreSQL's percentage-based autovacuum defaults can look reasonable until the table gets large enough that cleanup happens far too late
Why My Analytics Dashboard Showed No Data
A bulk insert pipeline was skipping callbacks, which left key analytics fields blank and turned a small fix into a much larger backfill
Built by Sam Lee with
♥