I talked about Rails4 (Edge Rails) at this event with @a_matsuda. matsuda-san talked about the overview of Ruby 2.0 and Rails4 and I did more details into Edge Rails toward the coming Rails4. We worked together well in spite of not planning in advance. Here's my slides:
The font used in the slides above is Movavi Font. This additional statement appears because I was asked by someone what font the slides use :)
Digging into the demo application
It's kind of a proof of concept how Rails4's ActionController::Live is promising. Here's the workflow of the application:
- Those connections are live streamings by ActionContoller::Live, newly introduced in Rails4
- Browsers send chat messages with plain XHR POST request.
- The messages are enqueued as jobs into queues implemented by Queue API.
- The jobs are dispatched, then messages above are published to Redis.
- As soon as messages are published, Redis broadcasts the messages to all the subscribers.
The demo application may look just a usual chat implementation. But I guess implementing chat-like system with Server-Sent Events + Redis Pub/Sub can be a possible solution for scalable realtime architecture. I wrote about it in this post before.
The diagram below shows that idea:
As you can see, Rails app servers and Redis slaves are scalable, that is, you can easily scale out your realtime system by just putting another servers. This architecture has some good points, I think.
- The architecture is simple and scalable.
- SSE is easier to understand than WebSockets.
- The application is easy to implement by many languages (of course not limited to Rails)
I wonder if I should choose Rails 4 to implement realtime apps which has such an architecture shown above, though. Nevertheless, it's obvious that Rails now provides an alternative against Node or other languages.