Is it possible to use Kafka streams API to reorder out-of-order events?
1,712 views
Skip to first unread message
Wei Zhou
unread,
Oct 11, 2017, 9:34:38 AM10/11/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Confluent Platform
Hi,
I wonder if it's possible to re-order a stream of out-of-order events by leveraging the windowing feature and time semantics of Kafka streams. By "out of order", I mean the order of the event time of the records (embedded in the event payload) may be different from the order of event arrival time. Specially, I need to able use Kafka API to read the out-of-order event stream and generate an output stream of ordered events and send the new stream back to Kafka, such that the order of events (i.e. order of the message offset ) in the new stream is based on the event time in the message payload, not the order the events are received in the original topic.
Is it possible to do this using Kafka Streams API? For example, by assigning event-time to the stream records using Timestamp Extractor, and then self-joining 2 copies of the original streams using a sliding window? Will this be able to generate an output stream of ordered events? If this won't work, is there any other way to make this work using Kafka Streams?
Thanks in advance!
Wei
Matthias J. Sax
unread,
Oct 11, 2017, 2:52:58 PM10/11/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to confluent...@googlegroups.com
You can do this, but you need to implement it by your own.
You would use a custom stateful `Transformer`. Within the transformer
you can buffer up records in your state and if you are sure you got all
data, you can emit the records in any order you want.
Using DSL would not be a good approach because there, records are always
processed in offset-order and it's not possible to change this at DSL
level. A custom TimestampExtractor won't help either.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Confluent Platform
Thanks a lot Matthias!
Wei
Alper Kanat
unread,
Apr 16, 2019, 2:33:46 PM4/16/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Confluent Platform
Hi Matthias,
I've a microservice which receives batched events and writes them into a topic one by one using Spring Kafka. Before writing messages to the topic, I calculate the timestamp of each message using their attributes and assign the timestamp to the corresponding ProducerRecord. I also key these messages with some ID within the message. Then another microservice consumes this topic, rekey the messages using another attribute and the KStreams app is configured with a special TimestampExtractor class which extracts the timestamp.
I wonder if the messages are ordered (using the timestamps I assigned earlier) during the repartioning process?
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to confluent...@googlegroups.com
No.
If data is repartitioned, there is no guarantee that all records in a
partition will be ordered by timestamp. The reason is, that multiple
upstream producers write into the repartition topic, and thus data in
appended interleaved. Hence, even if the data that each producer write
is ordered by timestamp, this property is lost on write into the
repartition topic.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Confluent Platform" group.
> To unsubscribe from this group and stop receiving emails from it, send