RMR

Incremental Email Sync With Gmail History and Microsoft Delta

Gmail and Graph cursors cut sync cost, if you plan for expiry.

· 8 min read
Cover illustration for “Incremental Email Sync With Gmail History and Microsoft Delta”
Email Data Extraction · December 4, 2026 · 8 min read · 1,786 words

Incremental email sync with Gmail History and Microsoft Graph Delta replaces repeated mailbox scans with a stored cursor that returns only what changed. Keeping efficient sync reliable enough to support current, permissioned relationship data requires understanding the APIs’ different scopes, preserving their checkpoints, and planning for expiry.

Why full-mailbox polling fails at scale and what token-driven sync replaces it with

Before the application knows what is new, it must page through message IDs, paying for that work even when nothing has changed. As mailboxes grow, the scan becomes more expensive without necessarily yielding more useful data. Across many connected accounts, that mismatch becomes an operational constraint.

Why should an inbox that has not changed need another scan? A persistent cursor gives the application a different starting point, marking where the previous sync stopped so that the next request retrieves changes since then. This shifts the workload from mailbox size toward change volume. A quiet inbox returns almost nothing, while a busy one takes more work as more changes come in. Full reads still have a role in initialization and recovery, but they no longer need to be the recurring default.

How Gmail's historyId cursor works as a monotonically increasing change log

Gmail uses historyId, a monotonically increasing integer, to mark a position in a mailbox’s change history. The application stores that position and calls users.history.list with startHistoryId set to the saved value. The response shows which messages were added, deleted, or relabeled since that point. The application processes those changes and updates its checkpoint. The cursor therefore represents progress through mailbox history.

That distinction becomes important during the initial full sync. The application should store the historyId of the most recent message, which is the first message in the list response, as its baseline. That value comes from a message, but later incremental calls use it as the starting point for the whole mailbox. Messages added or deleted during that scan can then appear in subsequent history responses as messageAdded or messageDeleted records, provided the baseline remains within the available history window.

Gmail returns nextPageToken when more history remains, so a high-volume mailbox still needs a pagination loop. The historyTypes parameter narrows processing to categories including messageAdded, messageDeleted, labelAdded, and labelRemoved. For applications that want conditional message reads instead, Gmail has no ETag contract on message resources. The supported change marker is historyId, used with history.list.

The push layer that eliminates Gmail's polling loop: Pub/Sub, watch(), and the historyId handoff

Diagram: Gmail Push Sync: From Pub/Sub Signal to History Retrieval. Visualizes: Show the step-by-step flow of Gmail's push-based incremental sync pipeline.

A cursor reduces the cost of checking for changes, but it does not decide when to check. Gmail’s users.watch tells the application when to check through Pub/Sub. Setting it up needs a cloud project, a topic, and an access-control grant, so using push takes work on infrastructure as well as on request parameters. In return, Gmail can notify the application within seconds of a mailbox change, removing the timer-driven polling loop.

The watch response supplies a historyId baseline and an expiration timestamp. When a change occurs, Gmail publishes a base64-encoded notification containing the user’s email address and a new historyId to the configured topic. A Pub/Sub subscription forwards that notification to the application’s HTTPS webhook endpoint. The notification is a signal. After decoding it and comparing its position with the stored checkpoint, the application calls users.history.list using the stored value as startHistoryId.

This separation also gives the pipeline some outage tolerance. If the webhook is temporarily unavailable, Pub/Sub retries delivery according to the subscription’s acknowledgment deadline. However, delivery durability does not remove the need to maintain the watch itself. A watch expires after 7 days, and a daily renewal job is required. A lapsed watch can stop events silently, without an error signal telling the application that its mailbox view is becoming stale.

How Microsoft Graph's delta query replaces EWS SyncFolderItems with a cursor-per-folder model

Microsoft Graph follows the same checkpoint principle, but its unit of tracking is a folder. The first call to /me/mailFolders/{id}/messages/delta performs a full pull, paging through that folder before returning a deltaLink at the end of the response set. The application stores this URL-encoded cursor and uses it for subsequent calls. Those calls return what has been added, changed, or removed since the saved position. The link is the continuation point for future syncs.

Sent Items, Drafts, and custom folders each require their own delta request and persisted deltaLink. There is no supported /me/messages/delta endpoint for a mailbox-wide equivalent. What happens, then, when a message moves? The source folder reports @removed, while the destination reports a fresh upsert, but the application sees both sides only if it tracks both folders. For an Inbox-only sync, a move to Archive looks like a deletion.

Graph’s Change Notifications provide the wake-up signal, while delta queries retrieve the changes, paralleling Gmail’s division between Pub/Sub and history retrieval. Teams migrating from Exchange Web Services will recognize the separation between notification and synchronization. EWS used Streaming Notifications and a SyncState string for each folder through SyncFolderItems. Graph uses Change Notifications and Delta Queries in their place. The per-folder model must therefore remain explicit in the implementation rather than being treated as a missing mailbox-wide feature.

Where each token expires and how to handle the fallback to full sync

Diagram: Checkpoint Expiry and the Full-Sync Fallback Path. Visualizes: Show two diverging paths from a single decision point: 'Is the stored checkpoint still valid?' Left path (YES): call incremental API (history.list / delta query) → process…

Neither provider promises an indefinitely usable checkpoint. Maintenance windows, outages, and extended periods without processing can leave an application with a cursor older than the history it can retrieve. Expiry belongs in the normal operating model. A production client needs both an incremental path and a full-sync fallback, because persisting a token does not guarantee that the provider can still honor it.

Gmail history records typically remain available for roughly a week, but in rare circumstances that window can shrink to hours. When a stored historyId falls outside it, history.list returns a 404. The application must detect that response and perform a full re-sync to establish a fresh baseline. Renewing the watch does not prevent this failure. Watch expiry governs the push layer, while history expiry governs how far back the application can retrieve changes, so a healthy subscription can coexist with an unusable checkpoint.

Graph likewise returns an error if a delta token has expired after a long offline period. Recovery requires the application to fall back automatically to a full pull and store the fresh deltaLink issued at the end. Because Graph tracks each folder on its own, it also needs recovery state for each folder. Without a dependable checkpoint, the application lacks the position from which to attempt incremental recovery or determine that its saved state can no longer be used.

A sync checkpoint can look like just another piece of configuration. In practice, it is a durable handle tied to a mailbox’s change history, and a deltaLink includes tenant-identifying material as well as its sync position. How cursors are stored is therefore a choice about both database design and security. They should get the same care as refresh tokens.

For production systems, the recommended treatment is encryption at rest using a key management service and read access limited to the specific service account that owns the sync. Stored cursors should also be rotated or invalidated when ownership changes through account offboarding, permission revocation, or tenant churn. A checkpoint should not become an overlooked remnant of a connection whose owner or authorization has changed.

Isolation must extend to each connected mailbox as well. Every mailbox has its own OAuth grant, refresh token, and cursor checkpoint, so exposure of one user’s state must not cascade to others. This matters even more when the output shows professional relationships as well as what is in an inbox. Who communicates with whom can itself be a sensitive institutional asset. Permissioned architecture and data privacy therefore apply to the sync handles as well as to the interaction data they help retrieve.

Quota management and multi-tenant scale: where the per-user limits bite and how to stay inside them

Correct checkpoints do not remove every quota constraint. Gmail sets limits for each user mailbox as well as each project, so the shared project budget alone cannot show how much work the application can do. Each connected account needs its own rate envelope. A quiet account and a heavily changing mailbox impose different workloads even when both use the same incremental architecture. Treating them as one undifferentiated stream hides the constraint at the point where it will be enforced.

The recommended production patterns include exponential backoff with jitter on rate-limit responses, batching during initial full-sync passes, and per-account token and checkpoint management. These address different parts of the workload. Backoff governs the response to throttling, while account-level management helps prevent one busy mailbox from consuming the shared budget at others’ expense. Incremental retrieval is still the main way to save quota because it avoids reading the same unchanged data over and over. The supporting controls handle pressure that remains after that larger waste is removed.

Initialization and recovery are where that pressure returns. A new account still needs its full baseline, and an account whose checkpoint has expired needs another full read. A multi-tenant service must therefore plan its quota for more than the incremental traffic it gets in normal use. What happens during a fallback belongs in the same capacity model as ordinary changes. Otherwise, the recovery path that keeps the data correct will be the least ready to handle the load.

What the sync output is actually for: turning message deltas into relationship signals

The useful output is more than a current inbox. A Gmail messageAdded record or a Graph upsert can supply a sender, recipient, timestamp, and thread, providing evidence of a human interaction. For relationship intelligence, the connection supplies the signal. Across connected accounts, these signals describe who knows whom and how recently and frequently they have interacted. The engineering work makes that network observable without requiring people to map it manually.

A colleague’s repeated contact with a target decision-maker at a previous company may expose a warm introduction path absent from the CRM and unlikely to be reported from memory. Alpha Watch is one company that treats relationship data scattered across email, calendar, and messaging apps as an undervalued asset. Keeping that data up to date makes the choice between polling and delta matter for this work as well as for the inbox.

AI-driven relationship scoring, including ranking introduction paths, surfacing engagement gaps, and drafting outreach for human review, depends on current interaction data. Stale or incomplete sync produces stale or incomplete relationship intelligence. A notification is therefore only the beginning of the chain. The final test is whether the pipeline preserves enough accurate, permissioned continuity for the connections it reveals to be trusted.

More in Email Data Extraction