ash-project / ash-project/ash

Proposal: Use relationships in PubSub topics to fan out

Open
#2,081 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
2.5k
Forks
426
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**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?

```elixir
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.

Contributor guide

Open the contributing guide

Research direction

Start with the publish and publish_all resource interface described in the issue, then review the linked Discord discussion and the performance concerns about querying relationships and publishing to many topics. Done means reaching agreement on the resource syntax or interface, relationship fan-out behavior, and its performance expectations.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.