When to Write a New Socket
We’ve written two Sockets so far, UserSocket and AuthSocket, and we wrote Channels for each of them. This raises the question of when we should create a new Socket versus using the same topic and adding a new Channel. You’ll make this decision based primarily on the authentication needs of your application. There are also performance costs to adding new Sockets; let’s look at these costs first.
Each connected Socket adds one connection to the server, but each connected Channel adds zero new connections to the server. Channels do take up a slight amount of memory and CPU because there is a process associated with each, but you can consider Channels nearly free because processes are cheap in Elixir. Sockets are a bit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access