Deduplicate Outgoing Messages

Learn how to deduplicate outgoing messages.

We'll cover the following

Outgoing messages

Preventing duplicate outgoing messages is an excellent exercise in Channel customization. The solution to this problem must be implemented as close to the client as possible. This is because that way, we can be sure of what messages were sent to a particular client. Channels are the lowest-level process we control between a single client and our server. This makes them the perfect location for us to achieve this task.

In the last example, we used Socket.assigns to store a state that is relevant to our Socket. In this example, we’ll be using Socket.assigns to store a relevant state to our Channel.

We can put anything we want in Socket.assigns. Any data that we add to Socket.assigns is for our Channel process only and won’t be seen by other Channel processes, even Channels that use the same Socket. This can be unclear at first but makes sense when we consider that Elixir is functional and generally side-effect free.

Note: If we modify the state of a Channel process, other processes in the system are not affected.

Let’s start by adding a new Channel route.

Get hands-on with 1200+ tech skills courses.