Skip to content

Improve Sender batching logic#113

Open
martosaur wants to merge 2 commits intoPostHog:mainfrom
martosaur:am-do-not-send-empty-batches
Open

Improve Sender batching logic#113
martosaur wants to merge 2 commits intoPostHog:mainfrom
martosaur:am-do-not-send-empty-batches

Conversation

@martosaur
Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Currently, Sender will occasionally attempt to send empty batches and get 400 from the ingestion API. This is happening due to a flaw in batching logic: whenever we receive first event in a batch, we set a timer. But if max batch size is reached, we send the batch immediately. This means that when the timer fires off, current batch can be empty. This PR contains 2 improvements:

  1. Whenever we decide to send a batch based on its size, we cancel current timer
  2. If the timer still goes off and our current batch is empty, we simply ignore it and do not attempt to send it.

💚 How did you test it?

Unit tests

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

@martosaur martosaur requested review from a team and rafaeelaudibert as code owners May 9, 2026 04:38
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.

1 participant