Phoenix Channels at scale

Phoenix Channels makes real-time look easy. You create a MyAppWeb.SomeChannel module, add a few handle_in/3 clauses, and you're broadcasting. Excellent! The default settings will carry you to a few thousand concurrent connections without effort, which is perfect for a low-traffic site.

What if your site becomes popular, though? The next orders of magnitude, reaching 100,000 connections per node and beyond, expose a different set of problems you'll need to deal with. For example:

  • You run out of file descriptors.
  • The BEAM port table overflows.
  • Phoenix.PubSub broadcasts start showing up in scheduler latency profiles.
  • Defaults that were fine at a small scale become a noticeable share of your CPU at 100k connections.

This documentation contains the information I wish had existed when I first hit those problems.

Who this documentation is for

This documentation is for you if:

  • You've shipped at least one Phoenix Channel.
  • You're either operating a Phoenix Channel at scale today, or you can see the scale curve coming.
  • You're comfortable on the BEAM.
  • You've read the official Phoenix Channels docs.
  • You want the field-guide version of scaling Phoenix Channels that picks up where the official documentation leaves off.

What you'll find here

This documentation will help you learn the following aspects of dealing with Phoenix Channels:

How to read this information

We've written these pages using the Diátaxis style, which consists of the following types of information:

  • Tutorials: you learn by doing
  • How-tos: you solve a specific problem
  • References: you look something up
  • Explanations: you understand the why

Every page tells you, in its opening sentence, what type of document it is.

If you're new to the site, the overview and tutorial are the natural entry points. If you're here because production is on fire, jump straight to the how-to guides.