0

Imagine a simple PHP application where an user can post notes and the other users can upvote or downvote them.

We want to implement a system where each note has a different rating (normal, good, great ...) based on the number of upvotes and downvotes it has.

My question is: When should I handle these rating changes?

My first idea was to check every time an user votes on a note if the vote doesn't change it's rating (e.g. from normal to good) but considering that voting on notes will be one of the most frequently used features on our site, it might slow down the site a lot.

We could also implement a cron job which fires every, let's say, half an hour and checks if the number of votes on every note corresponds to its rating but I suppose that would be a waste of our resources since most of the notes might not have been voted on during that time interval.

  • If your rating can be calculated easily enough (e.g. it derives directly from the netto vote count on note), then you could just store the netto vote count and calculate the rating then the note is retrieved. – Bart van Ingen Schenau Sep 12 '15 at 8:47
  • I would rather like to notify the user once the rating changes and give him points for that. – ondrejba Sep 12 '15 at 8:59
2

I would suggest, if you have the capability to daemonize processes on your server, that the best way of doing this would be to include in the 'Notes' object itself the business rules of ratings changes, to notify a message queue service (such as rabbitmq) when ratings change, and consume the message queue in the daemonized service in order to notify users that their note has a changed rating. This will allow you to keep individual vote request response times snappy and deal with the notification asynchronously.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.