# Do I have an use case for moving to async here?

**URL:** <https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020>\
**Category:** Getting Started\
**Created:** [August 13, 2023, 11:46am UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020 "2023-08-13T11:46:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrCordeiro](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrcordeiro/32/785_2.png) [@MrCordeiro](https://forum.djangoproject.com/u/MrCordeiro)\
**Post date:** [August 13, 2023, 11:46am UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020/1 "2023-08-13T11:46:05Z")

</div>

I have a working app that I would like to start migrating to async, but I’m having a hard time finding tutorials on the matter.

For example, look at this use case. In it, I have a rating models that, for each new rating, trigger a recalculation of the UserRating model

```python
@receiver(post_save, sender=Rating)
def update_or_create_skillsummmary(sender, instance, **kwargs):
    """
    Updates or creates a UserRating when a Rating is saved
    """
    if instance.level == sender.Rating.UNKNOWN:
        return

    skill_summary, _ = UserRating.objects.get_or_create(
        user=instance.to_user, skill=instance.skill
    )

    if instance.is_positive:
        skill_summary.update_upvotes()
    elif instance.is_negative:
        skill_summary.update_downvotes()

```

However, signals are synchronous by default I don’t need to wait for this recalculation before returning a response. I was wondering if I could move that transaction to an asynchronous queue somehow.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 13, 2023, 12:10pm UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020/2 "2023-08-13T12:10:25Z")

</div>

Unless there’s something really knarly in `update_upvotes` or `update_downvotes`, this is going to be such a fast process that it’s not worth trying to process it independently.  
In fact, I’d even get rid of the signal here, and add the call to this to the Rating model’s `save` method.

---

<div class="post-metadata">

**Author:** ![MrCordeiro](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrcordeiro/32/785_2.png) [@MrCordeiro](https://forum.djangoproject.com/u/MrCordeiro)\
**Post date:** [August 13, 2023, 12:29pm UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020/3 "2023-08-13T12:29:49Z")

</div>

Thanks for the support, Ken!

Right now update\_upvotes / update\_downvotes are simple aggregations, but I’m now including a new process for normalizing the user ratings which may take a while.

I expect the number of calculations on the UserRating model to increase.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 13, 2023, 12:42pm UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020/4 "2023-08-13T12:42:33Z")

</div>

Again, you want to also weigh that in the context of how frequently this is going to occur. I don’t know what your application is, how many users are actively using it, and how often this Rating model is going to be updated. That’s contextual information that only you can determine.

I always approach this type of situation from the perspective of “keep it simple until it has been proven necessary to do otherwise”. You can waste a lot of time rearchitecting an application for performance reasons to prevent what you think a problem is going to be - only to find out that you cleared the wrong bottleneck and that the real issue is somewhere else.

Even if your most complicated updates take a full second - or even two - by themselves, that’s not too bad if any individual person is only going to encounter it once or twice / day.

So yes, unless you can prove to yourself that you really have a problem - and that addressing this will solve it - I wouldn’t worry about it yet.

---

<div class="post-metadata">

**Author:** ![MrCordeiro](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrcordeiro/32/785_2.png) [@MrCordeiro](https://forum.djangoproject.com/u/MrCordeiro)\
**Post date:** [August 14, 2023, 8:01am UTC](https://forum.djangoproject.com/t/do-i-have-an-use-case-for-moving-to-async-here/23020/5 "2023-08-14T08:01:53Z")

</div>

That makes sense.  
Thanks for the input!
