Untangling cables and demystifying twisted transistors, by Vladimir Dementyev

Elevator Pitch

Rails brought building reactive web applications to the next level. Zero JS, no knowledge of WebSockets—just good old Rails! Action Cable and Hotwire make simple things simple. Still, to make complex things possible, we must learn what's under the hood and turn this knowledge into a superpower.

Abstract / Description

More and more Rails applications adopt real-time features, and it’s not surprising—Action Cable and Hotwire brought development experience to the next level regarding dealing with WebSockets. You need zero knowledge of the underlying tech to start crafting a new masterpiece of web art! However, you will need this knowledge later to deal with ever-sophisticated feature requirements and security and scalability concerns.

The variety of questions that arise when developers work with Rails’ real-time tooling is broad, from “Which delivery guarantees does Action Cable provide?” to “Can I scale my Hotwire application to handle dozens of thousands of concurrent users?”. To answer them, we need to learn our tools first.

In my talk, I will help you better to understand Rails' real-time component—Action Cable. I want to open this black box for you and sort through the internals so you can work with Action Cable efficiently and confidently.

Details

The talk can be split into three major parts: Action Cable abstractions, implementation details, and Hotwire’s Turbo Streams design.

We will peel the layers off the framework step by step during the talk, starting with user-facing features—abstractions (or Ruby APIs). (And from time to time, I want to refer to the history of Action Cable to show the current state and the evolution—you can’t understand today without understanding what came before).

  • Intro, or back in 2015. In a short intro, I want to share some history highlights and the Action Cable diagram from the first-ever presentation mentioning it. The diagram is vital for the talk: I want to enhance it gradually, and in the end, we will have a complete map of the Action Cable continent and the Hotwire archipelago with all the details.
  • Server-side abstractions, or the beauty of channels. Let’s talk about the unique design of Action Cable (streams encapsulation via channels), how it differs from other popular frameworks (from Socket.io to Phoenix), and, what’s important, which possibilities and strong (well, and weak) points arise from this design.
  • The client-side reflections, or how channels work in JS. (Did you know that it all started with CoffeeScript in 2015). Here I want to mention the essential features of the client-side package (and challenges it has seen along the way): automatic connection failure handling and multiplexing (or why you shouldn’t worry about creating multiple JS channel subscriptions for the same channel).
  • Broadcasters. Here we dig deeper into the pub/sub functionality and learn about all the phases between `ActionCable.server.broadcast` and the `receive(msg)` on the client side. I want to cover the topics of data serialization and consistency along the way (+ some upcoming Rails 7.1 features). Also, I want to show how to build a custom broadcasting adapter and the potential use cases (e.g., throttling).
  • Action Cable protocol and how to live with it. Let’s look at Action Cable from the WebSockets point of view, not Rails. Which messages are sent over the wire? What are their meanings? Technically, we can open a browser console and see the actual communication flow. Learning the protocol is essential if you want to build a client for the platform without official Action Cable support. It’s also important to understand the limitations of the protocol: its RPC incompleteness and errors-indifference.
  • Action Cable server—the real-time heart of the application. We learned about the protocol, but the actual connection handling is protocol-agnostic. Let’s learn how it’s implemented in Rails and what you should know about it. The most popular unknown for Rails developers is the workers thread (and its size), which can be a source of Active Record connection pool timeout problems if you don’t take it into account. I also want to discuss the threaded model and alternative implementations (e.g., Async-based or non-Ruby based). Also, I want to cover the topic of separating Web and Cable servers in production (and how to do that), so we can scale them independently.
  • The beauty of Hotwire—how Hotwire made it possible to reduce the amount of JS code to zero, what is signed streams, and how we can enhance the default Turbo Streams behavior (via custom channel classes).
  • The end. I present the “Map of Action Cable and Hotwire” we discovered during the talk and recall the key points.

For the talk, I tried to pick the topics which lie at the intersection of hidden/internal and valuable. And I extracted the “usefulness” metrics from my experience helping developers demystify Action Cable.

The ultimate goal of this talk would be upgrading the Rails guides chapter on Action Cable to include all the tiny (but important) details I want to present in the talk.

Pitch

I’ve been following Action Cable since its very first appearance. I can even say more—the library and its effects on the community greatly impacted my professional and open-source career. Partially because I wanted to improve it, I started contributing to Rails and building my own projects. But mostly because it made building real-time with Ruby and Rails accessible and, eventually, popular. And real-time and Ruby are Top-2 my programming passions.

How and why I came up with the talk idea? I’ve been pondering the idea of writing a comprehensive something (book?) on Action Cable for a while, so I already had some key points in mind. And I saw a tweet-call-out for RailsConf talks on “Rails internals or some Rails hidden features you know about”—that’s how two and two made four.

For the talk, I tried to pick the topics which lie at the intersection of hidden/internal and valuable. And I extracted the “usefulness” metrics from my experience helping developers demystify Action Cable.

The ultimate goal of this talk would be upgrading the Rails guides chapter on Action Cable to include all the tiny (but important) details I want to present in the talk.

Edit proposal

Submissions

Rails World 2023 - Accepted [Edit]

Add submission