website logo

← All articles

Hotwire/Turbo in Production: What We Learned Shipping a Real-Time App Without a SPA

We bet on Hotwire for a real-time internal dashboard last year. The pitch was irresistible: no JSON API, no separate frontend build, no duplicated state. Six months in production, I can tell you the bet paid off but not in the way the usual public demos suggest. Here are the war stories that matter.

The Morphing Pitfalls Nobody Warns You About

Turbo 8’s morphing via idiomorph is genuinely magical when it works. It’s also the source of our two most painful production bugs.

The autofocus scroll jump. We had a search input with autofocus in a header. Every time a broadcast refresh morphed the page, the viewport jumped to the top; mid-scroll, mid-reading. The fix was trivial (remove autofocus, use a Stimulus controller to focus conditionally), but finding it took hours. Morphing diffing triggers focus and scroll behaviors you’ve long forgotten about in your markup.

The form-wipe problem. This one hurt. A broadcasted refresh would morph the page while a user was typing into a form. Idiomorph saw the server’s clean form and the user’s dirty form, decided the server was authoritative, and wiped their work. The data-turbo-permanent attribute around the form solved the wipe, but broke submission reset for the submitting user. Our eventual fix was a Stimulus controller that clears the form explicitly after a successful submission, combined with data-turbo-permanent on the wrapper. It works. It’s not elegant. You will need a similar workaround.

Broadcast Reliability: It’s Not Magic, It’s Infrastructure

Turbo Streams over Action Cable is the part everyone demos and the part that breaks first at scale. We hit the WebSocket stampede around 2,000 concurrent connections on our Redis-backed Action Cable setup: erratic disconnects, CPU spikes from connection overhead, and the delightful experience of users seeing stale data with no error indication.

Our lessons:

Silent failures are the default. A failed Turbo Stream broadcast doesn’t throw a visible error in the browser. The page just… doesn’t update. We added a turbo:before-fetch-response listener to surface stream delivery failures, and instrumented our broadcast jobs with ActiveSupport::Notifications to track render times. Monitor broadcasts like you monitor database queries: they’re just as critical to the user experience.

Place your turbo_stream_from carefully. In one legacy bug, a developer initially put one inside a Turbo Frame that got replaced. Subscription silently destroyed, real-time updates gone. It must live in the <body> at the top level, outside any frame that gets swapped. Obvious in hindsight, invisible during development when you’re not navigating away from the page.

Consider Solid Cable before Redis. For our next project, we’re evaluating Solid Cable (database-backed Action Cable) for lower connection counts. The tradeoff is latency: Solid Cable polls at an interval, so sub-100ms real-time is off the table. For notifications and dashboard updates, 60-100ms is fine. For collaborative editing, you’d want AnyCable or Redis.

Stimulus Controller Patterns That Actually Scale

Stimulus is the glue. The pattern that saved us was treating Stimulus as stateless behavior, not state management.

Keep controllers small and disposable. Our rule: if a Stimulus controller holds state that survives more than one interaction cycle, it’s doing too much. Morphing will disconnect and reconnect controllers in ways you don’t expect. A controller that assumes connect() runs once will break. Use connect()/disconnect() as your only lifecycle guarantees, and never store anything in instance variables that morphing could invalidate.

Outlets over global events. We started with document.dispatchEvent for cross-controller communication. It was a mess of implicit dependencies. Switching to Stimulus Outlets made the relationships explicit and debuggable. A tabs controller declaring static outlets = ["tab-panel"] tells you everything about its dependencies at a glance.

Values API for reactive state. The Values API is underused. Instead of manually toggling classes and attributes in JavaScript, declare a value and react to its change callback. It keeps DOM updates declarative and morph-safe.

When We Still Reached for React

Two features in our app have React. We didn’t fight it.

The complex data grid. Our dashboard has a spreadsheet-like grid with column resizing, cell editing, virtual scrolling, and keyboard navigation across thousands of rows. Hotwire can theoretically handle this with enough Turbo Frames and Stimulus, but the complexity budget would have been absurd. React plus TanStack Table was the right call.

The drag-and-drop pipeline view. Kanban-style boards with real-time collaboration (two users moving cards simultaneously) required client-side conflict resolution and optimistic UI that morphing couldn’t provide cleanly. React with a lightweight state layer, fed by a JSON endpoint, stayed isolated and sane.

The hybrid architecture works because the boundary is clear: Hotwire owns the shell, navigation, CRUD, notifications, and dashboards. React owns the two widgets that need it. They communicate through Turbo Frames and a small JSON API. No global SPA. No duplicated routing. No build pipeline for 90% of the app.

The Verdict

Hotwire in production is not “no JavaScript.” It’s the right JavaScript in the right places, with the server owning state and HTML owning truth. The failures we hit were all in the seams - morphing assumptions, broadcast visibility, controller lifecycle - not in the core premise.

If you’re building a CRUD-heavy app with real-time enhancements, Hotwire will get you there faster than a SPA, with less infrastructure and fewer moving parts. Just budget time for the seams. They’re where the learning happens.