# Batch node: unique batch id?

**URL:** <https://discourse.nodered.org/t/batch-node-unique-batch-id/98690>\
**Category:** Core Development\
**Tags:** batch-node, clarification-of-behaviour\
**Created:** [16 August 2025 08:06 UTC](https://discourse.nodered.org/t/batch-node-unique-batch-id/98690 "2025-08-16T08:06:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [16 August 2025 08:06 UTC](https://discourse.nodered.org/t/batch-node-unique-batch-id/98690/1 "2025-08-16T08:06:12Z")

</div>

Hi There,

I am now playing around with the batch node and have a question to do with the IDs defined for batches. This question centres around the following flow which might be incorrect usage of the batch node:

```flows
[{"id":"61f1197fb98ebd3c","type":"group","z":"866410b56fa42447","name":"no parts attribute, batch generates batches that can be joined on","style":{"label":true},"nodes":["986e40576cf9935b","cc64390ba8e44396","73a7055de17cd629","974f6f2212ac282c","56cf09a7911cfe89","2a7824eca6408720","3d41c360d3045297","cf8a36a47aedbecb"],"x":206,"y":339,"w":1140,"h":409},{"id":"986e40576cf9935b","type":"inject","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","props":[{"p":"counter","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":302,"y":693,"wires":[["cc64390ba8e44396"]]},{"id":"cc64390ba8e44396","type":"change","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"msg"},{"t":"set","p":"counter","pt":"msg","to":"$$.counter + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":543,"y":577,"wires":[["73a7055de17cd629","974f6f2212ac282c"]]},{"id":"73a7055de17cd629","type":"batch","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","mode":"count","count":10,"overlap":0,"interval":10,"allowEmptySequence":false,"honourParts":false,"topics":[],"x":814,"y":577,"wires":[["56cf09a7911cfe89","2a7824eca6408720","cf8a36a47aedbecb"]]},{"id":"974f6f2212ac282c","type":"switch","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"limit to 10_000 messages","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"10000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":544,"y":380,"wires":[["cc64390ba8e44396"]]},{"id":"56cf09a7911cfe89","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 446","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1042,"y":466,"wires":[]},{"id":"2a7824eca6408720","type":"join","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":"false","timeout":"","count":"","reduceRight":false,"x":1032,"y":577,"wires":[["3d41c360d3045297"]]},{"id":"3d41c360d3045297","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 450","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1230,"y":577,"wires":[]},{"id":"cf8a36a47aedbecb","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 451","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":true,"statusVal":"","statusType":"auto","x":1040,"y":707,"wires":[]}]

```

My question why is the batch id always the same for the batches generated by the batch node?

 ![Screenshot 2025-08-16 at 09.56.49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/864c771fad76f76b7cdaa19fbdfa8989db825b9c.png)

Shown is the last message in a batch followed by two messages of the next batch (indicated by the index value of 9, 0, and 1). That output is generated by the `debug 451` node.

The id of all batches is the same as the original message id. The flow generates a single message that is updated with a counter so that in the end, ten thousand messages are generated that are batched into a thousand batches of ten - using the join node.

I would have assumed that the batches of ten would all be uniquely identified by a unique id (i.e. `parts.id = parts.index == 0 ? RED.nodes.generateId() : currentBatchId` instead of `parts.id = msg._msgid`)

Is this intended behaviour and if so, why? I would have assumed batches are unique and independent of the original messages that generated them.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [16 August 2025 08:34 UTC](https://discourse.nodered.org/t/batch-node-unique-batch-id/98690/2 "2025-08-16T08:34:06Z")

</div>

Ok to answer my own question:

 ![Screenshot 2025-08-16 at 10.30.07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a9ea4b2e07efa038f1e83c0d4072baffcbf60c7.png)

If the messages have unique message id (as in is the case if change node sets the \_msgid), then the batches are assigned uniqued batch ids and in fact the \_msgid of the first message - as suspected.

(Message id is faked here and generated using `$formatBase($random() * 1000000000, 16)`)

So I was generating an incorrect usage of the batch node by using the same \_msgid for all messages.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 August 2025 08:34 UTC](https://discourse.nodered.org/t/batch-node-unique-batch-id/98690/3 "2025-08-30T08:34:56Z")

</div>

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