How to deal with phoenix subscription using Absinthe?

I’m developing APIs using Phoenix + Absinthe, and I plan to use at least 2 instances.

When I want to push changes to client through subscriptions, do I need to do it on all instances? If yes, I need to use redis pubsub to notify changes to all instances?

At the end of the day Absinthe is just hooked up to Phoenix PubSub, so if you configure Phoenix PubSub to work in a cluster then Absinthe will Just Work. Phoenix PubSub works in a cluster either by doing distributed erlang or via Redis. Distributed erlang is preferred, but isn’t always possible if you’re on something like Heroku because you can’t have different heroku instances talk directly to one another.


Thanks @benwilson512, assume that I configured Phoenix.PubSub to work in a cluster, and I have :order subscription, and when the order is updated, then what should I do?

  1. I use Phoenix.PubSub to notify that changes to all instances, then on all instants I will call Absinthe.Subscription.publish
  2. I just call Absinthe.Subscription.publish, that’s all.

#2 :). You can just call publish, it will handle distributing it for you.

1 Like

Wow, amazing, thank you very much :slight_smile:

Also, I have a different Phoenix + Absinthe app (app B), run on cluster, and use the same database with the above app (app A), if app A makes change to order, I want subscriptions on app B to be updated.

For now, I’m thinking using RabbitMQ to exchange events between 2 apps, it seems that using PubSub probably is not appropriate in this case, because I’m afraid that subscriptions will be triggered multiple times (By multiple instances).

Do you have any suggestions?