Real-Time ETL Architecture Design and End-to-End Implementation Guide

    This article explains how to design a real-time ETL pipeline by breaking it into four layers: data source ingestion, change capture and transport, stream computation, and storage and serving. It covers where end-to-end latency comes from, how to handle windowing, late data, state, delivery semantics, and idempotent writes, and how real-time and batch pipelines should share metric definitions. A practical checklist for observability, capacity planning, schema design, recovery drills, and governance is included.

    1. Define the Problem First: What ETL Really Is and Where Latency Comes From

    ETL stands for Extract, Transform, Load. At its core, it moves data from where it is produced to where it is consumed, while unifying structure and correcting semantics along the way. Many teams treat it as a tooling problem, but it is first an architecture problem: the shape in which data is produced, how fast it changes, and how much latency downstream consumers can tolerate. These three factors determine the shape of the pipeline.

    Traditional pipelines are mostly batch: a scheduled job runs periodically, extracts the previous period’s data during off-peak hours, transforms it, and writes it into analytical storage. The advantages are simple implementation, predictable resource usage, and clear failure recovery boundaries. The drawback is equally obvious: data is inherently one scheduling cycle behind. When the business needs to see what just happened, batch processing cannot deliver.

    So the goal of real-time ETL can be stated in one sentence: compress end-to-end latency from data production to queryability down to seconds or less. One engineering habit matters here: avoid saying “real time” in a vague way. Break latency into segments instead, typically including commit-to-log visibility, capture into a message queue, queue waiting, computation windows, and write plus index refresh. Only by measuring each segment can you tell whether the bottleneck is in collection, buffering, or computation.

    2. Layered End-to-End View: Breaking Down the Four Layers

    Layer 1: Data Source Ingestion

    Common sources include business relational databases, application logs, messaging systems, third-party APIs, and time-series data reported by devices. This layer usually requires no changes to the business, but three things must be understood: whether data is structured or semi-structured, the change frequency and peak multiplier, and whether batch writes and long transactions exist. Long transactions cause log buildup, and the peak multiplier drives downstream capacity planning.

    Layer 2: Capture and Transport

    The mainstream approach to obtaining change data in real time is change data capture (CDC), which tails the database commit log and converts inserts, updates, and deletes into an ordered event stream. This approach is non-intrusive to business code and is a common industry solution. Alongside it is log collection, where a lightweight agent tracks file changes and ships them upstream. Both often coexist: the former carries structured business changes, the latter carries behavioral and operational logs.

    Either way, a high-throughput message queue is needed as a buffer. Its value is not just moving data, but more importantly decoupling and peak shaving: upstream writes at its own pace, downstream consumes at its own capacity, consumer offsets record progress, and data can be replayed after a failure.

    A schematic data flow:

    1. Business DB / logs / APIs / devices
    2. ↓ CDC or log agent
    3. Message queue (partitioned, ordered, replayable)
    4. ↓
    5. Stream computation (cleanse / join / aggregate)
    6. ↓
    7. Analytical store / search store / time-series store

    Layer 3: Computation and Transformation

    This is the core of a real-time pipeline. Once data leaves the queue it must be parsed, schema-aligned, filtered for dirty records, enriched with dimensions, deduplicated, and aggregated. The biggest difference from batch is that data is an unbounded stream, so windows and trigger strategies must be defined explicitly: tumbling windows for minute-level metrics, sliding windows for trend calculations, and session windows for behavioral sequence analysis.

    Out-of-order and late data must also be handled. In practice, a configurable lateness tolerance is usually allowed, and data beyond it goes to a side output stream for separate compensation rather than being dropped outright. State management must be designed up front: operators that correlate across events hold state, and the state backend should support incremental checkpoints so recovery can resume from the most recent offset.

    A simplified pseudocode sketch of the “filter, enrich, window aggregate, write out” structure:

    1. events = stream.from_topic("biz_change") \
    2. .filter(lambda e: e.op in ("insert", "update")) \
    3. .map(parse_and_align_schema) \
    4. .enrich_from(dim_lookup) \
    5. .key_by("order_id")
    6. metrics = events.window(tumbling(minutes=1)) \
    7. .aggregate(count(), sum("amount")) \
    8. .with_lateness(seconds=30, side_output="late")
    9. metrics.sink_to("olap_store", idempotent=True)

    Layer 4: Storage and Serving

    Choose storage by query pattern, not by “popularity”: columnar analytical databases suit aggregation-heavy analysis, distributed search engines suit detail retrieval, time-series databases suit metrics monitoring, and raw events should be archived to object storage for replay and recomputation. Tiered storage matters because it aligns cost structure with access patterns: cold data sinks down while hot data stays in the low-latency layer.

    3. Consistency, Idempotency, and Fault Tolerance

    What breaks first in a real-time pipeline is usually semantics, not performance. Three points must be settled:

    • Delivery semantics: decide whether the target is at-least-once or exactly-once. Most businesses can accept at-least-once, provided downstream writes are idempotent.
    • Idempotent writes: use a business primary key, or “primary key plus version number,” for upserts to avoid duplicate accumulation on replay.
    • Ordering and out-of-order data: assign windows by event time rather than processing time, and keep an event-time watermark so early-arriving data is not misjudged.
    1. -- Generic form of an idempotent upsert
    2. INSERT INTO fact_order_min (order_id, win_start, amount)
    3. VALUES (...)
    4. ON CONFLICT (order_id, win_start) DO UPDATE
    5. SET amount = EXCLUDED.amount;

    4. Dividing Work with Traditional Batch Processing

    Real time does not mean full replacement. The stable approach is dual pipelines working together: the real-time pipeline handles minute-level metrics and alerting, while the batch pipeline handles full corrections and complex backfills. Both share the same metric definitions and dimension definitions, avoiding a situation where real time reports one number and offline reports another. When unifying definitions is too costly, build a unified metric definition layer first, then optimize the pipelines.

    5. Implementation Checklist

    1. Observable latency per segment: every hop has timestamps and latency metrics, with threshold-based alerts configured.
    2. Capacity designed for peak: partition counts and parallelism are set from peak throughput, with headroom for backpressure.
    3. Schema first: define the event schema and version evolution strategy before writing collection logic.
    4. Rehearse recovery: periodically validate replay from checkpoints and archived data.
    5. Cost and governance: build cold/hot tiering, retention periods, data lineage, and access auditing alongside the pipeline.

    On the cloud, these capabilities are typically covered by general categories such as message queues, stream computation, object storage, log services, and monitoring and alerting. Platforms like Baidu AI Cloud offer this same kind of general capability组合 in combination, so selection should focus on latency metrics, elastic scaling, and observability. Overall, the success of real-time ETL depends on whether the layers are clearly separated, whether semantics are rigorous, and whether operations are observable, not on the “performance myth” of any single component.