Two-way ERP sync
Keeps HubSpot and the Dataforma ERP in step in both directions, after moving the ERP’s history into HubSpot with a ledger that can undo every write.
Data paths and guards
- HubSpot: Where reps work: deals, buildings, work orders and the record cards.
- Slack alerts: One alert per cause from the health board.
- Sync service: 24 routes on Vercel: the pollers, the webhook inbox and the card endpoints.
- State store: Id map, cursors, audit log, dead letters and the migration ledger.
- Dataforma, the ERP: Projects, work orders, buildings and estimates.
- From Dataforma, the ERP to HubSpot: History, loaded once. Companies, contacts, buildings, deals and work orders from the ERP’s history. One reversible load, before the sync went live.
- From Dataforma, the ERP to Sync service: Changes, by cursor poll. ERP records changed since the last cursor, and records with ids past the watermark. Cron schedules on the service.
- From Sync service to HubSpot: Deals and work orders. Records created or updated in HubSpot, matched by their ERP id. Each polled change.
- From HubSpot to Sync service: Edits and card actions. Rep edits to synced deal fields, and new ERP projects requested from a card. A signed webhook, and a reverse poll every 5 minutes.
- From Sync service to Dataforma, the ERP: Whole-record writes. The full ERP record, read first and written back with the edit. A queued edit that passes every gate.
- From Sync service to State store: Ids, cursors, dead letters. The id map, cursors, audit log, dead letters and ledgers. Every run.
- From Sync service to Slack alerts: Health checks. 12 checks, each alert keyed to its cause. Each health run.
- On Changes, by cursor poll: Cursor and id watermark. The poll follows ids as well as dates, because a record that was never edited has no modified date.
- On History, loaded once: Reversible ledger. Every migrated write is journaled, so a load can be rolled back.
- On Edits and card actions: Signed webhooks only. The inbox accepts only webhook calls that HubSpot signed.
- On Whole-record writes: Flags, allowlists, recency. A write runs only where its surface is switched on, the field is allowlisted, a person made the edit and nothing newer came from the ERP.
- On Whole-record writes: Read-back breakers. Each write is read back, and 8 breakers stop any surface whose writes do not match.
- On Ids, cursors, dead letters: Dead-letter ladder. A failed record retries at 15 minutes, 2 hours and 4 hours, then daily, and the daily lane has no final state.
- Built by me
- Platforms I connect to
- Guards
- Data paths
- In production
| History, loaded once Companies, contacts, buildings, deals and work orders from the ERP’s history |
|---|
| Changes, by cursor poll ERP records changed since the last cursor, and records with ids past the watermark |
| Deals and work orders Records created or updated in HubSpot, matched by their ERP id |
| Edits and card actions Rep edits to synced deal fields, and new ERP projects requested from a card |
|---|
| Whole-record writes The full ERP record, read first and written back with the edit |
| Ids, cursors, dead letters The id map, cursors, audit log, dead letters and ledgers |
| Health checks 12 checks, each alert keyed to its cause |
-
Systems
Reps work in HubSpot. The ERP keeps projects, work orders and buildings. Between them runs a TypeScript service on Vercel functions, with its state in Supabase Postgres and its alerts in Slack.
-
Data paths
The ERP’s history moved into HubSpot once, through a ledger that can undo it: 38,301 work orders and 11,215 deals, with 0 failed writes. After that, the service polls the ERP and writes each change to HubSpot.
- a History, loaded once
- b Changes, by cursor poll
- c Deals and work orders
-
Write-back
A rep’s edit, or a new project requested from a card, arrives as a signed webhook, and a reverse poll every 5 minutes makes sure none is missed. The service writes the whole ERP record back and keeps its state in the store.
- d Edits and card actions
- e Whole-record writes
- f Ids, cursors, dead letters
- g Health checks
-
Guards
Nothing writes to the ERP until it passes flags, allowlists and a recency gate, and every write is read back. A failed record climbs a dead-letter ladder that never closes without a fix.
- Cursor and id watermark on b
- Reversible ledger on a
- Signed webhooks only on d
- Flags, allowlists, recency on e
- Read-back breakers on e
- Dead-letter ladder on f
-
Result
11,598 deals are linked to the ERP, and a rep’s edit in HubSpot reaches it in about 5 minutes.
Project ids typed by hand, and an ERP with no webhooks
Reps typed ERP project ids into HubSpot by hand, and nothing synced between the two systems on its own. The ERP has no webhooks, replaces the whole record on every update, stamps times with no time zone, and shares one rate limit with the client’s staff.
What I built
- A TypeScript service on Vercel: 24 routes, 11 of them cron schedules.
- A Supabase Postgres state store, built over 35 migrations: id map, cursors, audit log, dead letters, webhook inbox and a migration ledger.
- A HubSpot app with 10 record cards and a settings page, where reps create ERP projects and edit 12 synced deal fields.
- A migration pipeline with fuzzy matching, a human review band and a ledger that can roll back every write.
- A 12-check health board with Slack alerts, and a dead-letter ladder that retries at 15 minutes, 2 hours and 4 hours, then daily.
What the guards protect against
| The risk | The guard |
|---|---|
| Records that were never edited stay invisible to a date window. | Cursor and id watermark The poll follows ids as well as dates, because a record that was never edited has no modified date. |
| A bad load cannot be undone. | Reversible ledger Every migrated write is journaled, so a load can be rolled back. |
| An unsigned call reaches the ERP. | Signed webhooks only The inbox accepts only webhook calls that HubSpot signed. |
| An echo or a stale edit overwrites newer ERP data. | Flags, allowlists, recency A write runs only where its surface is switched on, the field is allowlisted, a person made the edit and nothing newer came from the ERP. |
| A write reports success but never landed. | Read-back breakers Each write is read back, and 8 breakers stop any surface whose writes do not match. |
| A failed record is dropped and forgotten. | Dead-letter ladder A failed record retries at 15 minutes, 2 hours and 4 hours, then daily, and the daily lane has no final state. |
Decisions
-
Poll the ERP, and follow ids as well as dates
- Chose
- Poll on a cursor plus an id watermark.
- Instead of
- A window on the last-modified date. A record that was never edited has no modified date, so a date window never sees it.
- Trade-off
- Polling spends the rate limit the client’s staff share: a full reconcile takes 345 requests and about 108 seconds.
-
Write the whole record back, never a patch
- Chose
- Every write to the ERP reads the record, changes the edited fields and writes the whole record back.
- Instead of
- Sending only the changed fields. The ERP replaces the whole record on every update, so a write that leaves a field out empties it.
- Trade-off
- Every write costs a read first.
-
Pause the client’s own workflows during the load
- Chose
- A guard paused the client workflows that overlapped the load and restored them when it finished.
- Instead of
- Loading with every workflow running. 13 of 18 enabled deal workflows overlapped the load, and 3 of them ended in emails to customers.
- Trade-off
- The overlapping automations stop while a load runs; the deal load took about 26 minutes.
Results
- 11,598 deals linked to the ERP.
- 38,301 work orders and 11,215 deals migrated, with 0 failed writes.
- 34,251 associations drawn across 11,220 projects, and 3,856 billing offices loaded.
Facts
- Association-label limit measured at 50 per object pair, against a documented 10
- Cutover in two steps: deployed with writes off, one cycle watched, then writes switched on
- Round trip proven in HubSpot’s own screens: a card made an ERP project, and edits crossed both ways
Related builds
-
Two-way field-service sync
Date: Feb 2026
Fact: 11,683 deals and 8,182 tickets in a two-way sync
Client: For a commercial roofing service contractor
Systems: CenterPoint Connect, Zapier, QuickBooks Online and Make.com
Status: In production
-
Multi-tenant event processor
Date: Jun 2026
Fact: 10,630 events in 7 days through the queue that replaced Make.com
Client: For a multi-brand roofing company
Systems: AccuLynx and Make.com
Status: In production
-
Desktop accounting connector
Date: Jun 2026
Fact: Sales recognition reconciled to the cent across 3,709 deals
Client: For a residential roofing and solar contractor
Systems: QuickBooks Desktop
Status: In production