rodwatkins

rodwatkins

Channel based notification system

Hello,

I am looking for some advice about setting up notifications through channels. Here is what I am designing.
I have a private web site where users work closely together. So I wanted a way to send notifications of (model) changes to all users currently online. Notifications will be saved to the database (as part of a completely audited system).

Here is how I want it to behave. When a user is logged in, they receive notifications whenever a model is changed. As described in the channels chapter in “Programming Phoenix”, I planned to store a last_seen_id so that users can receive only the notifications they missed while disconnected. But I want that last_seen_id to be stored somewhere and not be lost when the user closes their browser or uses a different browser. So the best answer seems to be storing that id in the database.

Thus, when a message is sent successfully, the browser could send a message back with the new last_seen_id and then the server persists that to the database. Then when the client reconnects, the last_seen_id can be retrieved from the channel if it exists or look it up in the db if not.

Does that design makes sense? Or is there a better way.
Cheers
Rod

Most Liked Responses

josevalim

josevalim

Creator of Elixir

For the notifications case, you can also put all the relevant information in a map, including the user_id, post_id and everything else you may want to show the user. When doing a notification system, it is often best to have all the data you need in a single lookup instead of traversing multiple tables after the information you want. However, do include the source data in case you need to reconstruct the notifications later on.

OvermindDL1

OvermindDL1

That is precisely what I am doing. The client just sends a ‘seen’ message to the notification channels (I have multiple for different notification types) to indicate that it has seen up to ‘now’.

david

david

Would you mind elaborating on how you structured your notification relationships?

I’m trying to accomplish something similar, Multiple Polymorphic Associations in Ecto, and would be curious how you tracked your model changes in the db.

Thanks!

Where Next?

Popular in Discussions Top

vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
WolfDan
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New
griffinbyatt
Sobelow Sobelow is a security-focused static analysis tool for the Phoenix framework. For security researchers, it is a useful tool for g...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement