How to Call a Private Google Cloud Run Service From Outside Google Cloud With Identity Tokens
A program outside Google Cloud needs two things to call a Cloud Run service protected by Identity and Access Management (IAM): a…
When your service copies a provider’s records through an API and also receives webhook notifications, you have to bridge the gap between the initial read and the ongoing updates. A webhook is a message the provider sends when something changes. When your service imports existing records through the API, it usually reads them across multiple pages. Because records can change while your client walks those pages, the API responses and the incoming webhooks can describe different states of the same record.
To avoid losing or overwriting data, your service should first establish a provider-supported change boundary, save incoming webhook events while it reads the existing records, and then fetch changes from that boundary before relying on ongoing updates. A change boundary is a token, cursor, or timestamp from the provider that marks where to start pulling later changes. Providers make different guarantees, so check their documentation to see whether the initial read forms a consistent snapshot, how they order changes, and whether they let you retrieve missed events later.
Your client reads a paginated collection one page at a time. While it moves from one page to the next, a user or another system can create, update, or delete a record. As a result, your client can read an older version of a record from a page after a webhook carrying a newer version has already arrived. It can also miss a newly created record if it has already passed that part of the collection and the provider’s pagination does not account for changes made mid-read.
Your service cannot fix this race by applying each response as it arrives. If the client writes an older record from an API page over a newer webhook update, your local copy rolls back to an outdated state. Likewise, a delayed webhook can overwrite a newer record if your service treats arrival order as change order. Shopify documents that webhook deliveries can arrive out of order and points to provider-specific timestamps for sorting them. Use those timestamps only within the scope and precision Shopify documents, since they are not universal sequence numbers. See why webhook events arrive out of order for more on this ordering problem.
Before you start the import, check whether the provider offers a sync token, delta link, event cursor, or documented snapshot mechanism. Find out when that boundary becomes valid. Some providers let your client set it before reading the first page, while others return a continuation token only with the final page. Follow the provider’s documented method rather than picking a timestamp yourself.
While your client reads the initial pages, save incoming webhook events instead of discarding them. For each event, store the provider’s permanent ID for the record (its stable resource identifier) along with any fields the provider tells you to use for comparison or later retrieval. That way, your service can account for changes that happened during the import instead of treating the initial read as its only source of truth.
Each provider makes its own guarantees. Google Calendar documents that a full sync returns a nextSyncToken on the final page, and its page-token method accounts for entries added while your client reads pages. That guarantee belongs to Google Calendar’s sync API; ordinary pagination does not provide it. Microsoft Graph provides a different approach for supported resources: a delta query returns the collection state and then gives your client an @odata.deltaLink to fetch future changes.
Store each imported record under its stable resource identifier so the initial read and the saved webhook events point to the same local record. If the provider supplies a version number or timestamp for comparing records, use it only when the documentation explains what it means and how to compare values. Apply whichever state the documented comparison shows is newer. Handle deletions the way the provider documents, using its delete event or tombstone (a change record that marks a resource as deleted).
Once your client finishes reading the initial pages, use the saved boundary to fetch changes from that point onward. Keep saving live webhook events while this catch-up runs. Then merge the fetched changes and the saved events by resource identifier and documented version or timestamp. Save the latest continuation token or watermark only after catch-up finishes, so your service can resume from a known point if it restarts.
If the provider gives you no reliable field for ordering changes, arrival order will not tell you which version is newer. Use a provider-supported method to fetch or reconcile the record instead. Microsoft Graph, for example, can return a resource again across delta pages, so your client should combine results by resource identity rather than treating response order as change order. Its delta results also cover only supported resources and properties, and documented replication delays affect when changes appear.
A webhook feed does not always give you a complete change log that you can replay. Shopify warns that it does not guarantee delivery and recommends comparing local records against provider data. Shopify also notes that it can debounce narrowed webhook payloads when consecutive qualifying payloads are identical. On top of that, a provider’s change token can expire, arrive late, or cover only certain resources. For example, Google People’s otherContacts.list documentation gives that endpoint a seven-day sync-token lifetime, a limit that does not apply to other APIs.
Check the documentation for the exact resource and API version you plan to use. Verify whether the initial read is a consistent snapshot and whether the change mechanism includes deletions. You should also check which properties it tracks, when tokens expire, and whether the provider supports event replay or requires a full resync. If your service can miss notifications or if a catch-up boundary can expire, schedule reconciliation as the provider documents, because saved webhooks cannot recover every gap.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com