Search⌘ K
AI Features

When to Write a New Socket

Understand how to optimize real-time application architecture by deciding when to write a new Socket or add a Channel. Explore authentication requirements and performance impacts to ensure secure and efficient Phoenix applications.

We'll cover the following...

Writing 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. We’ll make this decision based primarily on the authentication needs of our 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. Channels do take up a slight amount of memory and CPU because there is a process ...