# How to do async things, in order?

**URL:** <https://discourse.nameko.io/t/how-to-do-async-things-in-order/209>\
**Category:** googlegroup\
**Created:** [October 12, 2017, 12:04pm UTC](https://discourse.nameko.io/t/how-to-do-async-things-in-order/209 "2017-10-12T12:04:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://discourse.nameko.io/u/Richard)\
**Post date:** [October 12, 2017, 12:04pm UTC](https://discourse.nameko.io/t/how-to-do-async-things-in-order/209/1 "2017-10-12T12:04:53Z")

</div>

We have some code which is first writing to a primary db then dispatching  
an event to write the same to a secondary different db.

However it seems the dispatched events do not get consumed in the order  
they were sent.

Is there some way to guarantee the order sent is the order those events get  
executed?

And if not, can this be done with an rpc.call\_async instead?

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 13, 2017, 12:39am UTC](https://discourse.nameko.io/t/how-to-do-async-things-in-order/209/2 "2017-10-13T00:39:07Z")

</div>

It depends on how many consumers you have. AMQP makes certain guarantees  
about ordering of messages in queues, but it means nothing if you have  
multiple consumers processing the messages. This stack overflow question  
\<[queue - RabbitMQ - Message order of delivery - Stack Overflow](https://stackoverflow.com/questions/21363302/rabbitmq-message-order-of-delivery&gt);  
is a good reference.

The only way to do this with Nameko Events or RPC is to either use a single  
consumer, or add something at the application layer to enforce ordering,  
like a distributed lock that prevented parallel consumption . A more  
elegant solution for this problem would probably be a new set of extensions  
that used a transport with stronger ordering guarantees, such as kafka.

> **···**
>
> On Thursday, October 12, 2017 at 1:04:53 PM UTC+1, Richard wrote:
> 
> > We have some code which is first writing to a primary db then dispatching  
> > an event to write the same to a secondary different db.
> > 
> > However it seems the dispatched events do not get consumed in the order  
> > they were sent.
> > 
> > Is there some way to guarantee the order sent is the order those events  
> > get executed?
> > 
> > And if not, can this be done with an rpc.call\_async instead?
