How to scale Phoenix Pubsub event publishing?

It’s not a single process, but it’s a single process per node, which dispatches the message to all the subscribers of that node (implemented using Registry.dispatch). Registry.dispatch actually does have a parallel option, which kicks in once registry stores registered processes on multiple ets table shards if enabled.

Phoenix PubSub does also support custom dispatchers though, which e.g. phoenix channels use to fastlane messages sent to external clients. Fastlaning in this case means encoding the message only once based on the serialization format and faning out only the encoded message directly to the sockets instead of faning out to channel processes, encoding messages individually and letting channel processes forward the encoded message to their sockets.

So you might be able to enable parallel sending by Registry by configuring a custom dispatcher.

6 Likes