Django haystack for advanced search

Haystack provides unified search across backends (Elasticsearch, Solr, Whoosh). I define search indexes mapping models to searchable fields. It handles full-text search, faceting, and highlighting. The SearchQuerySet API is similar to Django's ORM. I

Turbo Streams: server-driven redirect (Turbo Native friendly)

Sometimes you want to “redirect” from a turbo stream response (especially for Turbo Native flows). Returning a stream that updates a frame to include a turbo-visit shim keeps behavior consistent across clients.

Bulk operations with ActiveRecord import

Inserting thousands of records one-by-one is prohibitively slow due to the overhead of individual INSERT statements. The activerecord-import gem provides bulk insert capabilities that compile multiple records into a single multi-row INSERT, dramatical

Importmap setup for Stimulus controllers (Rails 7 style)

If you’re using importmap, a clean Stimulus setup matters: it keeps controllers discoverable and avoids mystery load order bugs. I pin @hotwired/turbo-rails and @hotwired/stimulus, then use controllers index discovery to register everything. The payof

Robust environment parsing for bool/int with explicit defaults

I like config that fails loudly when it’s wrong. The helpers below parse environment variables with explicit defaults and good error messages, which prevents subtle “zero value” behavior in production. This is especially important for flags like ENABL

Link that submits DELETE with Turbo (data-turbo-method)

In Hotwire apps, I still use Rails’ RESTful routes heavily. For destructive actions from a link, data-turbo-method='delete' is the cleanest approach: you keep semantic links where appropriate and let Turbo perform the method override. I usually pair i

Sampling logs to reduce noise during high-QPS incidents

Structured logs are great, but at high QPS they can become their own outage: too much IO, too much storage, and noisy dashboards. zap includes a sampler that allows you to keep early logs and then sample at a fixed rate. I like this for “successful re

Redis-Based Distributed Mutex (with TTL)

Sometimes you need “only one runner globally” (backfills, refresh jobs). A Redis mutex with TTL avoids deadlocks if the process dies. It’s not perfect, but it’s a solid pragmatic tool.

Turbo Drive lifecycle: attach global error handler

You’ll eventually hit non-200 responses or network flakiness. Hook Turbo events to log failures (and optionally show a toast). This is a pragmatic production addition that helps debugging without adding heavy tooling.

Action Cable Presence Tracking (Lightweight)

Presence is often more about “who is here now” than perfect accuracy. Use Redis sets with expiries updated by pings. This keeps the system simple and operationally understandable.

Stimulus: nested fields add/remove without re-rendering

For nested forms, Stimulus can manage the DOM while Rails handles the final params. Use a hidden template + a unique timestamp key. This keeps the server-rendered form simple and avoids JS frameworks.

Per-Request Query Budget (Detect Runaway Pages)

Set a rough query budget per request in dev/test and alert when exceeded. This is a pragmatic way to keep performance regressions visible without requiring a full APM setup.