We’re always seeking the best tool for the job at hand. Just when we think we’ve found it, we’re faced with a new use case or framework — which keeps us asking questions and evaluating options. Today, I'm exploring the performance of the Rails and Phoenix web frameworks when put up against the same task: building a very simple chat application.
- Show how to build a (very) simple chat in both frameworks
- Weigh the pros and cons of each framework for real-time interactions
Out of the box features
- Rails: With Rails 5, you've got everything you need for websocket communication. Nothing else is needed except a clean Rails install — unless you’re doing test-driven development (TDD). In that case, you'll notice that the built-in Rails testing tools don’t accommodate channels — yet!
- Phoenix: Phoenix comes with all the out-of-the-box socket features you could ever want, including testing tools. However, I had to set up Postgres to get the server running without errors, and I included jQuery for convenience.
Ease of use
- Rails: The ActionCable documentation feels a little scattered and disorganized. A lot of information is dumped on the reader without a thorough explanation. For instance, the stream_from and stream_for methods are hardly addressed. That said, nothing here is too difficult to overcome with a little trial and error.
- Phoenix: In my opinion, the Phoenix Channel documentation is vastly superior to the Rails documentation, and their test documentation is also great. The pattern matching abilities make the API a little simpler to explore and understand.
Rails and Phoenix have gone head-to-head in other well-run experiments — and I don’t feel it’s necessary to recreate those tests because their results appear to be pretty conclusive.
While both frameworks now support sockets and channels out of the box with relative ease, Rails simply can’t match the documentation and performance that Phoenix provides. If you need real-time web apps that can communicate using the WebSocket protocol, I strongly recommend that you consider Phoenix.