The previous lessons have defined who is accountable for the data, how it is documented, how its quality is measured and how it is protected. But DataCorp's platform is still empty: the data sits in five systems that have nothing in common. A relational database, an ERP that exports files every night, a marketing tool with an API, an application that emits two million events a day and a support tool. Each with its own technology, its own format, its own pace and its own way of naming things.

Data integration is the discipline concerned with bringing together data from heterogeneous sources to offer a consistent, usable view. In this lesson we will study it as an architecture decision: which integration styles exist and when each one is appropriate, which differences of schema and meaning have to be bridged, how to bring in only what has changed, and what properties a load must have to be reliable. We will finish with the integration map of DataCorp's five sources.

A note on scope: here we decide which pattern applies to each source and why. How to build the processes that carry it out (ETL and ELT, tools, orchestration) is the subject of Module 4.

The integration problem

Integrating would be trivial if all the sources shared technology, model and vocabulary. They do not, and the differences show up on four levels:

Level Difference At DataCorp
Technical How the data is accessed SQL, files over SFTP, HTTP API, event stream
Syntactic Format and encoding Tables, CSV with ;, nested JSON, free text
Structural How the data is organized An order is two tables in PostgreSQL; an event is a single JSON document
Semantic What it means The store's "product 3301" is the ERP's "ASP-0042"; the "date" is local time in one system and UTC in another

On top of that comes time: some sources change every second and others once a day, and the freshness requirements (RQ-04) are not the same for all of them.

Without a strategy, each need is solved with a direct connection between two systems, and with n systems you end up with as many as n × (n − 1) connections, each with its own logic. That is DataCorp's starting point: scattered scripts and two reporting tools connected to production. The alternative is to bring the data to a common point, the platform, by means of a few well-chosen patterns.

Integration styles and patterns

There are six basic ways of moving or bringing together data. The first three are styles of analytical integration; the last three describe the mechanism of exchange with the source.

Physical batch consolidation

The data is copied periodically from the sources to a common store, where it is kept and transformed. It is the classic data warehouse pattern: once a day (or every hour) whatever is new is extracted and loaded.

  • Pros: simple, robust, preserves history, puts no load on the sources during queries.
  • Cons: the data is as old as the last batch.

Replication and change data capture (CDC)

Replication keeps a synchronized copy of a database. Change data capture (CDC) is its finest-grained form: instead of querying the tables, it reads the database's transaction log, where the database records every insert, update and delete, and transmits those changes to the destination almost instantly.

  • Pros: freshness of seconds; it captures all the changes, including deletes and intermediate states; it puts hardly any load on the source.
  • Cons: more pieces to deploy and operate; it requires special permissions on the source database; schema changes have to be managed.

Data federation or virtualization

The data is not copied: an intermediate layer offers a unified view and, when a query arrives, translates it and distributes it among the sources at that moment.

  • Pros: data that is always current; nothing to store or synchronize; useful for exploring.
  • Cons: every analytical query hits the operational systems; performance is that of the slowest source; there is no history; if a source goes down, the query fails.

API integration

The source exposes a programming interface (usually HTTP with JSON) and the integrator asks it for the data. It is the normal way of obtaining data from cloud applications.

  • Pros: a stable, documented interface; the source controls what it exposes.
  • Cons: request limits, pagination, and sometimes the data arrives summarized or without history.

Messaging and events

The source publishes each fact as a message in an intermediate system (a queue or an event log), and the interested parties subscribe. The sender does not know who consumes.

  • Pros: it decouples producer and consumers; it supports high volumes and continuous delivery.
  • Cons: duplicates, out-of-order messages and the evolution of the message format have to be managed; it is one more piece of infrastructure.

File transfer

The source drops a file (CSV, JSON) in an agreed location and the destination picks it up. It is the oldest mechanism and is still the most widespread with legacy systems.

  • Pros: universal; it requires no access to the source system.
  • Cons: no schema guarantees; silent failures (a file that does not arrive, arrives empty or arrives twice).

Comparison

Pattern Does it copy the data? Typical freshness Load on the source Operational complexity Preserves history
Batch consolidation Yes Hours to a day Low, concentrated in the extraction Low Yes
Replication / CDC Yes Seconds to minutes Very low Medium-high Yes, every change
Federation / virtualization No Immediate High, on every query Medium No
API Yes Depends on how often it is polled Low, limited by the API Low-medium Depends on the API
Messaging / events Yes Seconds Very low Medium-high Yes, if the events are stored
File transfer Yes That of the delivery (normally daily) None Low Yes

How to choose the pattern

No pattern is the best; each source calls for its own. The choice comes from answering five questions, in this order:

  1. What freshness does the use case require? This is the decisive question. If yesterday's data is enough, a daily batch is the answer, however attractive a streaming technology may be.
  2. What does the source offer? You do not choose in the abstract: an ERP that only exports CSV does not support CDC.
  3. How much load can the source system tolerate? DataCorp's requirement RQ-07 (zero analytical queries against production) rules out federation over the transactional database from the outset.
  4. Do all the changes have to be captured or is the final state enough? If every intermediate state of an order matters, CDC is needed; if it is enough to know how it stands today, it is not.
  5. Who is going to operate it? Every streaming pattern adds components to watch over. With a team of two people (RQ-13), complexity is a first-order cost.

The rule of thumb: start with the simplest pattern that meets the required freshness and step up in complexity only where a requirement demands it.

Schema and semantic heterogeneity

Once the mechanism has been chosen, the underlying work remains: making data born in different systems combinable. The differences are documented in a mapping: the field-by-field correspondence between the source and the target.

Take the ERP inventory file. It arrives like this:

SKU;WAREHOUSE;STOCK;DATE
ASP-0042;WH01;118;17/11/2026
REC-0107;WH01;1.250;17/11/2026

Its mapping to the cleansed zone:

Source field Target field Transformation
SKU erp_sku Copy; it is also translated into product_id by means of a crosswalk table (lesson 03-06)
WAREHOUSE warehouse_id WH01 → 1
STOCK units (integer) Remove the period used as thousands separator: 1.250 → 1250
DATE inventory_date (date type) From DD/MM/YYYY to an ISO date: 17/11/2026 → 2026-11-17

This small example contains almost every usual type of discrepancy:

Discrepancy Example at DataCorp Risk if ignored
Names SKU / product_id; STOCK / units Fields that are not recognized as equivalent
Types and formats 1.250 with a period as thousands separator; decimal comma in the ERP's amounts 1,250 units read as 1.25
Dates 17/11/2026 versus 2026-11-17 03/10/2026 interpreted as March 10
Time zones orders.order_date is in Spanish mainland time, without saying so; the clickstream is in UTC Events and orders offset by one or two hours
Character encoding The ERP exports in ISO-8859-1; the rest use UTF-8 "Logroño" turned into "Logroño"
Identifiers The store identifies the product by product_id, the ERP by SKU; marketing identifies the customer by their email Impossible to join sales with inventory
Coded values delivered in the store; a numeric code in another system Statuses that cannot be compared
Granularity Orders line by line; campaigns summarized by day Joins that duplicate or lose amounts
Meaning "Amount" including VAT in the store and excluding VAT in accounting Incomparable figures under the same name

Time zones deserve an example, because their effect is subtle. A clickstream event with the timestamp 2026-10-31T23:30:00Z (UTC) took place, in Spanish mainland time, at 00:30 on November 1. If it is compared without conversion with the orders, which are in local time, that event will be assigned to October and the order it led to, to November. DataCorp's rule will be to store every timestamp in UTC and to calculate the business date in the Europe/Madrid time zone, which is the one used by the glossary definitions ("by order date").

The differences in the table range from easy to hard. Those of format are solved with a conversion; those of identifiers and meaning require agreements between people, and are the territory of governance (lesson 03-01) and master data (lesson 03-06).

Full load, incremental load and watermark

Every time you extract from a source there are two options:

Full load Incremental load
What it brings All the data, every time Only what is new or modified since the last extraction
Advantages Trivial; always consistent with the source; detects deletes Fast and light; it scales with the change, not with the size
Drawbacks Cost proportional to the total size It needs to know what has changed; it can miss changes
Suitable for Small tables or tables with no way of detecting changes Large tables that grow

At DataCorp, customers (200,000 rows) and products (15,000) are small: a daily full load takes seconds and avoids complications. orders and order_lines grow by 1,500 and 3,750 rows a day on top of millions accumulated: there the incremental load is a must, as ADR-001 already anticipated.

The watermark

The most common incremental technique relies on a watermark: the highest value already extracted from a column that grows over time. On each run you ask for whatever exceeds the previous watermark and, on finishing, you store the new one.

-- Control table: one row per entity, with the point up to which it was extracted
-- control.watermarks(source_system, entity, last_watermark, run_date)

-- Extraction of November 18 at 01:15, against the read replica.
-- :previous_watermark = '2026-11-17 00:00:00' (read from control.watermarks)
-- :new_watermark      = '2026-11-18 00:00:00' (start of the current day)
SELECT order_id, customer_id, order_date, status, total_amount
FROM orders
WHERE order_date >= :previous_watermark
  AND order_date <  :new_watermark;
  • :previous_watermark and :new_watermark are parameters that the process replaces with values on each run.
  • The interval is closed at the bottom and open at the top (>= and <): each order falls into exactly one run, with no gaps or overlaps.
  • The upper watermark is a fixed instant already in the past (00:00), not "now": that way the result is the same even if the query is repeated.
  • Only when the load finishes successfully is control.watermarks updated with the new watermark. If it fails, the watermark does not move and the next run retries it.

The limits of the watermark

The query above has a serious flaw for DataCorp: order_date only detects new orders. An order from November 3 that is returned on the 17th changes status without changing date, and the extraction does not bring it in again. The platform would keep counting it as net sales forever.

Limit What happens Remedy
Updates A creation column does not reflect later changes Use a last-modified column that the source updates on every change
Deletes A deleted row does not appear in any query Soft delete at the source (flagging instead of deleting), periodic comparison with a full load, or CDC
Late arrivals A transaction committed after the extraction, with a watermark earlier than it, is lost Overlap the intervals slightly and remove duplicates afterwards
Unreliable column The watermark is filled in by the application and some process forgets it Have the database itself maintain it; verify with counts

DataCorp adopts two measures:

  1. Definitive solution. The development team will add to orders an updated_at column, maintained by the database on every modification, through an expand-and-contract migration (lesson 02-04). The extraction will switch to filtering on it, with a 10-minute overlap:
SELECT order_id, customer_id, order_date, status, total_amount,
       updated_at
FROM orders
WHERE updated_at >= :previous_watermark - INTERVAL '10 minutes'
  AND updated_at <  :new_watermark;
  1. Interim solution. As long as the column does not exist, every night the orders from the last 60 days are extracted again by order_date. Since returns are accepted up to 30 days after delivery, that window covers practically all status changes. That is about 90,000 orders a night: a negligible volume.

Both solutions deliberately bring in rows that had already been brought in. That is only acceptable if the load is prepared for it, which leads us to the next property.

Idempotency

An operation is idempotent if running it several times produces the same result as running it once. It is the most important property of a data load, because loads get repeated: because of a failure halfway through, an automatic retry, a reprocessing after fixing an error or the overlaps we have just introduced.

A load that simply appends rows is not idempotent: repeated, it duplicates the sales. There are three techniques for achieving idempotency:

Technique How it works Where DataCorp uses it
Overwrite the partition Each run writes to a path determined by its parameters and replaces whatever was there Raw zone: the load of the 18th always writes to load_date=2026-11-18/
Insert or update by key If the key already exists, it is updated; if not, it is inserted Tables in the consumption zone (detailed in Module 4)
Remove duplicates on read Repeated copies are allowed and one is selected per key Step from raw to cleansed

The third technique resolves the overlaps of the incremental extraction. Of all the copies of the same order in the raw zone, the most recent one is taken:

SELECT order_id, customer_id, order_date, status, total_amount
FROM (
    SELECT o.*,
           ROW_NUMBER() OVER (
               PARTITION BY order_id               -- one group per order
               ORDER BY load_date DESC             -- the most recent copy first
           ) AS row_num
    FROM raw.orders o
) copies
WHERE row_num = 1;

ROW_NUMBER() numbers the rows within each group. PARTITION BY order_id forms one group per order and ORDER BY load_date DESC puts the most recently loaded copy first; keeping row_num = 1 returns one row per order, with its last known status. Running this query once or twenty times gives the same result: it is idempotent.

This combination (storing in the raw zone everything that arrives and deriving the current state when cleansing) is also what makes reprocessing possible, and it is one of the reasons behind ADR-002.

The canonical model

If every data consumer had to understand the format of every source, as many translations would be needed as there are source-consumer pairs. A canonical model is a common representation, independent of any system, into which each source is translated only once. With 5 sources and 6 use cases, you go from up to 30 translations to 5 + 6.

In DataCorp's architecture, the canonical model is that of the cleansed zone: there each entity has a single form, whatever its origin. Its conventions complete the naming policy POL-02:

Aspect Canonical convention
Timestamps Timestamp type, in UTC
Business date Calculated in the Europe/Madrid time zone
Dates Date type (ISO format YYYY-MM-DD when displayed)
Amounts Exact decimal, in euros; the name indicates whether it includes VAT (gross_amount, net_amount)
Text UTF-8 encoding, with no surplus spaces
Coded values Those of the reference tables (ref_), in lowercase
Customer identifier The store's customer_id
Product identifier The store's product_id; the ERP SKU is kept as an attribute
Origin Every row keeps load_date and the system it comes from

Two warnings prevent the frequent abuses of the concept. The canonical model is not designed in one go for the whole company: it grows entity by entity, as the use cases need it. And it does not replace the dimensional model: the canonical model (cleansed zone) integrates and normalizes; the dimensional model from lesson 02-05 (consumption zone) is built on top of it for analysis.

DataCorp's integration map and ADR-007

With the criteria above and the freshness requirements of RQ-04, Marta and Íñigo assign a pattern to each source:

Source and entity Pattern Frequency Destination in the raw zone
PostgreSQL: orders, order_lines Batch consolidation, incremental by watermark, from the read replica Daily, 01:15 postgres/orders/, postgres/order_lines/
PostgreSQL: customers, products Batch consolidation, full load, from the replica Daily, 01:15 postgres/customers/ (14 days in the raw zone, ADR-006), postgres/products/
Support: tickets The support tool's API, incremental by modification date Daily, 02:00 support/tickets/
ERP: daily inventory snapshot File transfer (CSV over SFTP) Daily, 03:00 erp/inventory/
Marketing: campaigns File transfer (CSV with the definition of the campaigns) and API (JSON with the daily results) Daily, 04:00 marketing/campaigns/, marketing/campaign_results/
ERP: current stock The ERP's API, polled periodically Every 10 minutes erp/stock/, with hour=HH/
Clickstream: events Messaging: the website and the app send events to a collector, which groups them into files Files every 15 minutes clickstream/events/, with hour=HH/

All the paths follow the ADR-004 convention (<source>/<entity>/load_date=YYYY-MM-DD/).

graph LR
    subgraph "Sources"
        PG["PostgreSQL<br/>(read replica)"]
        SOP["Support<br/>tool"]
        ERP["Warehouse ERP"]
        MK["Marketing"]
        WEB["Website and app"]
    end
    subgraph "Raw zone (datacorp-data-raw)"
        B1["postgres/"]
        B2["support/"]
        B3["erp/"]
        B4["marketing/"]
        B5["clickstream/"]
    end
    PG -->|"batch: incremental and full<br/>daily 01:15"| B1
    SOP -->|"API, daily 02:00"| B2
    ERP -->|"CSV file, daily 03:00"| B3
    ERP -->|"API, every 10 min"| B3
    MK -->|"CSV file + API<br/>daily 04:00"| B4
    WEB -->|"events, files<br/>every 15 min"| B5
    B1 --> DEP["Cleansed zone<br/>(canonical model)"]
    B2 --> DEP
    B3 --> DEP
    B4 --> DEP
    B5 --> DEP
    DEP --> CON["Consumption zone"]

The decisions that are not obvious:

  • Orders in batches and not by CDC. The required freshness is daily (D+1 before 07:00). CDC would give seconds that nobody has asked for, in exchange for more components to operate. It remains a possible evolution if some use case comes to need it.
  • Inventory needs two flows. The ERP exports a nightly snapshot, but the stockout alert (UC-03) requires a maximum age of 15 minutes. The daily snapshot feeds the history (fact_daily_inventory); the API call every 10 minutes, the alert. This second flow assumes that the ERP offers an API for querying stock levels: it is an assumption to be confirmed with its vendor. If it did not exist, more frequent exports or a direct read of its database would have to be negotiated.
  • Clickstream in micro-batches. The events travel by messaging, but they are delivered to the platform grouped into files every 15 minutes, enough for the required freshness of 1 hour. Stream processing proper is studied in lesson 04-03.
  • No federation. RQ-07 forbids analytical queries against production.

With the nightly extractions finished before 04:30, two and a half hours remain to cleanse, validate and publish before 07:00.

ADR-007: Integration patterns by source
Status: accepted            Date: 2026-11-26

CONTEXT
Five heterogeneous sources, with different required freshness (RQ-04),
a ban on analytical queries against production (RQ-07) and a team of
two people (RQ-13).

DECISION
1. Default pattern: physical consolidation in daily batches into the raw
   zone. Used for PostgreSQL, tickets, inventory snapshot and campaigns.
2. PostgreSQL: orders and lines, incremental by watermark; customers and
   products, full load. Always against the read replica.
3. Development will be asked for the orders.updated_at column. Until it
   exists, the orders from the last 60 days are re-extracted every night.
4. Stock levels: call to the ERP's API every 10 minutes (to be confirmed).
5. Clickstream: events by messaging, delivered in files every 15 min.
6. All loads are idempotent: they overwrite their load_date partition,
   and duplicates are removed on the way into the cleansed zone.
7. The cleansed zone is the canonical model: timestamps in UTC, business
   date in Europe/Madrid, UTF-8 and the store's identifiers.

ALTERNATIVES CONSIDERED
A. CDC on PostgreSQL. Deferred: freshness not required; more operation.
B. Query federation over the sources. Rejected: it breaches RQ-07.
C. Daily full load of orders. Rejected: it grows without limit.

CONSEQUENCES
Positive: few, simple patterns; each source with the required freshness.
Negative: two different flows for inventory; physical deletes of orders are
not detected (accepted: the store does not delete orders, it cancels them).
Follow-up work: confirm the ERP's API; data contract per source.

Common Mistakes and Tips

  • Choosing the pattern for the technology. "Real time" sounds better than "daily batch", but it costs far more. Always start from the freshness requirement.
  • Extracting from the primary database. Use the read replica: a heavy extraction can degrade the store.
  • Using "now" as the upper bound of the extraction. The result changes on every run and retries leave gaps or duplicates. Use fixed bounds.
  • A watermark on a creation column. It does not detect updates. It is the most frequent mistake in incremental loads.
  • Moving the watermark before confirming the load. If the process fails afterwards, that interval is lost forever.
  • Append-only loads. Sooner or later they will be repeated. Design each load so that it can be run twice without consequences.
  • Ignoring the time zone. A timestamp without a zone is an ambiguity waiting to cause an error. Record it in the mapping and convert to UTC.
  • Transforming during extraction. The more the data is manipulated before being stored in the raw zone, the less it can be reprocessed. Extract as is and transform afterwards.
  • Tip: document the mapping of each source next to its data contract (lesson 03-02). It is the first thing people look at when a figure does not match.
  • Tip: for each source, ask yourself what happens if the delivery does not arrive, arrives twice or arrives half-finished. The ingestion checks from lesson 03-03 exist for those three cases.

Exercises

Exercise 1: Choosing the pattern

State which integration pattern you would propose in each case and why:

  1. A logistics provider sends a file every morning with the status of the previous day's deliveries.
  2. The aim is to detect possible fraud at the moment an order is paid.
  3. Laura needs, just once, to join the sales with a table of 300 postal codes that another department maintains in its own database.
  4. A cloud advertising platform is brought in, which reports the daily spend per campaign.

Exercise 2: Following a watermark

The orders extraction uses order_date as its watermark and runs every day at 01:15 with the whole previous day as its interval. State whether the platform correctly reflects each situation and, if not, how it would be fixed:

  1. Order created on November 16 at 23:58.
  2. Order created on November 10 and cancelled on the 16th.
  3. Order created on November 16 and deleted by an administrator on the 17th.
  4. The extraction of the 17th fails and is relaunched manually at 09:00.

Exercise 3: Mapping and time zone

A clickstream event has "event_time": "2026-07-14T22:45:00Z" and corresponds to a purchase. In summer, Spanish mainland time is two hours ahead of UTC. Which business date does it correspond to? What problem would grouping the events by the UTC date cause when comparing them with the orders?

Solutions

Exercise 1

  1. File transfer, with a daily batch load. It is what the source offers and the freshness is sufficient. Arrival and volume checks have to be added.
  2. Messaging and events (or CDC): a reaction within seconds is needed. It is an operational case rather than an analytical one, and it would justify a streaming infrastructure that DataCorp does not need today.
  3. Federation, or a simple one-off export. For a single query on a tiny table it is not worth building a load. If the join became routine, the table should be brought into the platform as reference data.
  4. API, polled once a day, with a batch load. The daily freshness matches that of the rest of the campaign data.

Exercise 2

  1. Correct. It falls in the interval [Nov 16 00:00, Nov 17 00:00) and is extracted on the 17th at 01:15. It would only fail if the transaction were committed after the extraction, which is unlikely with more than an hour's margin.
  2. Incorrect. It was extracted on the 11th with whatever status it had then and the cancellation never arrives: order_date does not change. It is fixed with the updated_at column or, as an interim measure, with the 60-day window.
  3. Incorrect. The platform keeps an order that no longer exists at the source. The watermark does not see physical deletes. Remedies: have the store cancel instead of deleting (which is its usual practice), a periodic comparison of identifiers, or CDC.
  4. Correct, if the load is well designed. Since the upper bound is fixed (00:00 on the 17th) and not "now", the relaunch brings in exactly the same orders; since the load overwrites its load_date partition, it duplicates nothing; and since the watermark did not move when it failed, there is no gap. This is idempotency in action.

Exercise 3

22:45 UTC on July 14 is 00:45 on July 15 in Spanish mainland time. The business date is July 15.

If the events were grouped by the UTC date, the purchase would appear on the 14th in the clickstream and on the 15th in orders (which is in local time). In the conversion funnel (UC-04), all the purchases between 00:00 and 02:00 would appear one day earlier in the events than in the orders: the daily totals would never match, even though the monthly ones almost would, which is precisely what makes this error hard to detect.

Tip: always store the timestamp in UTC (it loses no information) and derive the business date as a separate column.

Conclusion

Data integration brings together sources that differ in technology, format, structure and meaning. There are six basic patterns (batch consolidation, replication and CDC, federation, API, messaging and file transfer), and the choice depends above all on the required freshness, on what the source offers and on the complexity the team can operate. Bridging heterogeneity requires an explicit mapping of fields, types, time zones, encodings and identifiers to a canonical model, which at DataCorp is the cleansed zone. Large tables are loaded incrementally with a watermark, whose limits (updates, deletes and late arrivals) make it necessary to rely on a last-modified column and on idempotent loads. ADR-007 assigns a pattern to each of the five sources, with daily batches as the norm and more frequent flows only for stock levels and the clickstream. Building the processes that will carry it out is left for Module 4.

The mapping has exposed the hardest problem of integration, which no format conversion solves: the store's product 3301 is the ERP's ASP-0042, and the same customer may appear twice with different email addresses. Before building any process, we have to decide how to recognize that two records are the same entity and which of its versions is the right one. That is the subject of the last lesson of the module, devoted to master and reference data.

© Copyright 2026. All rights reserved