Skip to content

Parallel sync & rate limit#194

Merged
Yostra merged 7 commits intov2from
v2-parallel
Mar 30, 2026
Merged

Parallel sync & rate limit#194
Yostra merged 7 commits intov2from
v2-parallel

Conversation

@Yostra
Copy link
Copy Markdown
Collaborator

@Yostra Yostra commented Mar 29, 2026

Summary

v2 dropped parallel backfill support, causing all Stripe list API calls to run sequentially. This restores parallel sync by splitting backfills into time-based segments using the account's created timestamp.

Streams that support created filter are split into 200 time segments and fetched concurrently via mergeAsync
Token-bucket rate limiter (default 25 req/s, configurable via RATE_LIMIT env) prevents hitting Stripe rate limits
Segment state is persisted in stream state for resumability across restarts
Streams without created filter support fall back to sequential pagination (existing behavior)

Test plan

  • Run backfill against a Stripe account with substantial data and verify parallel segments are fetched concurrently
  • Interrupt and resume a sync to verify segment checkpoint/resume works
  • Verify streams without supportsCreatedFilter still sync sequentially
  • Test with RATE_LIMIT env var to confirm rate limiting is respected

@Yostra Yostra force-pushed the v2-parallel branch 4 times, most recently from 02b137e to 1cea7b4 Compare March 30, 2026 00:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Restores parallelized Stripe list-API backfill in source-stripe by segmenting by created time ranges and adds request-rate limiting (in-memory by default, with an Engine-side Postgres-backed limiter when syncing to Postgres).

Changes:

  • Add segmented parallel backfill for supportsCreatedFilter streams, with resumable per-segment checkpoints.
  • Introduce a token-bucket rate limiter abstraction + in-memory implementation; plumb it through the Stripe source.
  • In Engine API, optionally inject a Postgres-backed distributed limiter (via @stripe/sync-util-postgres) when the destination is Postgres.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds workspace dependency wiring for @stripe/sync-util-postgres.
packages/source-stripe/src/src-list-api.ts Implements segment-based parallel backfill, merge of async generators, and rate-limited pagination.
packages/source-stripe/src/rate-limiter.ts Adds RateLimiter contract + in-memory token-bucket implementation.
packages/source-stripe/src/index.ts Extends config/state schema (rate_limit, backfill_concurrency, segments) and injects limiter into backfill.
packages/source-stripe/src/index.test.ts Adds tests for segment resume/checkpointing, sequential fallback, and rate limiter behavior.
apps/engine/src/api/app.ts Adds Postgres-backed limiter creation and injects it into the Stripe source during /read and /sync.
apps/engine/package.json Adds @stripe/sync-util-postgres dependency to support distributed rate limiting.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Yostra Yostra merged commit 6f5f7c6 into v2 Mar 30, 2026
6 checks passed
@Yostra Yostra deleted the v2-parallel branch March 30, 2026 22:24
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.

3 participants