KatInterview

Design a Two-Way Sync Engine Between a Platform and External SaaS Tools

System DesignModel answer
HardModel answerSystem Designdistributed-systemsevent-drivenconflict-resolution

Last updated

Design a system that keeps records in sync across a central platform and multiple third-party SaaS integrations, handling conflicts, retries, and rate limits reliably.

Scenario

You are building the backend for a work-management platform that integrates with external SaaS tools like project trackers, CRMs, and code repositories. Users interact with records inside your platform, but those same records are mirrored in one or more external tools. Changes can happen on either side at any time.

Your job is to design the sync engine that keeps everything consistent.

Functional Requirements

  • Two-way propagation. A change made inside your platform should appear in the connected external tool, and a change made in the external tool should appear in your platform.
  • Conflict handling. When the same record is modified on both sides before either change has synced, the system must detect and resolve the conflict without silently dropping data.
  • Idempotent operations. Network failures will cause retries. A retried operation must not create duplicates or apply the same change twice.
  • Scale. Support tens of thousands of active connections, each potentially receiving bursts of thousands of changes in a short window.

Non-Functional Requirements

  • No updates should be lost during partial outages or provider downtime.
  • Propagation latency should be sub-second where the external API supports webhooks and has rate-limit headroom.
  • OAuth tokens and other credentials must be stored and accessed securely.

What to Cover

  1. A component-level architecture for both the outbound path (platform → external) and the inbound path (external → platform).
  2. How you detect and prevent sync loops, where a change bounces back and forth indefinitely between the two sides.
  3. Your conflict detection and resolution strategy, with trade-offs between approaches.
  4. How you guarantee idempotency on creates and updates in both directions.
  5. How you handle rate limits imposed by external APIs, including bursts from bulk operations.
  6. A data model that tracks sync state, pending operations, and conflicts.

Hints

Hint 1

The external API is the weakest link. Webhooks can be delayed, duplicated, or missing entirely — design the inbound path assuming the webhook payload alone is not trustworthy. Re-fetching the current remote state before processing is safer than trusting the payload.

Hint 2

Whole-record last-write-wins is easy to implement but silently drops data when two fields are edited concurrently on different sides. Think about whether you can do a per-field merge against a stored base snapshot instead.

Hint 3

A sync loop is easy to miss during design. Trace the full round-trip: platform write → push to external → external fires webhook → inbound worker → platform write → outbox event → push again. Identify exactly where you break the cycle and make it reliable under retries.