- Define event meaning and ownership before choosing infrastructure.
- Treat delivery guarantees as an end-to-end property, including the sink.
- Test replay, late events and reconciliation before trusting reports.
For data engineers building operational and analytical pipelines.
A dashboard can refresh every few seconds and still report the wrong revenue. Duplicated events, late refunds and incompatible schemas are often more damaging than a slightly slower pipeline. The design needs to explain what happens to a business fact from its first commit to its final query.
This guide follows an illustrative order-event pipeline: an operational system emits changes, Kafka retains them, Flink transforms them and a lakehouse stores queryable tables. The tools are useful only when event contracts, recovery behaviour and data ownership are equally clear.
1. Define the business event and its contract
Decide whether an event records a fact, a command or a snapshot. An “order paid” fact should identify the order, account, currency, event time and a stable event ID. It should not quietly change meaning when a new producer is deployed. Assign an owner who can approve schema changes and explain the fields.
Include both the time the business action happened and the time the pipeline received it. Those values answer different questions when a device reconnects or a source backfills history. Store a schema version and document how consumers handle unknown fields, missing optional values and changes to enumerations.
For a transactional source, decide how committed changes reach the log. An outbox or supported change-data-capture path can avoid the gap between a database commit and a separate publish request. It still needs monitoring, retention planning and a procedure for restarting after a prolonged outage.
2. Partition Kafka around the ordering requirement
Choose the key according to the sequence that consumers must preserve. If order-state updates must be processed in order, an order ID is a plausible key. If one large tenant dominates traffic, a tenant-only key can create a hot partition. Estimate the distribution with representative data before increasing partition count.
Kafka’s delivery semantics distinguish producer, consumer and transactional behaviour. Do not interpret an idempotent producer as a guarantee that an external database can never receive a duplicate. The consumer and sink must participate in the required correctness model.
Record retention separately from business retention. The event log may need enough history to rebuild a consumer after a failure, while regulated records may require a different archive. Alert on lag in terms of the business freshness requirement, and check whether the consumer can catch up faster than new events arrive.
3. Handle event time, state and checkpoints in Flink
A stream processor must decide when an event-time window is sufficiently complete. Choose watermark and late-event behaviour based on observed delay, not a convenient round number. A late refund may need to update yesterday’s revenue rather than disappear from the report.
Flink checkpoints support recovery of processing state. End-to-end exactly-once outcomes also depend on source replay and sink behaviour. Verify the connector’s guarantees and configuration for the versions you deploy; a checkpoint indicator by itself does not prove correctness at the destination.
Exercise a restart while a window contains data and a sink write is pending. Check resulting totals and duplicate IDs after recovery. Size state storage and checkpoint intervals using realistic load. A pipeline that passes a small demo may accumulate state or spend too long checkpointing when key cardinality increases.
4. Build lakehouse tables for corrections and evolution
Keep a recoverable raw layer and a curated layer with explicit transformation rules. The raw layer helps investigate why a reported value changed. The curated layer should define its grain, such as one row per order or one row per order-state change, so joins do not accidentally multiply revenue.
Table formats such as Apache Iceberg support schema and partition evolution. That capability does not remove the need to test old readers, downstream queries and backfills. A renamed business concept may require a transformation even when the physical schema change is valid.
Plan maintenance alongside ingestion: small-file compaction, snapshot retention and deletion policies affect query speed and recoverability. Separate a backfill from the live write path until its outputs are reconciled. Publishing a large historical rewrite directly into a live reporting table makes it harder to identify the cause of a discrepancy.
5. Test failures with business-level reconciliation
Build fixtures for duplicate events, out-of-order updates, missing references, invalid currency and deleted records. Replay them through the same transformations used in production. Check business invariants as well as row counts: refunds must refer to valid orders, and totals must reconcile within the documented rounding rules.
| Failure | Expected behaviour | Evidence |
|---|---|---|
| Duplicate event ID | Apply the business change once | Stable totals after replay |
| Late refund | Correct the intended reporting period | Before/after reconciliation |
| Unknown schema | Quarantine or reject explicitly | Alert and recoverable payload |
| Worker restart | Resume without unexplained loss | Source-to-sink comparison |
Quarantined records need an owner and a replay path. A dead-letter queue that nobody reviews is delayed data loss. Include its age and volume in the operational view.
6. Release with freshness and recovery objectives
Define what readers need: for example, a proposed internal target might be that most paid orders appear in the operations view within a minute. Label that as a requirement to validate, not a measured result. Measure freshness from the source event to the queryable destination, including queueing and table commit time.
Release one source and one consumer first. Compare the new report with the existing report over a representative business period and investigate disagreements. Test rebuilding a table from retained events, then record the time and capacity required. Recovery that takes days may not meet the business objective even if no events are lost.
Publish an ownership map, schema-change procedure and reconciliation runbook. Connect alerts to actionable steps instead of paging on every lag fluctuation. Our SLO guide explains how to make the freshness objective operational.
Common questions
Does Kafka guarantee exactly-once writes to every database?
No. The guarantee depends on the entire path. Inspect the producer, processing framework, connector and destination transaction model, then verify the result through failure and replay tests.
Do we need a streaming pipeline for every report?
No. If the business can use hourly or daily data, a simpler batch pipeline may be easier to operate. Choose freshness from the decision the report supports.
What should a pipeline alert measure?
Measure end-to-end freshness, reconciliation failures, quarantine age and recovery capacity. Infrastructure metrics help diagnose these outcomes but should not replace them.
Sources & further reading
Primary documentation and research used for the technical context in this guide. Examples and checklists are illustrative; validate them against your system and the versions you deploy.
