Sync records from a paginated API to a downstream service
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Dec 2025. It tests api integration, pagination and idempotency.
Finish an integration in an existing Python service (FastAPI, pytest). It reads every page of an authenticated, paginated JSON API, keeps the records that match a filter, transforms them into the shape a downstream service expects, and sends them to that service in one batch request. The batch must be safe to retry without creating duplicates, and every failure must be handled on purpose, not swallowed.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
sync(source_client, downstream_client) -> SyncResult— fetches all pages, filters, transforms and posts one batch; returns how many records were read, kept and sent. - The source API takes an auth token and returns
{"data": [...], "next_cursor": str | None}. - The downstream API accepts
POST /batchwith anIdempotency-Keyheader.
Example
page 1: {"data": [{"id": "r1", "status": "active", "amount": 500},
{"id": "r2", "status": "deleted", "amount": 100}], "next_cursor": "c2"}
page 2: {"data": [{"id": "r3", "status": "active", "amount": 250}], "next_cursor": null}
filter status == "active", transform amount to {"value": amount / 100}
POST /batch Idempotency-Key: <key derived from the batch>
[{"id": "r1", "value": 5.0}, {"id": "r3", "value": 2.5}]
Constraints
- About 75 minutes, in an unfamiliar repository.
- Follow the repository's existing patterns for HTTP clients, configuration and tests.
Clarifying questions
- Which filter and transform rules apply? Are they in the API documentation?
- What should happen when a page fails half-way: retry, abort, or post what was read?
- How should the idempotency key be built so that a retry of the same batch reuses it?
- Is there a limit on batch size?
- How are auth tokens provided and refreshed?
What a strong answer covers
- A pagination loop that follows the cursor until it is empty and guards against a cursor that repeats.
- Auth on every request, and a clear error for 401/403 instead of retrying forever.
- Retries with backoff only for errors worth retrying (timeouts, 429, 5xx).
- A deterministic idempotency key (for example, a hash of the sorted record IDs) so a retried post does not duplicate the batch.
- Explicit handling of a rejected batch: log it, raise it and report it, never silently drop it.
- Tests with fake clients for multiple pages, an auth failure, a failing page and a retried post.
Follow-ups
- The source has millions of records. Post in chunks, and make the whole sync resumable.
- Run the sync incrementally, fetching only records changed since the last run.
- The downstream accepts the batch but rejects some records. How do you report and retry them?
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Dec 202560 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
What it tests
api integration · pagination · idempotency
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
