# Task.start vs TaskSupervisor

**URL:** <https://forum.elixirforum.com/t/task-start-vs-tasksupervisor/26718>\
**Category:** Questions\
**Tags:** task, phoenix\
**Created:** [November 11, 2019, 3:10pm UTC](https://forum.elixirforum.com/t/task-start-vs-tasksupervisor/26718 "2019-11-11T15:10:15Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![fxn](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fxn/32/20274_2.png) [@fxn](https://forum.elixirforum.com/u/fxn)\
**Post date:** [November 11, 2019, 10:23pm UTC](https://forum.elixirforum.com/t/task-start-vs-tasksupervisor/26718/6 "2019-11-11T22:23:41Z")

</div>

Thanks @josevalim :).

I totally missed the caller monitors the task too, so the indirection through the supervisor to prevent tasks from crashing the WS is unnecessary, as shown in your example.

I believe we lose the order guarantee, however. Let me explain: Events have a timestamp, and they have to be published to the message bus in order. To have a more concrete scenario in mind, these are (mainly) GPS locations sent by users, and they are broadcasted to the platform via a Kafka partition that depends on the user ID. So, the workflow guarantees order because the phone sends things in order (because of the direction of the arrow of time 😀), the WS processes them in order because Phoenix has one single process per user and topic, and Kafka partitions guarantee order too.

If I understand the proposal correctly, the WS is able to handle a new event while the task runs, and so we could have two tasks being executed in parallel. If that is right, then we could have a rare-but-theoretically-possible race condition. Is there a way to tweak that approach to preserve ordering?

That was the idea of the original `await` call, that `handle_in` does not process a new event until the previous one has been processed. That guarantees ordering in a simple way at the cost of less concurrency.

If we move this to a separate process to go async, then the mailbox of that process is the one preserving ordering. That introduces an indirection/complication in the implementation that I am not sure is worthwhile for my needs. Also, I need to think about messages piling up in the WS vs in that mailbox in different problematic scenarios. Hmmm…

---

_[View the full topic](https://forum.elixirforum.com/t/task-start-vs-tasksupervisor/26718)._
