# Action batching

**URL:** <https://community.temporal.io/t/action-batching/5773>\
**Category:** Community Support\
**Created:** [August 23, 2022, 3:21pm UTC](https://community.temporal.io/t/action-batching/5773 "2022-08-23T15:21:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yegor\_Roganov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yegor_roganov/32/2661_2.png) [@Yegor\_Roganov](https://community.temporal.io/u/Yegor_Roganov)\
**Post date:** [August 23, 2022, 3:21pm UTC](https://community.temporal.io/t/action-batching/5773/1 "2022-08-23T15:21:34Z")

</div>

Hello

I’m evaluating Temporal for our use cases and I’m stuck at implementing batching.

Essentially I’ve got a workflow that runs with high concurrency (200+ per second) and needs to index data to ElasticSearch. ElasticSearch performs best when indexing data in bulk and not one by one. So what I think I need is to somehow batch inputs to the indexing activity so that it receives N records to index, not just one.

Is this possible with Temporal? How?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 23, 2022, 3:29pm UTC](https://community.temporal.io/t/action-batching/5773/2 "2022-08-23T15:29:23Z")

</div>

I would do the following:

- An activity that adds the ES record to a shared queue. The message in the queue includes activity task token.
- This activity uses asynchronous completion to not complete when its function returns.
- A separate thread periodically consumes the records buffered in the queue, and sends a batch request to ES.
- Once the batch request succeeds all the activities in the batch are completed using manual completion client.

---

<div class="post-metadata">

**Author:** ![Yegor\_Roganov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yegor_roganov/32/2661_2.png) [@Yegor\_Roganov](https://community.temporal.io/u/Yegor_Roganov)\
**Post date:** [August 23, 2022, 3:39pm UTC](https://community.temporal.io/t/action-batching/5773/3 "2022-08-23T15:39:29Z")

</div>

Thanks for the reply.

> An activity that adds the ES record to a shared queue

What do you mean by a queue in this context? Is it a Temporal task queue or just an external queue (e.g. RabbitMQ)?

> A separate thread periodically consumes the records buffered in the queue

Similarly, would this thread run as a part of a Temporal workflow or external to Temporal?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 23, 2022, 4:46pm UTC](https://community.temporal.io/t/action-batching/5773/4 "2022-08-23T16:46:54Z")

</div>

> What do you mean by a queue in this context? Is it a Temporal task queue or just an external queue (e.g. RabbitMQ)?

In memory queue.

> Similarly, would this thread run as a part of a Temporal workflow or external to Temporal?

External to Temporal. Lives in the same process as the in-memory queue.
