Skip to content

refactor(ingest): per-table batching + pipelined flushes - #192

Merged
EricAndrechek merged 15 commits into
mainfrom
table-batching
Jun 3, 2026
Merged

refactor(ingest): per-table batching + pipelined flushes#192
EricAndrechek merged 15 commits into
mainfrom
table-batching

Conversation

@EricAndrechek

Copy link
Copy Markdown
Member

Summary

Per-table batching

Related Issues

Closes #191

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR refactors ingestion dispatch to parse messages once, route them by table into lazily-created per-table channels, and run independent per-table batching state machines with configurable size and timeout. It also replaces shared E2E fixtures with generated per-suite ClickHouse tables and updates tests, setup, docs, and changelog.

Changes

Per-Table Batching Pipeline

Layer / File(s) Summary
Batching Configuration and Data Contracts
internal/ingest/worker.go
parsedMsg gains tableName. IngestWorker adds maxBatch, maxWait, and ackWg; package defaults and consumer tuning constants are centralized.
Message Parsing and Dispatch Loop
internal/ingest/worker.go
parseMsg centralizes envelope parsing (malformed JSON is logged and double-acked). StartIngestWorker starts dispatchLoop which demultiplexes parsed messages into lazily-created, bounded per-table channels and defines shutdown order.
Per-Table Batching State Machine
internal/ingest/worker.go
New tableLoop/tableBatcher accumulates per-table rows, flushes on maxBatch or maxWait, enforces one in-flight bulk flush per table, coalesces triggers arriving during a flush, and performs final synchronous drain/flush on channel close.
Acknowledgment and Shutdown Ordering
internal/ingest/worker.go
Background double-acks are scheduled on ackWg; handleSuccess uses ackWg for ack goroutine lifetime. Shutdown waits table loops first, then drains ackWg.
Tests: parse, flushTable, tableBatcher, dispatch regressions
internal/ingest/worker_test.go
Test harness updated to wait on ackWg. Adds TestParseMsg, rewires flush tests to flushTable via parseAll, adds tableBatcher unit/state-machine tests, and adds dispatch-loop regression tests for per-table isolation and partial-batch correctness.

E2E: Per-Suite Table Isolation & Setup

Layer / File(s) Summary
E2E table helpers and DDL
tests/e2e/sdk/tables.ts
Adds TableKind/KINDS, TABLE_DDL generators, SUITES, suiteTables, tableName, and allTableSpecs() to compute per-suite physical table names and DDL.
Global E2E setup and bootstrap
tests/e2e/sdk/setup.ts
Replaces fixture application with createTables() that POSTs generated DDL for allTableSpecs(), refreshes schema against generated names, and bootstraps dynamic policies for those tables.
E2E test suites
tests/e2e/sdk/*
Multiple E2E tests updated to import suiteTables("<suite>") and use T.clicks/events/users instead of hard-coded table names; admin tests snapshot/restore baseline policy; DLQ/timing checks and polling windows adjusted.
Docs & Changelog
docs/src/content/docs/ingest-pipeline.md, docs/src/config/sidebar.ts, AGENTS.md, CHANGELOG.md
Adds contributor-facing ingest pipeline deep-dive, registers the “Ingest Pipeline” sidebar entry, documents E2E per-suite isolation rules in AGENTS.md, and updates changelog describing per-table batching and E2E setup changes.

🎯 4 (Complex) | ⏱️ ~45 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the ingestion worker to move from a global batching strategy to a per-table batching architecture. By isolating batches per table, the system ensures that high-volume traffic is not delayed by the batching or timing constraints of low-volume tables. This change also introduces pipelined flushes to maximize throughput by allowing concurrent batch accumulation and ingestion.

Highlights

  • Per-table Batching: Refactored the ingestion worker to use per-table batching instead of a global batch, preventing cross-table contamination where low-volume tables could strand events from high-volume tables.
  • Pipelined Flushes: Implemented a per-table loop with pipelined flushes, allowing a new batch to accumulate while a previous one is in-flight, improving throughput and reducing latency.
  • Improved Reliability: Added a new test case to reproduce and verify the fix for the cross-table contamination issue identified in refactor(ingest): per-table batching + pipelined flushes; unblock per-table-per-test e2e isolation #191.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added go Pull requests that update go code area/ingest Ingest pipeline (Bento, batching, DLQ) labels May 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ingest worker to use per-table batching and pipelined flushing, resolving an issue where low-volume tables could delay high-volume tables. A new test is added to verify this behavior. However, a critical issue was identified in tableLoop where exiting immediately on ctx.Done() bypasses draining buffered messages in the table channel, which can lead to message loss or unnecessary redeliveries on shutdown.\n\nVerdict: Iterate

Comment thread internal/ingest/worker.go Outdated
@EricAndrechek EricAndrechek moved this from Backlog to In progress in WaveHouse Task Board Jun 2, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation area/docs Documentation, site/, README labels Jun 2, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 3, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
wavehouse-docs c27550a Jun 03 2026, 03:17 PM

@github-actions github-actions Bot added the area/sdk TypeScript SDK (clients/ts/) label Jun 3, 2026
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file area/infra CI, build, deploy, Docker, release labels Jun 3, 2026
@EricAndrechek
EricAndrechek marked this pull request as ready for review June 3, 2026 13:12
@EricAndrechek
EricAndrechek requested a review from taitelee June 3, 2026 13:12
@EricAndrechek EricAndrechek moved this from In progress to Ready in WaveHouse Task Board Jun 3, 2026
Comment thread docs/src/content/docs/ingest-pipeline.md
@github-actions github-actions Bot removed dependencies Pull requests that update a dependency file area/infra CI, build, deploy, Docker, release labels Jun 3, 2026

@taitelee taitelee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Per-table batching refactor, wait groups for graceful shutdown, and load distribution using goroutines and channels for ingest. Important to check docs for wait group logic.

@github-project-automation github-project-automation Bot moved this from Ready to In progress in WaveHouse Task Board Jun 3, 2026
@EricAndrechek
EricAndrechek merged commit 3f27ebd into main Jun 3, 2026
7 checks passed
@EricAndrechek
EricAndrechek deleted the table-batching branch June 3, 2026 17:31
@github-project-automation github-project-automation Bot moved this from In progress to Done in WaveHouse Task Board Jun 3, 2026
EricAndrechek added a commit that referenced this pull request Jun 3, 2026
Resolves the CHANGELOG.md [Unreleased] conflict: keeps this branch's
"Lint/format coverage" + docs-deploy-from-CI-job entries alongside main's
new per-table-batching (#192) and health-endpoints (#213) entries, and
reconciles the stale "Project policies CardGrid" wording (that homepage
element was replaced by the closer call-to-action band on this branch).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation, site/, README area/ingest Ingest pipeline (Bento, batching, DLQ) area/sdk TypeScript SDK (clients/ts/) documentation Improvements or additions to documentation go Pull requests that update go code

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

refactor(ingest): per-table batching + pipelined flushes; unblock per-table-per-test e2e isolation

2 participants