Presence indicator with ActionCable + Turbo Streams

14327
0

Presence is usually overkill, but for collaboration features it’s valuable: show who’s online in a room. I identify connections with current_member in ApplicationCable::Connection, then in a channel I broadcast updates when members subscribe/unsubscribe. The UI subscribes with turbo_stream_from @room and renders a partial listing online members. I keep the data minimal and ephemeral: store online member IDs in Redis or a simple in-memory store (depending on deployment), and never treat presence as security. The Turbo approach is nice because updates are HTML fragments, so styling is consistent and you don’t build a JSON protocol. The main gotcha is scale: presence can be chatty, so throttle broadcasts and keep the partial fast.