Blog

Thoughts on software engineering, web development, and technology

S
Sam Lee

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.

Apr 03, 2026·SDK Design
S
Sam Lee

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.

Mar 30, 2026·Hotwire
S
Sam Lee

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.

Mar 25, 2026·Ruby on Rails
S
Sam Lee

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.

Mar 19, 2026·Ruby on Rails
S
Sam Lee

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.

Mar 18, 2026·SQL
S
Sam Lee

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.

Mar 18, 2026·SQL
S
Sam Lee

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

Mar 17, 2026·PostgreSQL
S
Sam Lee

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

Mar 16, 2026·PostgreSQL
S
Sam Lee

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

Mar 15, 2026·PostgreSQL
S
Sam Lee

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

Mar 14, 2026·Ruby on Rails

Built by Sam Lee with

 ♥