I would like to implement a RESTful API.

Some PUT requests, after updating an object should also generate a change notification to some subscribed users.

How should I implement that so that it doesn't send duplicate notifications?

How is this done?

I'm looking for design patterns, best practices, etc. not for code... How should I write this question in order not to be downvoted?

Possible solutions answers (not discussion)

  1. there are pro/cons in doing that
  2. use design pattern X,Y,Z: pro/cons
  3. use a different architecture, pros/cons
  4. look at examples somewhere
  • the notifications are also idempotent, aren't they? why does it matter whether you only send 1 or 2 notifications for 1 change? – user253751 Mar 19 at 14:54
  • 1
    @user253751 well, I don't want to receive 2 emails if there is only one change. I could easily implement a logic that doesn't send out an email if nothing is changed, but I'll face problems with concurrency. The general feeling is that sending n-times the same request will not have the same effects...I don't understand if it's a gross mistake or not – Glasnhost Mar 19 at 15:12
  • 1
    also, wouldn't only sending one email mean it is idempotent? Idempotent means doing it twice is the same as doing it once. If doing it twice sends two emails and doing it once sends one email, surely it's not idempotent – user253751 Mar 19 at 15:15
  • @user253751 so you'll do it without even thinking about it? – Glasnhost Mar 19 at 15:18
  • It sounds like you just want avoid duplicate notifications. You might consider simply logging the change requests with a hash of the data and a flag indicating whether the notification for that change was sent. The first request results in the change log being created, and the second request sees that a record already exists for that entity/hash and doesn't send a notification. – Dan Wilson Mar 19 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.