Many automations start simple: “Every night, pull new records from System A and push them into System B.” It works for weeks, then you discover missing items, duplicates, or a backfill that takes hours and locks up your downstream system.
The root cause is usually not the API call itself. It is state. If your job does not clearly remember what it processed last, it has no reliable way to answer the question “What should I fetch next?”
This post explains an evergreen approach for small teams: checkpointed syncs. You will learn how to pick a good cursor, store it safely, and design the flow so it can restart without creating gaps.
Why scheduled syncs break
Most scheduled “poll and copy” jobs break because they rely on assumptions that stop being true as volume grows or as systems behave differently under load. A few common failure modes show up across CRMs, ticketing tools, ecommerce platforms, and analytics systems.
- Time window drift: A job fetches “records from the last 24 hours” but runs late, runs twice, or overlaps with an outage. This creates gaps or duplicates.
- Non-deterministic ordering: You fetch pages of results without a stable sort key, so items can move between pages while you are paging.
- Partial success: The job inserts some records, fails mid-run, then reprocesses the whole window on the next run.
- Late-arriving updates: Systems often update older records (a contact changes phone number) long after creation, which time-window-only approaches miss.
A checkpointed sync is essentially a disciplined way to define “done” so a run can stop and resume without guessing.
The checkpoint pattern (in plain language)
A checkpoint is a small piece of state that represents the position of your sync. Each run uses the checkpoint to fetch the next chunk of work, processes it, and then advances the checkpoint.
There are two common forms:
- Cursor: “Everything with an ID greater than X” or “everything after cursor token Y.”
- Watermark: “Everything updated after timestamp T.”
The pattern works best when your data source supports an incremental query that is both stable and ordered. If it does, you can treat the API as a stream: you read forward, commit progress, repeat.
Key Takeaways
- Design your sync around a stable ordering key (cursor) rather than “last N hours.”
- Advance checkpoints only after work is durably written downstream.
- Use a small overlap window (lookback) to handle late updates, and dedupe downstream.
- Make restarts boring: a rerun should be safe and predictable.
Choose a cursor you can trust
Picking the cursor is the most important design decision. A “good” cursor has a few properties: it is monotonic (moves forward), comparable (you can sort by it), and available in every record you care about.
Common cursor options
- API-provided cursor tokens: Some APIs return a
next_cursortoken. Use it if it is documented as stable and designed for pagination. - Increasing numeric IDs: If IDs are strictly increasing and queryable as “greater than,” they can be excellent cursors.
- Updated-at timestamps: Useful, but risky if timestamps are not precise, can move backwards, or are only updated on some changes.
If you can choose between “created_at” and “updated_at,” prefer updated_at when your downstream needs to reflect edits. But do not assume timestamps alone are safe. Ties happen. Clocks drift. Records can share the same timestamp value.
A robust compromise is a compound cursor: sort by (updated_at, id). You advance by the last processed pair. This avoids skipping items when multiple records share the same timestamp.
checkpoint:
updated_at: "2026-11-16T03:14:15Z"
id: "contact_84219"
query:
order_by: ["updated_at", "id"]
filter: updated_at > checkpoint.updated_at
tie_breaker: id > checkpoint.id when updated_at equals checkpoint.updated_at
Even if your API does not support compound filtering directly, you can approximate it with a lookback strategy (described later) and downstream deduplication.
Where to store state and how to update it safely
Your checkpoint must live somewhere durable that every run can read. The simplest storage is often best:
- A small database table keyed by job name (recommended if you already have a database).
- A single file in object storage or a repo (works, but be careful with concurrent runs).
- A workflow tool’s built-in variable store (convenient, but understand backup and audit needs).
Two rules make checkpoint updates reliable:
- Write downstream first, checkpoint second. Do not advance the checkpoint until you have durably stored the records you just processed.
- Advance to what you actually processed, not what you requested. If a page returns fewer items than expected, only commit the last item you successfully handled.
Also decide what “one run” means. Many teams structure runs as: fetch a page, process it fully, commit checkpoint, then fetch the next page. If the job fails mid-run, the next run restarts at the last committed page boundary.
Use a small lookback window to cover late updates
Even with the best cursor, you will encounter late updates, API delays, or eventual consistency where a record is not visible immediately. A practical technique is to add a lookback window: on each run, start slightly before the checkpoint, then dedupe downstream.
For example: “start from (last_updated_at minus 10 minutes).” The goal is not to reprocess the whole day. It is to re-scan a small buffer where changes are most likely to show up late.
A concrete example: CRM contacts to an internal database
Imagine a small B2B company that keeps its customer contacts in a CRM. They have an internal database that powers their app and marketing reports. They run a sync every 15 minutes.
Requirements:
- New contacts should appear quickly.
- Edits to existing contacts (name, email, status) must be reflected.
- The sync should survive failures without manual cleanup.
A checkpointed design might look like this:
- Checkpoint stored as (
last_updated_at,last_id) in a database table. - Fetch page of contacts ordered by (
updated_at,id), starting from a lookback of 10 minutes beforelast_updated_at. - Upsert downstream by CRM contact ID (so reruns replace the same record instead of creating a second one).
- Advance checkpoint to the max (
updated_at,id) that was actually processed.
What happens on a failure? Suppose the job processes 600 contacts and then crashes. Because the checkpoint only advanced after each page was fully written, the next run re-reads at most one page plus the 10 minute lookback. Downstream upsert semantics prevent duplicates from becoming separate rows. You get a small amount of extra work, but you avoid gaps and large backfills.
Common mistakes (and how to avoid them)
- Using “last run time” as the cursor: Store a checkpoint that comes from the data, not the scheduler clock.
- Assuming API ordering is stable without specifying it: If the API supports sorting, explicitly set it. If it does not, treat results as unstable and use smaller pages plus dedupe.
- Advancing the checkpoint too early: If you update the checkpoint before downstream writes are committed, a crash can permanently skip records.
- Ignoring updates to old records: If you only sync “created since checkpoint,” edits will never propagate. Prefer
updated_ator a mechanism that captures changes. - No concurrency control: Two overlapping runs can leapfrog checkpoints. Use a simple lock (even “only allow one active run”) or store checkpoints with an atomic compare-and-set.
When not to use checkpointed polling
Checkpointed polling is a strong default, but not always the best fit.
- Near-real-time requirements: If you need updates in seconds, a polling sync every few minutes may be too slow or too expensive.
- Very high volume with strict API limits: If you cannot reasonably scan changes with the available rate limits, you may need a different ingestion approach or a more selective dataset.
- No incremental query support: If the API cannot filter by time, ID, or cursor, your “sync” becomes repeated full exports. That can still work, but it is a different design problem.
- Complex downstream side effects: If “processing a record” triggers emails, tickets, or irreversible actions, you must be extra careful. Favor designs where reprocessing is safe, or isolate side effects behind additional checks.
A copy-and-paste checklist
Use this to review an existing sync or design a new one.
- Cursor: Have we defined a stable ordering key (or compound key) for incremental reads?
- Query: Do we explicitly request ordering and filtering, or are we relying on defaults?
- State storage: Is the checkpoint stored durably and shared across runs?
- Commit rules: Do we write downstream first and advance the checkpoint only after success?
- Restart behavior: If the job crashes mid-run, can the next run resume without gaps?
- Lookback: Do we intentionally re-scan a small overlap window to catch late updates?
- Deduping: Are downstream writes naturally id-based (upsert) so reprocessing is safe?
- Concurrency: Do we prevent overlapping runs from racing the checkpoint?
- Observability: Do we log how many records were fetched, written, and where the checkpoint moved?
- Backfill plan: If we need to resync history, do we have a controlled way to do it (separate job or “start cursor” override)?
FAQ
How big should the lookback window be?
Start small, typically 5 to 15 minutes. Increase it only if you have evidence of late-arriving updates or eventual consistency that exceeds your buffer. The right size is “as small as possible, but large enough to be boring.”
What if the API only supports page numbers, not cursors?
Page numbers can work, but they are fragile if records can be inserted or updated while you paginate. Prefer any server-provided cursor token if available. If not, reduce page size, enforce a stable sort, and consider a lookback window plus downstream upserts to absorb reordering.
Do I always need a database to store checkpoints?
No. You can store checkpoints in a durable file or a workflow tool’s variable store. A database becomes useful when you need atomic updates, auditability, or multiple related syncs. The key requirement is: it must survive restarts and be consistent for every run.
How do I handle deletes?
Deletes are often not visible via incremental “updated_at” queries unless the source provides tombstones or a change log. If your downstream needs accurate deletions, look for a “deleted records” endpoint, a change feed, or periodic reconciliation that compares IDs and marks missing ones.
Conclusion
A checkpointed API sync turns “run it every so often” into a repeatable ingestion process: read forward in a stable order, write durably, then commit progress. With a sensible cursor, a small lookback window, and downstream upserts, you can keep data moving reliably without constant manual cleanup.
If you already have a nightly or hourly sync, adding a checkpoint is usually the simplest upgrade you can make to reduce gaps, shrink backfills, and make failures routine instead of scary.