Hi! We’re currently deployed on AWS ECS with an ALB load balancer with sticky sessions enabled. We’re looking at deploying elsewhere and I’m curious if we still need sticky or affinity sessions.
We store quite a bit of state in the channel. The client tells the server which models/queries it wants to subscribe to and and the channel on the server uses Endpoint.subscribe
to subscribe. Here’s an example (simplified)
defmodule WebApp.SessionChannel do
def handle_in("subscribe", model_uuid, socket) do
WebApp.Endpoint.subscribe("model:" <> model_uuid)
end
end
When changes come in, the server broadcasts those changes using Endpoint.broadcast!
to any connected clients. E.g.
def handle_in("mutation", %{id => model_uuid, mutation => mutation}, socket) do
modify_db(mutation)
WebApp.Endpoint.broadcast!("model:" <> model_uuid, "update", mutation)
end
And, lastly, the channel pushes any updates for subscribed topics to the client:
def handle_info(%Broadcast{topic: "model:" <> _id, event: "update", payload: mutation}, socket) do
push(socket, "model-update", mutation)
end
My understanding is we need the channel to the be alive for the subscriptions to stay alive and we need the client connecting to the same server to keep the channel alive. Thus, we need sticky sessions.
Is that accurate?