# Why kafka event key must be unique?

**URL:** <https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [October 25, 2019, 10:10pm UTC](https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330 "2019-10-25T22:10:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![filebeater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/filebeater/32/18565_2.png) [@filebeater](https://discuss.elastic.co/u/filebeater)\
**Post date:** [October 25, 2019, 10:10pm UTC](https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330/1 "2019-10-25T22:10:11Z")

</div>

I read the following from the manual. However, i could not seem to find this requirement from apache kafka documentation? We would like to use hostname + source filename to be kafka event key, which is definitely not unique. something like the following:  
key: ['beat.hostname', 'source']

#### `key` [edit](https://github.com/elastic/beats/edit/7.4/libbeat/docs/outputs/output-kafka.asciidoc)

Optional Kafka event key. If configured, the event key must be unique and can be extracted from the event using a format string.

---

<div class="post-metadata">

**Author:** ![filebeater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/filebeater/32/18565_2.png) [@filebeater](https://discuss.elastic.co/u/filebeater)\
**Post date:** [October 25, 2019, 11:42pm UTC](https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330/2 "2019-10-25T23:42:13Z")

</div>

i believe the documentation is incorrect,  
FYI: I set the following key and it works fine.  
key: '%{[beat.hostname]}+%{[source]}',

---

<div class="post-metadata">

**Author:** ![faec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/faec/32/46988_2.png) [@faec](https://discuss.elastic.co/u/faec)\
**Post date:** [October 30, 2019, 4:05pm UTC](https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330/3 "2019-10-30T16:05:34Z")

</div>

Thanks for pointing this out! I think you're right; here is a [stackoverflow post](https://stackoverflow.com/questions/29511521/is-key-required-as-part-of-sending-messages-to-kafka) with a useful discussion about key uniqueness. If strict ordering of the events is needed, a fixed key may be desirable, but it shouldn't be necessary in general.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 27, 2019, 4:05pm UTC](https://discuss.elastic.co/t/why-kafka-event-key-must-be-unique/205330/4 "2019-11-27T16:05:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
