# Ordered Processing of Messages consumed from Kafka

**URL:** https://discuss.akka.io/t/ordered-processing-of-messages-consumed-from-kafka/4178
**Category:** Akka Streams & Alpakka
**Tags:** kafka
**Created:** [May 12, 2019, 5:55pm UTC](https://discuss.akka.io/t/ordered-processing-of-messages-consumed-from-kafka/4178 "2019-05-12T17:55:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sigurd](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@sigurd](https://discuss.akka.io/u/sigurd)
#### Post date: [May 12, 2019, 5:55pm UTC](https://discuss.akka.io/t/ordered-processing-of-messages-consumed-from-kafka/4178/1 "2019-05-12T17:55:18Z")

</div>

Hey guys,

I have a question about the committing of messages in Kafka.  
Kafka use a offset which is represented by a ascending number for a consumer group.  
So the committing have to be done in correct order, right?  
If I have three messages a,b,c and in this case a batch size of 1, then a need to commit a, then b and finish with c.

It is allowed to use a unordered operator such as mapAsyncUnordered?

In this example, the third line is the important part (process messages of one partition):

```auto
committablePartionedSource(..)
.mapAsyncUnordered(bufferSizer, pair -> pair.second()
    .mapAsyncUnordered(buffer, business())
    .runWith(commiterSink(),mat))
.toMat(Sink.ignore(), Keep.both())
.mapMaterializedValue(pair -> Consumer.createDrainingControl(pair))
.run(mat)

```

Is this process correct or break this the committing process of kafka?

Best  
Sigurd

---

<div class="post-metadata">

### Author: ![johanandren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/johanandren/32/85_2.png) [@johanandren](https://discuss.akka.io/u/johanandren)
#### Post date: [May 13, 2019, 9:10am UTC](https://discuss.akka.io/t/ordered-processing-of-messages-consumed-from-kafka/4178/2 "2019-05-13T09:10:04Z")

</div>

If you want to keep the ordering of the events you cannot use `mapAsyncUnordered` but must instead use `mapAsync` which keeps the original ordering.

With re-ordering and committing offset to Kafka you could end up committing a higher offset and then dropping a lower offset element and losing data.
