# Improve Logstash data resiliency

**URL:** <https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378>\
**Category:** Logstash\
**Created:** [November 17, 2021, 12:52am UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378 "2021-11-17T00:52:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodolffo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodolffo/32/82817_2.png) [@Rodolffo](https://discuss.elastic.co/u/Rodolffo)\
**Post date:** [November 17, 2021, 12:52am UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/1 "2021-11-17T00:52:42Z")

</div>

Hi everyone!

I'm working on an architecture in which we will ingest transactions into Elasticsearch from our application servers, and want to make absolutely sure that we store 100% of the data. I just want to validate if my theory is correct, or if there is a better way of doing this.

Right now, there's a Filebeat agent on every application server, those ship the documents to a Logstash cluster, which will forward them to their specified destination (we have multiple ES stacks, and also do some filtering and data transformations in Logstash). We have persistent queue turned on for all instances, but as it is stated even in the documentation (and as it can be figured out by common sense), they don't protect against e.g. instance termination, disk corruption etc.

What I imagine I can do is generate a reproducable, unique ID for every document, and send them to multiple Logstash instances (\>= 2). During normal operation, an instance which first recieves the document just writes it into Elasticsearch, and the subsequent ones will (intentionally) fail, so no duplication can happen - in theory (we're currently deciding between doing manual rollover or a data stream, but in this case it's most likely that we have to send documents with the same ID to the same underlying index so duplicate IDs can be detected, not sure if that's possible with a data stream, e.g. based on a timestamp field).

Is my theory correct, does it have any drawbacks or performance impacts (apart from obviously using twice as much resources in the Logstash cluster, which is still far more cheap than a larger ES cluster), and does significantly impact the ES performance, or is there any better way of achieving this?

---

<div class="post-metadata">

**Author:** ![ahmed\_charafouddine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmed_charafouddine/32/45129_2.png) [@ahmed\_charafouddine](https://discuss.elastic.co/u/ahmed_charafouddine)\
**Post date:** [November 17, 2021, 9:59am UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/2 "2021-11-17T09:59:18Z")

</div>

I don't think that's possible since it seems to me that the logsatsh instances work independently from each other. How are you going to make your logstash 1 know for example that the logstash 2 has already processed the message x and that it should not be dropped?

One of the solutions - because I believe there are a lot of them - would be for example to use a kafka broker or redis in front of your agents. These deposit the data on your broker and the logstashes will consume what is deposited in the broker.

---

<div class="post-metadata">

**Author:** ![Alex\_Marquardt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_marquardt/32/42925_2.png) [@Alex\_Marquardt](https://discuss.elastic.co/u/Alex_Marquardt)\
**Post date:** [November 17, 2021, 5:06pm UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/3 "2021-11-17T17:06:01Z")

</div>

To summarize: you will send the same document with the same `_id` to two Logstash instances. Each instance will send that same document with the same `_id` to the Elasticsearch cluster , but only the first to arrive at the cluster will be sucessfully written, and the other will fail to write (as desired).

You can achieve this by specifying an action of "create" , which will ensure Elasticsearch will reject the document if it already exists. As this could generate a lot of error messages, you should whitelist this specific error - i.e. skip all 409 errors which are `document_already_exists_exception`: [Elasticsearch output plugin | Logstash Reference [7.15] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-failure_type_logging_whitelist)

Seems like it should work. Since the second copy of the document should be rejected quite early in the indexing process, I would expect sending the same document twice to have a very small impact on overall cluster performance. But you should test it to be sure.

---

<div class="post-metadata">

**Author:** ![Rodolffo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodolffo/32/82817_2.png) [@Rodolffo](https://discuss.elastic.co/u/Rodolffo)\
**Post date:** [November 18, 2021, 10:33pm UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/4 "2021-11-18T22:33:21Z")

</div>

Thanks for the replies! Streaming messages is indeed a great idea, most likely we will implement this by using Kafka and multiple consumer groups, or simply with a Kafka Elasticsearch sink connector.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 19, 2021, 12:19am UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/5 "2021-11-19T00:19:41Z")

</div>

Just one thing, the `_id` field that you generated is only unique at the index level, not at cluster level, if you write to an index that has some kind of rollover, you still can get duplicates.

I would say that the same thing applies to data streams, as the back indices have rollovers.

---

<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:** [December 17, 2021, 12:20am UTC](https://discuss.elastic.co/t/improve-logstash-data-resiliency/289378/6 "2021-12-17T00:20:12Z")

</div>

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