Skip to content

Add Railway deployment guide#52

Closed
irinanazarova wants to merge 3 commits intomasterfrom
docs/railway-deployment
Closed

Add Railway deployment guide#52
irinanazarova wants to merge 3 commits intomasterfrom
docs/railway-deployment

Conversation

@irinanazarova
Copy link
Copy Markdown

Summary

Adds a deployment guide for Railway, covering the full path from Solid Cable to AnyCable-Go in production.

Based on real migrations of two Rails apps (Fizzy and Solaris) to AnyCable on Railway, with every pitfall we hit documented inline.

What's covered

  • AnyCable-Go service — Docker image setup, env vars, via dashboard and Railway CLI
  • Rails configuration — gem, cable.yml, anycable.yml, initializer (secrets + Turbo verifier key in one file), production.rb
  • Authentication — JWT meta tag for cross-domain, connection.rb guidance
  • Client-side JS — importmap-rails (vendoring + alias pin + turbo import patching) and jsbundling-rails (just npm install)
  • CSP — URI.parse-based origin extraction
  • Development mode — keep Solid Cable for dev, AnyCable for prod
  • Presence — complete Hotwire example with <turbo-cable-presence-source>
  • Scaling — memory vs NATS broker
  • Verification — browser DevTools checklist, broadcast test, Railway CLI logs
  • Troubleshooting — integrated at each failure point

Pitfalls documented from real deployments

  • anycable/anycable-go:latest may be too old for presence (pin to 1.6)
  • @anycable/turbo-stream vendored file needs patching for importmap-rails (named imports vs Turbo namespace — this should be fixed in the npm package)
  • signed_stream_verifier_key must be in after_initialize
  • HTTP broadcast port is 8080 (not 8090) when ANYCABLE_SECRET is set
  • ANYCABLE_URL (public, browser-facing) vs ANYCABLE_HTTP_BROADCAST_URL (private, *.railway.internal)
  • CSP blocks WebSocket if connect-src doesn't include the AnyCable-Go origin
  • System tests break silently if vendored JS imports fail

Note on @anycable/turbo-stream npm package

The package imports { connectStreamSource } from @hotwired/turbo as a named export. This works with jsbundling (real npm package) but breaks with importmap-rails (turbo.min.js from turbo-rails nests it under Turbo). This causes a silent SyntaxError that kills all JS on the page. The guide documents a manual patch, but the package itself should be fixed to handle both:

import * as TurboModule from "@hotwired/turbo"
const { connectStreamSource, disconnectStreamSource } =
  TurboModule.connectStreamSource ? TurboModule : TurboModule.Turbo

Covers deploying AnyCable-Go + Rails on Railway with:
- HTTP broadcasting over private networking (no Redis)
- JWT authentication for cross-domain WebSocket
- Turbo Streams + importmap-rails setup with vendored JS
- Presence indicator example
- Railway CLI commands alongside dashboard instructions
- Troubleshooting for common pitfalls (CSP, version pinning,
  signed stream verifier key load order, broadcast port)
@palkan
Copy link
Copy Markdown
Member

palkan commented Mar 31, 2026

The only relevant bits are how to use railway cli to deploy anycable-go and CSP configuration (though it also must be a part of the general Rails guide). Everything else is unrelated to Railway deployment (and full of incorrect instructions, e.g., initializers, import maps, NATS, etc.).

@palkan palkan closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants