# Detected out-of-order KTable update(for foreign key join)

**URL:** <https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082>\
**Category:** Kafka Streams\
**Created:** [17 July 2024 13:25 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082 "2024-07-17T13:25:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebestnic](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/thebestnic/32/3894_2.png) [@thebestnic](https://forum.confluent.io/u/thebestnic)\
**Post date:** [17 July 2024 13:25 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/1 "2024-07-17T13:25:06Z")

</div>

Hi, I’m getting some out-of-order KTable update in my kakfa streams application. I’m ingesting 10ish tables from kafka connect and enriching the data by chaining ktable joins. I have started getting a few out-of-order KTable after several days of it running for some of my foreign key joins(the initial snapshot went fine). Any idea on how to fix or debug this in more details ?

```auto
2024-07-16 09:21:44.809 WARN 1 --- [-StreamThread-3] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721136104525] new timestamp=[1721136104524]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[2] offset=[2422592].
2024-07-16 10:07:15.642 WARN 1 --- [-StreamThread-4] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721138835409] new timestamp=[1721138835408]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[3] offset=[2418189].
2024-07-16 11:29:32.530 WARN 1 --- [-StreamThread-2] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721143772304] new timestamp=[1721143772285]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[0] offset=[2430283].
2024-07-16 11:59:42.296 WARN 1 --- [-StreamThread-2] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721145582053] new timestamp=[1721145582052]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[1] offset=[2422121].
2024-07-16 13:11:01.654 WARN 1 --- [-StreamThread-3] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721149861431] new timestamp=[1721149861430]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[4] offset=[2426659].
2024-07-16 13:26:43.611 WARN 1 --- [-StreamThread-3] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721150803437] new timestamp=[1721150803434]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[2] offset=[2429629].
2024-07-16 14:52:07.442 WARN 1 --- [-StreamThread-2] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-1.0, old timestamp=[1721155927303] new timestamp=[1721155927302]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000132-topic] partition=[1] offset=[2168931].
2024-07-16 15:24:29.245 WARN 1 --- [-StreamThread-2] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-1.0, old timestamp=[1721157869084] new timestamp=[1721157869080]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000132-topic] partition=[1] offset=[2169464].
2024-07-16 15:51:42.102 WARN 1 --- [-StreamThread-3] o.a.k.s.kstream.internals.KTableSource : Detected out-of-order KTable update for my-app.logging.partial-5.0, old timestamp=[1721159501863] new timestamp=[1721159501862]. topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic] partition=[2] offset=[2434427].

```

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [18 July 2024 16:09 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/2 "2024-07-18T16:09:30Z")

</div>

I guess the question is where the out-of-order data comes from. – If you have `builder.table("topic")` and this table reports out-of-order updates, you would need to look into the upstream app which published the data.

If there is some repartitioning happening inside the KS app, out-of-order data is something that cannot be avoided.

The generic solution to handle out-of-order data for KTables is the usage of “versioned KTable”:

- [Introducing Versioned State Store in Kafka Streams](https://www.confluent.io/blog/introducing-versioned-state-store-in-kafka-streams/)
- [Versioned KTables for temporal join accuracy using Kafka Streams](https://developer.confluent.io/tutorials/versioned-ktables/kstreams.html)

---

<div class="post-metadata">

**Author:** ![thebestnic](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/thebestnic/32/3894_2.png) [@thebestnic](https://forum.confluent.io/u/thebestnic)\
**Post date:** [12 August 2024 14:07 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/3 "2024-08-12T14:07:11Z")

</div>

Well it happens only for foreign key joins. I do 5 normal joins and have no error associated but the 2 foreign key joins generate erros. We can see in the stack I posted that it’s on the response topic of the join : my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000132-topic. Only one app publishes events but there are 5 stream threads(a single Kubernetes pod)

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [21 August 2024 19:45 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/4 "2024-08-21T19:45:35Z")

</div>

FK joins always need to do some repartitioning, while PK-joins work on the input topics as-is. Thus, if there is no out-of-order data in the input topic, unordered data cannot happen for PK-join, but it can still happen for FK-joins.

Using versioned KTables for the FK-join should still help.

---

<div class="post-metadata">

**Author:** ![foal](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/foal/32/3692_2.png) [@foal](https://forum.confluent.io/u/foal)\
**Post date:** [27 February 2025 11:38 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/5 "2025-02-27T11:38:21Z")

</div>

Hi, can you explain - all questions for FK JOIN:

1. What happening if such WARNING appears? I miss some data?
2. How to avoid (at least reduce) this message for FK JOIN with simple KTable? Is it depending ob broker performance?
3. How the versioned KTable help? Should I have all KTable versioned? I join 2 simple Ktables and output is 3rd simple KTables how to say FK join to use internally the versioned KTables?

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [27 February 2025 21:17 UTC](https://forum.confluent.io/t/detected-out-of-order-ktable-update-for-foreign-key-join/11082/6 "2025-02-27T21:17:15Z")

</div>

I did take a close look, and realized that the log lines say `topic=[my-app-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-0000000154-topic]`. So it’s Kafka Streams internal, and not related to your input KTables you are joining.

> What happening if such WARNING appears? I miss some data?

No data will be dropped. But it would indicate that the join result might not be what you expect, ie, potentially incorrect result.

> How to avoid (at least reduce) this message for FK JOIN with simple KTable? Is it depending ob broker performance?

I don’t think you can do anything about it. I believe it’s the side effect of [[KAFKA-18713] Kafka Streams Left-Join not always emitting the last value - ASF JIRA](https://issues.apache.org/jira/browse/KAFKA-18713) (we are actively working on a fix for this ticket).

> How the versioned KTable help? Should I have all KTable versioned? I join 2 simple Ktables and output is 3rd simple KTables how to say FK join to use internally the versioned KTables?

Given that it seems to be a bug in Kafka Streams, I doubt that versioned KTables would actually help…
