tjdam

tjdam

Hi, all!

I just spent the weekend on a fun project going through the ins and outs of GraphQL subscriptions using Absinthe and Apollo Client to write a notification system (have never even used Phoenix PubSub before).

I’m so impressed and excited I could finally make it work but… then I realized I overlooked a major aspect of notification, which is to receive notifications when you are NOT THERE, connected (heh :see_no_evil_monkey:)

So now I’ve been thinking of how to go about doing it, I know I’m thinking very naively, so I’d like to consult you guys’ wisdom on that.

The most simple solution I see is to hold these notifications on the database I’m already using (Postgres) but how? One entry per user and notification would be reaaaally not scalable, it seems? It seems like it should be a trivial problem to solve (I wouldn’t know) but it’s been challenging me.

Anyone?
Thank you!

Showing Posts 1 to 7

derek-zhou

derek-zhou

One entry per user per notification, right in your database. You can have a background job to delete delivered entries to keep the database lean. In any event, you are way too early to consider scalability.

tjdam

tjdam OP

Really! That is what I had in mind, but I thought it would lead to an insane amount of duplication. I’m not trying to be hyper performant or anything, but it sounded to me that having one entry per user for a given event would be duplicating that event each time.

Would you have one table for the events and link the users with a many-to-many or you’d actually have a duplication of the event for each notification entry?

Thank you!

derek-zhou

derek-zhou

It is a matter of normalizing your database schema. You should familiar yourself with the normal form and eliminate the data duplication.

tjdam

tjdam OP

So the way I conceptualize in my mind now is to have a notifications table that holds all the data (perhaps just a json b field) for each notification and then a users_notifications table that references users and notifications and holds the status for the notification (if delivered or something else).

Does that seem right?

derek-zhou

derek-zhou

I have no idea of what are your requirements. Honestly, I think using a jsonb field is a bit strange.

03juan

03juan

You got this right. But you’ll want to use a has-many-through users -> user_notifications -> notifications because you need to store the status in the join table so you can index and filter on it. That’ll make the queries much more performant.

There are pros and cons of using jsonb to store your data and, as @derek-zhou implies, you really have to understand whether that’s something you need and you’re willing to live with the tradeoffs. Know, your, anti-patterns

tjdam

tjdam OP

I mostly thought of using jsonb because the notification system is supposed to receive events from all sorts of different parts of the application that results in different structs, so I thought of storing them schemalessly (is that word?) as to just have them ready when the user access it… but reading the references you pointed me to, I started thinking of ways of having a Notification struct and have the different results to comfort to it somehow instead of the other way around.

Anyways, thank you so much for your time and for the references! :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews