PubSub
Explore how PubSub supports message broadcasting in Phoenix Channels to enable real-time web applications. Understand topic naming for scalability and performance, and learn how PubSub manages communication across nodes in a cluster. This lesson helps you grasp the foundation of delivering real-time updates efficiently in distributed Elixir applications.
We'll cover the following...
Selecting a topic name
A carefully selected topic name is vital for the scalability and behavior of an application. For instance, a public Channel providing inventory updates to an e-commerce storefront could be implemented in a variety of ways:
inventory: This topic does not delineate between different .SKUs Stock Keeping Units inventory:*: This topic delineates between different item with a wildcard.SKUs Stock Keeping Units
If an overly broad topic is selected, such as inventory, then an inventory change to an SKU is broadcast to every connected client, even if they are not viewing the item. A narrower topic such as inventory:* would lead to more connected topics (one per viewed item) but means that outgoing data could be held back from clients that aren’t viewing a particular SKU.
In this example, we would select a ...