Wrapping Up

Let's highlight the main contents of this chapter.

We'll cover the following

The importance of tests

Tests that are easy to read and modify are essential for having an application that any teammate can maintain in the future. These tests also help identify errors in code.

Author’s Note: When I created the DedupeChannel, I discovered a bug where the pushes would happen incorrectly. The tests that I wrote revealed the bug to me. The value of well-written tests never decreases, even for experienced programmers.

Wrapping up

Writing real-time applications requires us to consider the unreliable nature of long-lived connections. Users can disconnect at any time, so our applications must be developed with this in mind. A source of truth that lives outside of the connection lifecycle is one of the best ways to combat the challenges of unreliable connections.

Applications in production should always have multiple servers to ensure uptime, even when something goes wrong. Channels are usable across multiple servers, with only a tiny amount of work necessary to ensure everything works as expected. Distributing our application over multiple servers adds new challenges, but it can significantly improve scalability and reliability.

It’s possible to both write and test complex business logic in Channels. Phoenix gives us the right foundations so we can develop robust Channel tests while only needing to learn a handful of functions. These tests can ensure that complex logic such as asynchronous message processing and state is correctly implemented in a Channel.

One of the most important aspects of a scalable real-time application is ensuring that performance is good, even with many simultaneous users.

Get hands-on with 1200+ tech skills courses.