System test: asserting Turbo Stream responses

I don’t test Hotwire behavior by guessing; I add system tests that exercise the UI. With Capybara, I click a button that triggers a Turbo Stream response and assert that the DOM changes without a full page reload. The exact assertion depends on the fe

Exponential backoff with jitter for retries

Immediate retries are a great way to stampede a struggling dependency. I use exponential backoff with jitter so retries spread out naturally and don’t synchronize across instances, and I cap the maximum delay so worst-case latency doesn’t become unbou

Turbo Frames: infinite scroll with lazy-loading frame

Infinite scroll can be done with plain HTML + Turbo Frames. Render a “next page” frame with loading: :lazy so Turbo fetches it when it enters the viewport. No JS required, and it degrades gracefully.

Django model signals vs overriding save

Signals and save overrides both handle model events, but have different use cases. I override save() for logic intrinsic to the model. Signals decouple logic across apps—I use them when multiple apps need to respond to model changes. Signals can make

Resilient CSV Export as a Streamed Response

Large CSV exports should not allocate huge strings. Use ActionController::Live to stream rows. Include a heartbeat and handle client disconnects gracefully. This is real-world Rails ops code.

Filter UI that syncs query params via Stimulus (no front-end router)

Filters are better when the URL reflects state. I use a small Stimulus controller that updates the query string as filters change, then triggers a Turbo visit (often with data-turbo-action='replace'). This gives shareable URLs and correct back-button

Shallow Controller, Deep Params: Form Object Pattern

When controllers become parameter jungles, use a form object. It centralizes coercion, validations, and save logic. This pattern is extremely effective for admin panels and multi-step flows.

Remove deleted items instantly with turbo_stream.remove

Destructive actions should feel immediate. For delete links inside a list, I return a Turbo Stream that does turbo_stream.remove dom_id(record). That removes the DOM node without re-rendering the rest of the list, which avoids the common “jump” effect

Django URL namespacing and reverse lookups

URL namespaces prevent name collisions across apps. I set app_name in app-level urls.py and use namespace in include(). Reverse lookups use reverse('namespace:name') or {% url 'namespace:name' %} in templates. This makes URLs maintainable when refacto

Simple concurrency limiter for batch operations

Unbounded Promise.all is a great way to overload your DB (or a third-party API). I use a small concurrency limiter so I can process batches efficiently while keeping backpressure. This is especially useful for migrations, backfills, and webhook replay

Debounced live search with Stimulus + Turbo Streams

For search-as-you-type, I keep the server in charge and use a small Stimulus controller to debounce form submission. The controller listens to input events, waits ~250ms, then triggers a normal Turbo form submit. The server responds with index.turbo_s

JWT access + refresh token rotation (conceptual)

A single long-lived JWT is a liability: if it leaks, it’s valid until it expires and revocation is hard. I use short-lived access tokens and longer-lived refresh tokens, and I rotate refresh tokens on every use. Rotation means that if an attacker stea