Title: perf(webapp): parallelize streaming batch-item ingest by matt-aitken · Pull Request #3777 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: perf(webapp): parallelize streaming batch-item ingest by matt-aitken · Pull Request #3777 · triggerdotdev/trigger.dev
X Title: perf(webapp): parallelize streaming batch-item ingest by matt-aitken · Pull Request #3777 · triggerdotdev/trigger.dev
Description: Problem The item-streaming endpoint of the two-phase batch API (POST /api/v3/batches/:batchId/items) processed streamed items strictly sequentially. For a batch of many large payloads, each offloaded to object storage inline, this serialized N object-store round-trips inside a single request and could exceed Node's default server.requestTimeout (300s). The webapp then returned 408, which the SDK reads as 408 terminated and retries up to 5 times, turning a slow ingest into a failure that takes tens of minutes to surface. Fix Ingest now runs through p-map over the NDJSON async iterable with bounded concurrency (STREAMING_BATCH_INGEST_CONCURRENCY, default 10): p-map pulls lazily from the stream, so at most concurrency items are read and in-flight at once. Peak memory stays bounded to roughly concurrency × STREAMING_BATCH_ITEM_MAXIMUM_SIZE and request-body backpressure is preserved. Set the env to 1 for fully sequential ingestion (escape hatch). Why this is safe (ordering and idempotency unchanged) Ordering derives from each item's index (enqueue timestamp = batch.createdAt + index), not enqueue order. Dedup is atomic per index in enqueueBatchItem. The NDJSON parser now stamps oversized-item markers with their emit position, removing the consumer's sequential lastIndex assumption (the only order-dependent bit). The count-check and conditional-seal path is untouched. Scope This speeds up every batch ingested through the streaming endpoint, not just large-payload batches. Each item does a per-item Redis enqueue regardless of size, and those now overlap. Large payloads benefit most because they add an object-store offload round-trip on top of the enqueue. Verification Added an integration test (streamBatchItems.test.ts) that drives the real service against Postgres + Redis + RunEngine and times a 150-item batch at increasing concurrency. Object-store offload is modelled as a fixed per-item latency (local round-trips are too small to compare meaningfully): runCount=150 large payloads (10ms/item offload): concurrency=1 1739ms concurrency=10 192ms (9.1x faster) concurrency=50 57ms (30.7x faster) small payloads (Redis enqueue only, no offload): concurrency=1 90ms concurrency=10 24ms (3.7x faster) The test asserts correctness at every concurrency (all items accepted, sealed, enqueued exactly once), that parallel ingest beats the sequential floor, and that the small-payload case is strictly faster than sequential, so the win is not specific to large payloads. Also exercised end-to-end over real HTTP against a local server: a 20-item batch (12MB body) ingests and seals, a re-stream of the sealed batch returns sealed: true with zero re-accepted items (idempotent retry), and an oversized item still seals at its correct index. Existing coverage stays green: concurrent ingest of a 100-item batch, in-flight processing never exceeding the configured concurrency, concurrent dedup on streaming retry, and emit-position marker indexing. Follow-ups (not in this PR) SDK pre-offload of large item payloads (send application/store refs instead of raw blobs) to remove object-store work from the request hot path and shrink the request body. Optional server.requestTimeout bump as a safety net. CI fix Added .github/workflows/codeql.yml to replace GitHub's automatic ("dynamic") CodeQL scanning. The dynamic setup was failing to upload SARIF results because the auto-generated GITHUB_TOKEN lacked the security-events: write permission. The explicit workflow grants that permission at the job level and pins all actions to commit SHAs, consistent with the repo's security conventions. ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention. I ran and tested the code works Testing Integration test (streamBatchItems.test.ts) validates correctness and performance at concurrency 1, 10, and 50 for both large and small payloads. End-to-end verified over real HTTP: 20-item/12MB batch ingests and seals, idempotent retry returns sealed: true, oversized item seals at correct index. Changelog Streaming batch ingest now processes items with bounded concurrency instead of one at a time, so batches of many large payloads ingest far faster and no longer time out. Concurrency is configurable via STREAMING_BATCH_INGEST_CONCURRENCY (default 10); set it to 1 for fully sequential ingestion. Screenshots [Screenshots] 💯
Open Graph Description: Problem The item-streaming endpoint of the two-phase batch API (POST /api/v3/batches/:batchId/items) processed streamed items strictly sequentially. For a batch of many large payloads, each offload...
X Description: Problem The item-streaming endpoint of the two-phase batch API (POST /api/v3/batches/:batchId/items) processed streamed items strictly sequentially. For a batch of many large payloads, each offload...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/3777
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4cfd6803-ba22-0a1a-f388-aeac89653428 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DE3E:1F5CA2:3337B4:4BB248:6AFAE0F8 |
| html-safe-nonce | 2a5cfb520f7a99d85084f041000d6d22945a4bca2e9793d8fdd8dd9600df6316 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTNFOjFGNUNBMjozMzM3QjQ6NEJCMjQ4OjZBRkFFMEY4IiwidmlzaXRvcl9pZCI6IjY2NzQ4MTI2ODgwMDc4ODA5NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0ee3a0baf850cbff3dffbbe2b348b9bb907a9671f2bce91be7e66c79932baec0 |
| hovercard-subject-tag | pull_request:3770705323 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/3777/files |
| twitter:image | https://avatars.githubusercontent.com/u/10635986?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/10635986?s=400&v=4 |
| og:image:alt | Problem The item-streaming endpoint of the two-phase batch API (POST /api/v3/batches/:batchId/items) processed streamed items strictly sequentially. For a batch of many large payloads, each offload... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d9bd51a568909a83d1abb9d6f74d68f0c87ca85fe3a56d3f5d70d8b89add9f2 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a7ae932999cc6d511008dbf980ff9efad2a31f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width