01IntegrationsType: Reference architecture
CRM and ERP in step, with no silent overwrites
A reference design for two-way sync on serverless middleware: one owner per field, and a person for anything ambiguous.
Shows
- Enterprise Integrations
- Software Architecture
- API Design
Where this comes from: Drawn from systems I've designed on Zoho. The business, names and data here are generalized. The patterns and failure modes come from real work, and the design includes what that work taught me.
On This Page
In 30 Seconds
Middleware on Zoho Catalyst keeps Zoho CRM and an ERP in step in both directions, through one durable queue: a table with one row per record. Every field has one owning system and syncs only from it. Outages make work wait, bad data waits for a fix, and anything ambiguous stops for a person.
What It Guarantees
- A record edited on both sides is never silently overwritten.
- An outage never turns good data into failed records.
- A create with an unknown outcome is never retried blindly.
- Staging a change twice is a no-op, and only writes known to be safe retry on their own.
- The sync's own writes never bounce back as new changes.
The Problem
Picture a distributor whose sales team works in Zoho CRM while finance, stock and deliveries run in an ERP. Staff type every customer twice, and sales can't see balances, orders or deliveries.
A link sounds simple until you list what it must survive. The two systems fail and throttle independently. The ERP keeps its own numbering and stays the reference for money. An order can't exist in the ERP before its customer does. Change events arrive late, twice or out of order. The ERP's API has no idempotency key, so when a create times out, nobody knows whether it landed. And the customer record lives in both systems, edited by two teams.
Workflow rules and scheduled scripts handle the happy path and fail quietly on the rest.
The Approach, in One Sentence
Every change becomes one row in a durable queue and reaches the other system only when the write is known to be safe; otherwise the row waits or stops for a person.
Architecture
Connections in this diagram
- ERP changes → Durable queue (stage)
- CRM changes → Durable queue (stage id)
- Nightly safety net → Durable queue (re-stage)
- Durable queue → Read fresh, validate (claim)
- Read fresh, validate → Target changed since? (valid)
- Target changed since? → Write on shared key (no)
- Target changed since? → Stop for a person (yes)
- Write on shared key → Park and wait (system down)
- Write on shared key → Stop for a person (create unclear)
Key Decisions
A middleware with a durable queue, not CRM workflows calling the ERP
The alternative was Deluge on workflow triggers, plus an hourly scheduler. Deluge has no durable queue, no locking and no backoff, so any state between runs is hand-built in CRM records. Yet each record in flight needs saved state before any external write, and retries and alerts need one home.
One owner per field, not "last write wins"
The alternatives were last write wins, or the newest timestamp. Clocks in two systems disagree. I've seen a wrong time-zone assumption shift every pull window by hours. The customer record lives in both systems, so I split it by field: sales owns contact details, finance owns terms, balances and numbering.
Classify every failure before retrying
The alternative was one retry policy for everything, which lets an outage burn every record's retries. So system failures (timeouts, server errors, throttling) park without counting an attempt. Missing data waits for a fix before any write. A rejected write spends the record's few retries, then waits for a person. A transport error on a create goes straight to a person, because a retry could create the record twice.
Match on the ERP's internal id, not a natural key
The alternatives were tax id, email or name. Branches share a tax id, and customers share emails. The id lives in a unique CRM field, and every upsert names it as the match field. Zoho's API documentation says that, unless told which field to match on, its upsert (insert or update, matched by key) checks system duplicate-check fields such as an account's name first, then unique fields. An account could then match another with the same name.
When Things Go Wrong
The ERP goes down or throttles
A short run of system failures opens a circuit breaker (a switch that stops all calls to the ERP) for a couple of minutes. A rate-limit answer keeps it open for as long as the ERP asks. Rows park, pulls keep their watermark (the time of the last good pull), and work resumes on its own.
A create times out
The row goes to the dead-letter queue, where a person sees a hint: search the ERP for the CRM id before replaying. A timed-out update is parked and retried, since it is idempotent: sending it twice gives the same result.
Someone edits an owned field on the wrong side
Before writing, the sync compares the target with what it last wrote. If they differ, the row stops as a conflict, and a person picks the value.
Records arrive out of order
Each run handles customers, then deals, then quotes, so a new customer unblocks its quote in the same run. A row still waiting for its parent after about two hours goes into the next daily digest.
The source sends an empty value
Blank means "nothing sent", not "erase". Only a field's owner can clear it.
What the Business Gets
- Staff type a customer once, and sales sees balances, orders and deliveries in the CRM.
- Finance keeps the ERP as the reference for numbering and money.
- Problems show on the record that has them, with a reason anyone can act on.
- An outage costs time, not data, and one switch pauses all ERP writes without loss.
For Engineers
Data model. Queue row: entity, direction, source id, unique key entity|direction|source id, payload, fingerprint, state, attempts, next try. Cross-reference: CRM id, ERP id, and the fingerprint last written each way. Watermarks: per pull job, in the source's clock, advanced only after a fully successful run.
States. ready → working → done, with exits to ready (backoff), waiting_data, waiting_parent, parked, conflict and dead_letter. A reaper frees rows stuck in working after a crash.
Idempotent staging. Same fingerprint: skip, so retry counts survive. New fingerprint: back to ready, which also revives stuck rows once the source is fixed. Rows being worked are left alone. A CRM event carries only the id and event time. At staging, the event time is the row's change marker, so a redelivered event is a no-op.
Echo guard and triggers. Fingerprint = SHA-256 of the mapped fields, keys sorted, metadata left out. Every CRM write sends an empty trigger list ([]). Zoho's documentation says that if it is left out, the matching workflow rules, approvals and Blueprint run for that write.
Retries. Only rejected writes spend attempts. Backoff grows from seconds to half an hour, then dead-letter. A failed read must raise, never return an empty list, or "deleted" and "unreachable" look the same.
process(row):
rec = read_fresh(row.source_id) # never trust the event payload
if rec is gone: return done(row, "deletes are not synced")
if problems(rec): return wait_for_data(row, problems(rec))
out = owned_fields(map(rec))
if hash(out) == xref.last_sent(row): return done(row, "echo")
if target_now(row) != xref.last_written(row): return conflict(row)
try: write(out)
except SystemFailure: return park(row) # attempts unchanged
except Timeout: return needs_person(row) if creating else park(row)
except DataFailure: return retry_or_dead_letter(row) # rejected: spends an attempt
xref.record(row, hash(out)); done(row)
Tests. Offline, both APIs mocked, first step of the deploy command: echo guard, kill switch, create timeout (dead-letter), update timeout (park). Each deploy ships exactly one commit, so live code traces back to the repo.
A limit to know. The comparison and the write are two calls, so an edit that lands in the moment between them can still be overwritten.
How I Build Systems Like This
I start from a written spec, a data dictionary of every synced field, and a decision on which system owns each one. AI agents (Claude Code) help with analysis, review and audits under written rules: read-only by default, a backup before any write, no deploy until live code matches the repo. In my audits, every claim records how it was verified.