Unit 07 · Chapter 1 · 14 min read

Risk data contracts and event time

Build features that mean the same thing in analysis and production.

The concept at a glance

Only use facts known at decision time

A fictional timeline has a decision cutoff at 10:00. Event A occurs at 09:10 and arrives at 09:20, so it is available. Event B occurs at 09:35 and arrives at 10:10, so it is excluded. The current payment is also excluded from a count of previous attempts.

Enlarge to read every label and explore the connections

A fact can occur before a decision and arrive after it. Reproducible features use event time and the time the system learned the fact.

  1. Preserve occurrence and receipt time separately.

  2. Exclude observations received after the decision.

  3. Retain feature definitions and source versions.

The model is excellent in the notebook. In production, a missing timestamp becomes midnight and a missing amount becomes zero. The model did not change. The meaning of its inputs did.

Define an event contract

Define an event contract — the flow
Define an event contract Define an event contract — the flow Follow the sequence. Use the documented contract. Produce Emit a versioned event Validate Check types units and required meaning Consume Use the documented contract
  1. ProduceEmit a versioned event
  2. ValidateCheck types units and required meaning
  3. ConsumeUse the documented contract
Follow the sequence. Use the documented contract. Chapter sources · Open image

An event contract gives fields stable meaning. Include event_id, entity references, event_type, occurred_at, received_at, schema_version, and explicit money units. A payment amount without a currency is incomplete. A timestamp without a documented time basis is difficult to compare.

Validate at ingestion and preserve rejected records in a controlled repair path. Do not silently coerce invalid amounts or unknown event types into safe defaults. Additive schema changes still need compatibility tests when downstream consumers assume a complete field set. The contract is shared by producers and consumers, not owned only by the data warehouse.

Inside the mechanism. A durable event contract includes event ID, business action ID, entity references, event type, schema version, event time, receipt time, amount, currency, and source. Distinguish a corrected event from a repeated delivery. Validate semantic rules such as currency and amount compatibility, not only JSON shape. Rejected records need an owned quarantine path and reconciliation so validation cannot silently remove transactions from the risk population.

A concrete example. A transaction event needs a stable identity, schema version, event time, and amount with a currency. A producer change can break consumers even when the message still parses. The case identifies 12,250 eligible records from a source population of 12,500. The required workflow completes for 11,882, but 178 completed records miss the illustrative internal target. Another 368 remain incomplete. Communication evidence covers 11,763 generated notices. Scope, completion, timeliness, and delivery are four separate properties of the customer outcome.

When the assumption fails. A new producer reuses an identifier and changes the meaning of a nullable field. Version the contract, validate semantics, and quarantine ambiguous records before they update state. The following worked sequence shows the reference condition, a stress condition, and a response condition with explicit synthetic data. These are comparative assumptions, not measured causal effects.

Follow a worked case3 conditions · 36 figures

A transaction event needs a stable identity, schema version, event time, and amount with a currency. A producer change can break consumers even when the message still parses.

Define an event contract — the distinction
Define an event contract Define an event contract — the distinction These concepts answer different questions. Read each definition in the context of the section. Occurred time When the underlying event happened Received time When this system learned about it
Occurred time
  • When the underlying event happened
Received time
  • When this system learned about it
These concepts answer different questions. Read each definition in the context of the section. Chapter sources · Open image
Event specimen
Define an event contract Event specimen Fictional teaching record. Consumer contract version. Event specimen Illustrative data; not a real customer record or a prescribed policy. amount_minor 12500 125.00 USD in this example currency USD Explicit unit schema_version 3 Consumer contract version Safe-looking defaults can distort risk
Fictional educational excerpt / Not for execution

Event specimen

Illustrative data; not a real customer record or a prescribed policy.

  1. amount_minor12500

    125.00 USD in this example

  2. currencyUSD

    Explicit unit

  3. schema_version3

    Consumer contract version

Safe-looking defaults can distort risk

Fictional teaching record. Consumer contract version. Chapter sources · Open image
Define an event contract — control and failure modes
Define an event contract Define an event contract — control and failure modes Safe-looking defaults can distort risk. The branches show why alternative designs fail. Control design Reject or repair invalid semantics explicitly. Safe-looking defaults can distort risk. Failure mode 1 Store money without currency. Amounts cannot be interpreted reliably. avoid Failure mode 2 Use one timestamp for every purpose. Observation and arrival differ. avoid Failure mode 3 Assume schema-valid means meaning-valid. Units and definitions still need checking. avoid
Control design

Reject or repair invalid semantics explicitly. Safe-looking defaults can distort risk.

Failure mode 1avoid
Store money without currency. Amounts cannot be interpreted reliably.
Failure mode 2avoid
Use one timestamp for every purpose. Observation and arrival differ.
Failure mode 3avoid
Assume schema-valid means meaning-valid. Units and definitions still need checking.
Safe-looking defaults can distort risk. The branches show why alternative designs fail. Chapter sources · Open image

Make time-aware features reproducible

Make time-aware features reproducible — the flow
Make time-aware features reproducible Make time-aware features reproducible — the flow Follow the sequence. Rebuild the feature at the original cutoff. Window Bound event time Knowledge Exclude records learned later Replay Rebuild the feature at the original cutoff
  1. WindowBound event time
  2. KnowledgeExclude records learned later
  3. ReplayRebuild the feature at the original cutoff
Follow the sequence. Rebuild the feature at the original cutoff. Chapter sources · Open image

A point-in-time feature uses only information available at the decision. Filter both event time and knowledge time when delayed data matters. An event that happened yesterday but arrived tomorrow was not available to today’s model.

For a one-hour count, exclude the current event and define whether the lower boundary is inclusive. The following teaching query counts earlier attempts known by the decision cutoff. Production code also needs the actual schema, indexes, deduplication, and transaction policy.

SELECT count(*)
FROM payment_events
WHERE account_id = :account_id
  AND occurred_at >= :decision_time - interval '1 hour'
  AND occurred_at < :decision_time
  AND received_at <= :decision_time;

Inside the mechanism. Point-in-time correctness uses both when a fact occurred and when it became available. For a decision at time t, the feature join must exclude observations received after t even if their event date is earlier. Preserve the transformation version and input snapshot. This prevents a late dispute or corrected customer profile from leaking into a historical model evaluation. Time zones and window endpoints need explicit conventions.

A concrete example. A feature must contain only information available at the decision time. A late dispute cannot become an earlier transaction feature merely because its transaction date is old. The rule flags 659 of 18,200 decision snapshots. Of those flags, 393 meet the synthetic target, giving 59.64% precision. It misses 98 target events. Under the stated cost assumptions, residual loss and operating friction total $24,546. The important result is the connection between the population, action, capacity, and outcome—not one isolated score.

When the assumption fails. A training join uses the latest customer state and leaks future outcomes. Join by both event time and availability time, then preserve the feature snapshot. The following worked sequence shows the reference condition, a stress condition, and a response condition with explicit synthetic data. These are comparative assumptions, not measured causal effects.

Follow a worked case3 conditions · 36 figures

A feature must contain only information available at the decision time. A late dispute cannot become an earlier transaction feature merely because its transaction date is old.

Make time-aware features reproducible — the distinction
Make time-aware features reproducible Make time-aware features reproducible — the distinction These concepts answer different questions. Read each definition in the context of the section. Historical event Happened before the decision Available evidence Was also known before the decision
Historical event
  • Happened before the decision
Available evidence
  • Was also known before the decision
These concepts answer different questions. Read each definition in the context of the section. Chapter sources · Open image
Late-arrival example
Make time-aware features reproducible Late-arrival example Fictional teaching record. Cannot use the event then. Late-arrival example Illustrative data; not a real customer record or a prescribed policy. Occurred 09:00 Earlier real event Received 11:00 Later system knowledge Decision 10:00 Cannot use the event then Late data can create hidden leakage
Fictional educational excerpt / Not for execution

Late-arrival example

Illustrative data; not a real customer record or a prescribed policy.

  1. Occurred09:00

    Earlier real event

  2. Received11:00

    Later system knowledge

  3. Decision10:00

    Cannot use the event then

Late data can create hidden leakage

Fictional teaching record. Cannot use the event then. Chapter sources · Open image
Make time-aware features reproducible — control and failure modes
Make time-aware features reproducible Make time-aware features reproducible — control and failure modes Late data can create hidden leakage. The branches show why alternative designs fail. Control design Filter by availability as well as event time. Late data can create hidden leakage. Failure mode 1 Use the final warehouse snapshot. It includes facts learned later. avoid Failure mode 2 Include the current attempt in prior history. That changes the feature definition. avoid Failure mode 3 Ignore window boundaries. Off-by-one events can change decisions. avoid
Control design

Filter by availability as well as event time. Late data can create hidden leakage.

Failure mode 1avoid
Use the final warehouse snapshot. It includes facts learned later.
Failure mode 2avoid
Include the current attempt in prior history. That changes the feature definition.
Failure mode 3avoid
Ignore window boundaries. Off-by-one events can change decisions.
Late data can create hidden leakage. The branches show why alternative designs fail. Chapter sources · Open image

Preserve missingness and quality

Preserve missingness and quality — the flow
Preserve missingness and quality Preserve missingness and quality — the flow Follow the sequence. Use the approved response for that defect. Detect Identify missing stale or invalid evidence Classify Record the cause where known Fallback Use the approved response for that defect
  1. DetectIdentify missing stale or invalid evidence
  2. ClassifyRecord the cause where known
  3. FallbackUse the approved response for that defect
Follow the sequence. Use the approved response for that defect. Chapter sources · Open image

Missing data can come from a new customer, an unsupported source, a timeout, or a broken pipeline. These causes have different meanings. Use explicit validity and freshness fields rather than treating every missing value as zero.

Track completeness by source, product, and relevant population. A global 99 percent completeness rate can hide a fully broken small segment. Define which defects prevent a decision, which permit a bounded fallback, and which require later repair. The data-quality decision should be visible in the risk result so operations can distinguish customer risk from system uncertainty.

Missing is a state with possible causes. A device signal may be absent because the customer uses an unsupported environment, a provider is down, consent is unavailable, or the event arrived through a different product path. Replacing every absence with zero makes these situations look like the same measured value. Preserve the missing state and, where reliable and appropriate, its reason.

The decision policy must define what to do with that state. A model can be trained to handle missing inputs, but a new production outage may create a missingness pattern it never encountered during training. Monitor availability by feature and traffic segment. An aggregate health check can look normal while one high-impact population receives incomplete evidence.

Inside the mechanism. Use a typed quality state such as present, absent, stale, unavailable, or conflicting alongside the value. A missing count should not become zero unless the source contract establishes that meaning. Report completeness against the eligible population and by important segment. A global average can hide a broken partner feed. The decision record should retain the quality state actually used.

A concrete example. A zero count, an absent record, a stale response, and a failed source are distinct observations. Their operational meaning depends on the feature contract. The daily source population is 14,200 items, but 284 are outside the completed monitoring run. The included population creates 250 hits and 205 unique cases. With 17 cases already open and capacity for 240, the queue closes at 0. Coverage, duplicate work, and staffing are separate causes; reducing one number does not prove that the overall control improved.

When the assumption fails. The feature store replaces failed reads with zero and hides a device-data outage. Retain explicit quality states and route incomplete evidence through an approved policy. The following worked sequence shows the reference condition, a stress condition, and a response condition with explicit synthetic data. These are comparative assumptions, not measured causal effects.

Follow a worked case3 conditions · 36 figures

A zero count, an absent record, a stale response, and a failed source are distinct observations. Their operational meaning depends on the feature contract.

Preserve missingness and quality — the distinction
Preserve missingness and quality Preserve missingness and quality — the distinction These concepts answer different questions. Read each definition in the context of the section. Known zero A valid measured absence Unknown value Measurement is unavailable or invalid
Known zero
  • A valid measured absence
Unknown value
  • Measurement is unavailable or invalid
These concepts answer different questions. Read each definition in the context of the section. Chapter sources · Open image
Quality record
Preserve missingness and quality Quality record Fictional teaching record. Policy-defined treatment. Quality record Illustrative data; not a real customer record or a prescribed policy. history_count null Unavailable value quality provider_timeout Known cause action bounded fallback Policy-defined treatment System uncertainty must remain visible
Fictional educational excerpt / Not for execution

Quality record

Illustrative data; not a real customer record or a prescribed policy.

  1. history_countnull

    Unavailable value

  2. qualityprovider_timeout

    Known cause

  3. actionbounded fallback

    Policy-defined treatment

System uncertainty must remain visible

Fictional teaching record. Policy-defined treatment. Chapter sources · Open image
Preserve missingness and quality — control and failure modes
Preserve missingness and quality Preserve missingness and quality — control and failure modes System uncertainty must remain visible. The branches show why alternative designs fail. Control design Keep quality status in the decision record. System uncertainty must remain visible. Failure mode 1 Replace all nulls with zero. Unknown becomes a false measured fact. avoid Failure mode 2 Monitor only global averages. Small segments can fail completely. avoid Failure mode 3 Let every consumer invent a fallback. Behavior becomes inconsistent. avoid
Control design

Keep quality status in the decision record. System uncertainty must remain visible.

Failure mode 1avoid
Replace all nulls with zero. Unknown becomes a false measured fact.
Failure mode 2avoid
Monitor only global averages. Small segments can fail completely.
Failure mode 3avoid
Let every consumer invent a fallback. Behavior becomes inconsistent.
System uncertainty must remain visible. The branches show why alternative designs fail. Chapter sources · Open image

Use lineage as an engineering tool

Use lineage as an engineering tool — the flow
Use lineage as an engineering tool Use lineage as an engineering tool — the flow Follow the sequence. Link the resulting value to its use. Source Identify original evidence Transform Version the feature computation Decision Link the resulting value to its use
  1. SourceIdentify original evidence
  2. TransformVersion the feature computation
  3. DecisionLink the resulting value to its use
Follow the sequence. Link the resulting value to its use. Chapter sources · Open image

Lineage connects a feature to its source events, transformations, and versions. It supports debugging, model review, customer corrections, and incident analysis. A column name is not enough if its definition changed over time.

Store the feature definition version and the source snapshot or reproducible reference needed for the use. Apply privacy controls to the retained data. When a source defect is found, use lineage to identify affected decisions and models. Without it, teams often rerun everything or miss part of the impact because they cannot trace which records consumed the bad field.

Inside the mechanism. Lineage connects a source fact to transformations, features, models, rules, actions, and later outcomes. Store stable version references and make the path inspectable for a historical decision. A dashboard definition change can alter reported performance without changing customer behavior. Version metric logic as well as model logic so a comparison can be reproduced under the same definitions.

A concrete example. An explanation must connect a decision to the evidence, transformations, policy, and model used at that moment. The current production model cannot explain every historical action. The case identifies 4,032 eligible records from a source population of 4,200. The required workflow completes for 3,911, but 59 completed records miss the illustrative internal target. Another 121 remain incomplete. Communication evidence covers 3,872 generated notices. Scope, completion, timeliness, and delivery are four separate properties of the customer outcome.

When the assumption fails. A feature transformation changes without a version and makes past decisions irreproducible. Retain immutable references to source facts and executable transformation versions. The following worked sequence shows the reference condition, a stress condition, and a response condition with explicit synthetic data. These are comparative assumptions, not measured causal effects.

Follow a worked case3 conditions · 36 figures

An explanation must connect a decision to the evidence, transformations, policy, and model used at that moment. The current production model cannot explain every historical action.

Use lineage as an engineering tool — the distinction
Use lineage as an engineering tool Use lineage as an engineering tool — the distinction These concepts answer different questions. Read each definition in the context of the section. Column label Human-readable field name Lineage Traceable path from source to decision
Column label
  • Human-readable field name
Lineage
  • Traceable path from source to decision
These concepts answer different questions. Read each definition in the context of the section. Chapter sources · Open image
Feature lineage
Use lineage as an engineering tool Feature lineage Fictional teaching record. Impact tracing reference. Feature lineage Illustrative data; not a real customer record or a prescribed policy. Feature refund_ratio Output field Definition v8 Window and denominator rules Source batch batch-117 Impact tracing reference The same name can hide changed meaning
Fictional educational excerpt / Not for execution

Feature lineage

Illustrative data; not a real customer record or a prescribed policy.

  1. Featurerefund_ratio

    Output field

  2. Definitionv8

    Window and denominator rules

  3. Source batchbatch-117

    Impact tracing reference

The same name can hide changed meaning

Fictional teaching record. Impact tracing reference. Chapter sources · Open image
Use lineage as an engineering tool — control and failure modes
Use lineage as an engineering tool Use lineage as an engineering tool — control and failure modes The same name can hide changed meaning. The branches show why alternative designs fail. Control design Version definitions and preserve traceable sources. The same name can hide changed meaning. Failure mode 1 Rename columns as the only history. Past calculations remain unclear. avoid Failure mode 2 Keep raw data everywhere for convenience. Lineage still needs controlled access. avoid Failure mode 3 Ignore downstream models during a data incident. They may inherit the defect. avoid
Control design

Version definitions and preserve traceable sources. The same name can hide changed meaning.

Failure mode 1avoid
Rename columns as the only history. Past calculations remain unclear.
Failure mode 2avoid
Keep raw data everywhere for convenience. Lineage still needs controlled access.
Failure mode 3avoid
Ignore downstream models during a data incident. They may inherit the defect.
The same name can hide changed meaning. The branches show why alternative designs fail. Chapter sources · Open image

Reconcile the population

Reconcile the population — the flow
Reconcile the population Reconcile the population — the flow Follow the sequence. Explain every material difference. Eligible Define the source population Processed Trace each required stage Reconcile Explain every material difference
  1. EligibleDefine the source population
  2. ProcessedTrace each required stage
  3. ReconcileExplain every material difference
Follow the sequence. Explain every material difference. Chapter sources · Open image

Risk systems need population checks: eligible source events, accepted ingestion, feature computation, decisions, and downstream cases. Compare counts and identifiers across these stages. A model can be accurate on the records it sees while missing a large part of the business.

Use control totals and exception reports with explicit exclusions. Investigate unexpected differences by event type and partner. Preserve duplicates separately from missing events. A total count match can still hide one extra and one missing record, so perform identifier-level checks for consequential paths.

Population reconciliation tests whether the pipeline sees the activity it claims to cover. Compare source transactions with accepted events, feature rows, decisions, and final outcomes using stable identifiers and documented exclusions. An event can be valid in isolation while an entire partition is absent. Count checks, amount checks within currency, and age checks help locate these gaps. Keep duplicates, late arrivals, rejected records, and genuinely out-of-scope activity distinct so the reconciliation can explain a difference rather than merely detect one.

Inside the mechanism. Population reconciliation should conserve identifiers and values across stages while explaining legitimate exclusions and aggregation. Compare received, accepted, rejected, processed, and pending records for the same window. Account for late arrivals explicitly. A checkpoint or throughput counter is not an independent source of truth. Use authoritative upstream and downstream records to identify missing, duplicated, and mismatched actions.

A concrete example. Transport delivery counts do not establish that all financial events reached the ledger. Count and value comparisons need the same identifiers, window, and currency. The batch begins with $780,000 of instructions and $748,800.00 of captured value. At the observation cutoff, $22,464.00 remains pending. After the stated refunds, fees, and restrictions, $604,281.60 is available for payout. The unresolved instruction count is 2; an unknown external result is handled separately from a known decline.

When the assumption fails. A consumer checkpoint advances past rejected events and the dashboard still shows healthy throughput. Reconcile authoritative event IDs and amounts through ingestion, decision, and posting. The following worked sequence shows the reference condition, a stress condition, and a response condition with explicit synthetic data. These are comparative assumptions, not measured causal effects.

Follow a worked case3 conditions · 36 figures

Transport delivery counts do not establish that all financial events reached the ledger. Count and value comparisons need the same identifiers, window, and currency.

Reconcile the population — the distinction
Reconcile the population Reconcile the population — the distinction These concepts answer different questions. Read each definition in the context of the section. Model accuracy Quality on scored records System coverage Whether required records were scored at all
Model accuracy
  • Quality on scored records
System coverage
  • Whether required records were scored at all
These concepts answer different questions. Read each definition in the context of the section. Chapter sources · Open image
Coverage reconciliation
Reconcile the population Coverage reconciliation Fictional teaching record. Coverage gap despite good model accuracy. Coverage reconciliation Illustrative data; not a real customer record or a prescribed policy. Eligible 10000 Source events Decided 9800 Risk results Unexplained 200 Coverage gap despite good model accuracy Coverage is a separate property from accuracy
Fictional educational excerpt / Not for execution

Coverage reconciliation

Illustrative data; not a real customer record or a prescribed policy.

  1. Eligible10000

    Source events

  2. Decided9800

    Risk results

  3. Unexplained200

    Coverage gap despite good model accuracy

Coverage is a separate property from accuracy

Fictional teaching record. Coverage gap despite good model accuracy. Chapter sources · Open image
Reconcile the population — control and failure modes
Reconcile the population Reconcile the population — control and failure modes Coverage is a separate property from accuracy. The branches show why alternative designs fail. Control design Reconcile identifiers as well as totals. Coverage is a separate property from accuracy. Failure mode 1 Measure only scored records. Missing events disappear from the metric. avoid Failure mode 2 Assume equal counts mean equal populations. Offsetting errors can remain. avoid Failure mode 3 Exclude failures without reporting them. The denominator becomes misleading. avoid
Control design

Reconcile identifiers as well as totals. Coverage is a separate property from accuracy.

Failure mode 1avoid
Measure only scored records. Missing events disappear from the metric.
Failure mode 2avoid
Assume equal counts mean equal populations. Offsetting errors can remain.
Failure mode 3avoid
Exclude failures without reporting them. The denominator becomes misleading.
Coverage is a separate property from accuracy. The branches show why alternative designs fail. Chapter sources · Open image

Chapter connections

Continue with Decision engines, rules, and reliable execution to follow the next part of the system. Use the glossary for terminology and risk mathematics for formulas and worked calculations.

Sources

Reviewed 2026-09-17
  1. PostgreSQL: transaction isolation
  2. scikit-learn: model evaluation metrics