sfertman/redis-atom

notifyWatches

sfertman opened this issue · 0 comments

Right now redis-atom will notify local watches only. Should all possible watches be notified?

Not sure what the expected behaviour should be. When I have a single service running and an atom has watches, the watch function is invoked once for each update. If I have multiple clones of a service running, for example then only watches on the service that made the update get notified.

If I were to notify all services about the change then the watcher functions would be invoked multiple times. What if they have side effects? What if they write to a db or send webhooks?

On one hand, every service should know about updates to atom if they subscribe to it, but on the other hand you would have to be very careful about side effects.

It would seem that the expected behaviour should be to notify locally once. However, it does make sense to have some sort of way for all services to learn about atom updates if they choose to.

Perhaps keep default behaviour but create an option for watches to subscribe to pubsub(s) of changes to atom. I could have a pubsub created at construction time and push update events to all services' queues (fetched by key prefix or something). So, if I want to get notified on every update, even if it's not mine, then I addWatch that listens to my queue (with a convenient helper fn). If I only want to watch my updates then I addWatch like a regular atom.