Skip to content

Conversation

thumbsupep
Copy link

Proposed changes

per a support request between the company I work for and Segment support, Segment's engineers were able to repro a bug with the onBatch handler, and recommended that consumers preserve the ordering in which events are received as a workaround. I have copied their explanation and code sample verbatim.

This correction of the sample code documentation will help consumers and should save some bandwidth for the Segment support team.

Merge timing

ASAP once approved

per a support request between the company I work for and Segment support, Segment's engineers were able to repro a bug on their side with the onBatch handler, and recommended that consumers preserve the ordering. I have copied their explanation and code sample verbatim.
@thumbsupep thumbsupep requested a review from a team as a code owner September 15, 2025 17:31
@thumbsupep thumbsupep changed the title Update insert-functions.md Update insert-functions.md to correct onBatch example Sep 15, 2025

To create a batch handler, define an `onBatch` function within your destination insert function. You can also use the "Default Batch" template found in the Functions editor to get started quickly.

**However**, Segment's function invoker service relies on positional consistency between the input and output arrays when using the `onBatch` handler. When a function returns a transformed batch, Segment pairs each output event with its corresponding input using array index positions—not event IDs or timestamps. Consumers must preserve the original order in their `onBatch` implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**However**, Segment's function invoker service relies on positional consistency between the input and output arrays when using the `onBatch` handler. When a function returns a transformed batch, Segment pairs each output event with its corresponding input using array index positionsnot event IDs or timestamps. Consumers must preserve the original order in their `onBatch` implementation.
You must preserve the original order in the `onBatch` implementation, as Segment's function invoker service relies on positional consistency in the `onBatch` handler between the input and output arrays. When a function returns a transformed batch, Segment pairs each output event with its corresponding input using array index positions, not event IDs or timestamps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants