• WebSockets connections are stateful. • Connection between a client and a server remains constant and connected • Direct interaction between browser and server • Enables simultaneous communication (full duplex)
E • Integrated WebSockets for Rails • Real-time features written in Ruby in the same style and form as the rest of the Rails application • Provides both the client-side JS framework and a server-side Ruby framework. • Access to domain model written with Active Record
E • Cable or Connection - single Websocket connection from client to server • Channels - one Cable connection has many Channels • Broadcastings - one Channel can be streaming from zero or more broadcastings • Broadcaster - Action Cable has its own server (we need to run another server process). Uses Redis pubsub functions to keep track of what’s been broadcasted on what cable and to whom.
AT M AY N E E D W E B S O C K E T S A S A S O L U T I O N • Clients needs to exchange (send and receive) rapidly data with the server • Streaming • “Live” data or “Live” elements
O L U T I O N S T O T H E S E P R O B L E M S • Polling • Polling involves the client asking the server, on a set interval if there is any new data • The advantage of polling is that it's rock-solid and extremely simple to set up • The disadvantage is that it adds considerable load to the servers • HTTP caching is a very good to alleviate the load, but the server still has to respond to every client every • It is ok for comments sections but not ok for rapid back- and-forth or streaming data
O L U T I O N S T O T H E S E P R O B L E M S • Long-polling • Client sends a request to the server for new data and waits for the server response until they have new data • Falls apart if data changes often • Server-sent Events (SSEs) • One-way connection from the server to the client • Clients can't use SSEs to send data back to the server • Not so well supported (Ex: Heroku and Internet Explorer)
regular MVC setup (like the Rails controllers) • Can be subscribed by multiple clients (consumers) • Each channel can be streaming zero or more broadcastings • A broadcasting is a pubsub link where anything transmitted by the broadcaster is sent directly to the channel subscribers who are streaming that named broadcasting H O W A C T I O N C A B L E W O R K S : S E R V E R S I D E