ash icon indicating copy to clipboard operation
ash copied to clipboard

Proposal: Use relationships in PubSub topics to fan out

Open pikdum opened this issue 7 months ago • 4 comments

Is your feature request related to a problem? Please describe.

I'd like a way to use relationships in pubsub topics, especially with has_many relationships through a join table.

Using a social media site as an example, this would allow broadcasting new posts to all followers using a relationship like post.author.followers.user_id to publish to post:$follower_id topics.

Describe the solution you'd like

  • some way use relationships in publish topics
  • list of publish topics is generated from that + event is published to all

Describe alternatives you've considered

  • publish to a more broad topic + filter once a process receives it
  • have the client dynamically generate specific topics to follow
  • custom notifier

Express the feature either with a change to resource syntax, or with a change to the resource interface

Since publish and publish_all use lists for combinations, maybe tuples could be used for relationship attributes?

  pub_sub do
    prefix "post"
    module SocialMediaWeb.Endpoint    
    publish_all :create, [{:author, :followers, :user_id}]
    publish :update, ["foobar", [{:author, :followers, :user_id}, :_pkey]]
  end

Additional context

https://discord.com/channels/711271361523351632/1298629277524295700/1377340286405181461

One thing I'm not certain about is performance - doing queries + generating these topics + publishing to each could be slow with larger relationshpis.

pikdum avatar May 31 '25 04:05 pikdum

Performance will be awful for popular sites. Consider integrating with ash oban optionally. I mean: integrate Ash Oban into the feature -- don't make devs figure this out.

dev-guy avatar May 31 '25 15:05 dev-guy

I think providing choice on this front makes sense. However I think what we should do here instead is allow configuring a function or a module that implements a behavior that returns a list of topics, that way the logic can just be "whatever you want".

publish_all :create, {Fanout,...opts}

I won't likely do this myself any time soon, but I'd support the latter implementation.

zachdaniel avatar Jun 01 '25 04:06 zachdaniel

It seems a PR was opened for this, but it hasn’t been merged, and the issue remains open. I just wanted to check if this means the feature hasn’t been fully addressed yet.

jechol avatar Aug 14 '25 12:08 jechol

I started working on it, but there is more work needed, and priorities shifted, so I haven't had time to work on it more.

barnabasJ avatar Aug 14 '25 12:08 barnabasJ