Phoenix PubSub Patterns

•
118
•

Implements standardized Elixir Phoenix PubSub patterns for reliable real-time broadcasts and efficient LiveView state management.

This skill provides a comprehensive set of best practices and implementation patterns for Phoenix PubSub within Elixir applications. It enforces robust real-time architectures by mandating connection-guarded subscriptions, centralizing broadcast logic within business contexts, and utilizing immutable state updates in LiveViews. By following these strict guidelines, developers can eliminate common issues like duplicate subscriptions during static renders and ensure that real-time logic remains decoupled from the presentation layer for better maintainability and testability.

Key Features

01Full-cycle testing patterns that validate context triggers and LiveView reactions.
02Standardized topic naming conventions for resource-specific and collection-wide events.
03Immutable assign updates using update/3 for optimized LiveView performance.
04Guarded subscriptions using connected?(socket) to prevent duplicate event processing.
05118 GitHub stars
06Context-driven broadcasting that keeps real-time logic inside the business layer.

Use Cases

01Refactoring legacy LiveView code to follow Elixir community best practices for PubSub.
02Implementing notification systems that push updates to specific users or resources.
03Building real-time collaborative dashboards where multiple users must see synchronized data.