Question

I have a very simple web application. A student comes in and he creates a note in one of the subjects. Each subject has number of subscribers. Similar to stackoverflow tags, once a tag has been added to a question, the subscribers are notified.

Similary in my app, I want to add subscribers, so once a note is created for a particular subject, all the subscribers of that subject are mailed.

I have my db models as follows -

class Subject(models.Model):
//some vlaues here 

class Note(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    author = models.ForeignKey(User)
    subject = models.ForeignKey(Subject)

class SubscriptionModel(models.Model):
    subject = models.ForeignKey(Subject)
    subscriber = models.ForeignKey(User)

There are couple of ways of implementing it -

  1. Once a note is created, a post_save signal can be fired to email all the subscribers of that subjecct.

  2. Something with pub-sub can be done.

  3. Something with rss feeds can be done.

I am not sure what is a scalable approach to implement it, any help or pointers would be appreciated, thanks.

Était-ce utile?

La solution

Signal are synchronous, so it will be bad to have mailing done in the save signal because it will slowdown the save process and will not scale.

I suggest to use asynchronous task via queue like django-rq or celery. And you can just put task in the queue in the post_save signal. This approach will scale well and wont interfere with normal site functioning.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top