# How do event-driven data replication patterns streamline data warehousing and analytical data lake synchronization?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Data Warehousing, CDC Replication

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-event-driven-data-replication-patterns-streamline-data-warehousing-and-analytical-data-lake

## Answer

**Basics:** Traditional replication runs scheduled bulk queries and compares timestamps, which is slow and consumes API calls. With CDC, Salesforce publishes a change event whenever selected objects are created, updated, deleted or undeleted. A subscriber applies those changes to a warehouse such as Snowflake, BigQuery or a lake.

**How it works:**
1. Select objects in Setup > Change Data Capture. The number of entities included free is limited (verify, extra entities need an add-on).
2. Do an initial full load with Bulk API (use PK chunking for big tables).
3. Subscribe to `/data/AccountChangeEvent` through Pub/Sub API (or CometD).
4. Each event carries `ChangeEventHeader` with `changeType`, `changedFields`, `recordIds`, `commitTimestamp`, `transactionKey` and `sequenceNumber`.
5. A consumer writes events to a stream such as Kafka and merges them into target tables, storing the last replay ID.
6. On `GAP_*` or `GAP_OVERFLOW` events, or if the replay ID has expired, resync the affected records.

**Advanced / deep dive:** Retention is about 72 hours, so a consumer outage longer than that needs a full or incremental reload. Events are field-level for updates, so apply them as upserts keyed on the Salesforce ID. Handle deletes as tombstones or soft deletes in the warehouse. CDC delivers committed changes, honours field-level security of the subscriber, and does not include formulas. Alternatives include Salesforce Data Cloud (rebranded Data 360 in recent releases, verify) zero-copy sharing with Snowflake or BigQuery, Heroku Connect, and ETL tools using Bulk API 2.0 queries. Pick CDC when freshness matters more than simplicity.

**Code / config example:**
```text
changeType: UPDATE
entityName: Account
recordIds: [001xx000003DGb2AAG]
changedFields: [Name, Industry]   -- only these appear in the payload
commitTimestamp: 1730000000000, transactionKey: ..., sequenceNumber: 1
```

**Hidden gotchas & must-remember points:**
- Retention is 72 hours, so keep the replay ID and plan a backfill.
- Initial data is not in the event stream. You must bulk load first.
- Gap events mean data was missed and needs a refresh.
- Entity limits and delivery allocations apply (verify for your edition).
- Formula fields and some compound fields behave differently.
- A single transaction can produce several events, so use `transactionKey` for ordering.

**Best practice:** Combine an initial bulk load, CDC streaming, idempotent upserts and a scheduled reconciliation check.

---
Source: ForceChallenges · last updated 2026-11-02
