How lucerion/pub_sub_hub works
• Hub – The core service that manages users, channels, subscriptions, tokens, and internal RPC handling. It also handles the persistence of data (e.g., via Ecto migrations in the priv/repo directory).
• Publisher – A client application that authenticates with the Hub, creates channels, and publishes content.
• Subscriber – Another client application that authenticates, subscribes to channels, and receives published data.
Main Components
a. Hub Service:
– Acts as the central coordinator.
– Contains multiple submodules (users, channels, subscriptions, tokens, RPC handling).
– Manages database interactions (see the migrations and repo files).
b. Publisher Service:
– Authenticates against the Hub.
– Invokes RPC methods to create channels and publish data.
c. Subscriber Service:
– Authenticates against the Hub.
– Uses RPC calls to subscribe/unsubscribe and to receive messages.
d. Database:
– Used by the Hub for storing user credentials, channel definitions, subscriptions, and more.
e. RPC Mechanism:
– Facilitates inter-process communication between the Hub, Publisher, and Subscriber.
– Clearly visible in the structure by having dedicated modules (e.g., PubSubHub.Publisher.RPC.Supervisor, PubSubHub.Subscriber.RPC.Supervisor) and corresponding lib files.
Relationships and Interactions
– From Publisher → Hub highlighting authentication, channel creation, and publishing data.
– From Subscriber → Hub showing authentication and subscription management.
Architectural Patterns and Design Principles
a. Modular and decoupled design: Each major app (hub, publisher, subscriber) is an independent OTP application, ensuring clear separation of concerns.
b. Use of RPC: The system leverages Elixir’s capabilities for remote procedure calls between distributed nodes, ensuring loose coupling.
c. Persistence Layer: Use of Ecto migrations and a dedicated repository indicates a clear data persistence pattern.
d. Supervisory Structure: Indicated by the presence of Application modules and supervisor directories, it emphasizes fault tolerance and robust process management.
Relevant Technologies and Frameworks
a. Elixir (and OTP) is the core language and framework behind the system.
b. Ecto for database interactions.
c. The RPC-based mechanism inspired by WebSub for pub/sub communications.
d. To note the use of environment variables (via .env files) for configuration.
Overall Advice
– Be as detailed as possible. Break down the Hub into its internal components (Users, Channels, Subscriptions, Tokens, RPC Handlers) if needed; this helps in visualizing the internal responsibilities.
– Focus on data flow: from client actions (create publisher/subscriber, authentication, channel management) toward the Hub and then to the persistence layer or back to the clients.