← Data and engineering quality · Chapter 2

Define the purpose and boundaries of event data

Define purposes, minimal fields, versions, and lateness rules for course-completion events, then trace how duplicates, missing records, and deletion affect derived metrics.

After this guide, you can

Validate event contracts and specify access, retention, and deletion across collection and derived metrics.

A learning page plans to collect exercise-completion events to find confusing steps. Define the decision before collecting data. Measuring step completion normally does not require uploading full answers or retaining every input and device detail.

E-1 and the other identifiers are fictional. A completed event means the program observed a defined condition; it does not prove mastery. The case defines a minimal contract and examines versions, duplicates, timing, and deletion responsibilities.

Define when the event happens

Clicking submit, passing a check, and successfully saving a result are different moments. Choose the condition appropriate to the question and generate the event at an authoritative point. Frontend clicks describe interaction but cannot replace confirmed persistence.

An event dictionary names its trigger, producer, fields, units, and purpose. A completion event might include a public lesson ID, schema version, and stable event ID. If user-level conversion requires an identifier, assess its necessity and scope separately.

Explain the use of every field. Omit fields with no identified purpose. Free text, model prompts, uploaded content, and account details should not be default telemetry. Narrow access and retention are needed even for debugging, or analytics becomes another copy of business documents.

Separate event time from arrival time

Event time describes occurrence; ingestion time describes receipt. Offline retries can deliver yesterday's event today, and client clocks may be inaccurate. Aggregation by either time answers a different question, so name the choice in the metric definition.

At-least-once delivery can repeat records. A stable event ID enables deduplication, whose window and storage lifetime also need design. If one ID reappears with different content, reject or investigate the conflict rather than randomly overwriting it.

Out-of-order arrival affects windows. A system can accept bounded lateness and revise results or report late events separately. The choice depends on real-time needs, permitted revisions, and cost. Mark when a window is sufficiently complete instead of comparing incomplete recent data directly with settled history.

Shape validation is an initial gate

Field additions and renaming require versioning and compatibility planning. Producers may not update together. JSON Schema can check types, required fields, and allowed values, but cannot prove an event occurred or that collection has an appropriate basis.

This offline model accepts three fixed fields, version 1, and completed events. It deduplicates E-1, rejects unsupported versions and missing fields, and refuses a boolean as an integer version.

events = [
    {"id": "E-1", "version": 1, "kind": "completed"},
    {"id": "E-1", "version": 1, "kind": "completed"},
    {"id": "E-2", "version": 2, "kind": "clicked"},
    {"id": "E-3", "version": 1},
]
def valid(event):
    return (isinstance(event, dict) and set(event) == {"id", "version", "kind"}
            and isinstance(event["id"], str) and bool(event["id"])
            and type(event["version"]) is int and event["version"] == 1
            and event["kind"] == "completed")
seen = set()
accepted = []
for event in events:
    if valid(event) and event["id"] not in seen:
        seen.add(event["id"])
        accepted.append(event)
assert len(accepted) == 1
assert not valid({"id": "E-4", "version": True, "kind": "completed"})
print(len(accepted))

The actual output is 1. Only the first E-1 is accepted. Its duplicate, E-2's unsupported version, and E-3's missing kind are excluded. The model uses no JSON Schema library and does not validate time, persist records, or resolve conflicting duplicate content.

Production collection can isolate invalid records in a controlled error queue with error categories and producer versions. Do not print entire failed events into general logs. Compatibility failures need enough version evidence to locate and repair the producer change.

Minimization requires more than hashing

W3C privacy principles call for limiting transferred data to what user goals require and providing appropriate controls. A hashed identifier may still connect records, and predictable source values may be enumerated. Removing a name does not automatically anonymize a behavioral trail.

Distinguish identity-free aggregation, linked operational data, and sensitive debugging. They need not share identifiers or retention rules. Possible future usefulness does not justify unlimited collection, and a consent screen does not replace necessity analysis.

Processing grounds, consent requirements, and rights depend on applicable rules and context. This lesson does not establish legal sufficiency. Technical controls can limit fields, access, and retention; a schema function cannot determine compliance.

Assign lifecycle responsibility

Name an owner and record the path from producer through queues and storage to metric tables. Changes need a list of affected reports. Lineage and metric versions explain transformations and support recalculation after errors.

Define access and retention for raw, aggregated, and debugging data. Deletion must consider applicable rules for copies, exports, backups, and derived tables. Deleting the primary table may leave linkable copies. If backups cannot be immediately changed, define how restoration avoids reintroducing deleted records.

OpenTelemetry describes runtime signals, without implying unlimited business dimensions. User IDs in metric labels create high cardinality and privacy costs. Manage request correlation, business events, and aggregate dimensions according to their purposes.

Preserve reasons for missing data

Quality checks include validity, duplication, lateness, and producer coverage. A successful collection job does not establish complete arrival. Rejection rates by version, producer, and time can reveal a client release that omits a field.

Do not replace a missing lesson ID with an arbitrary course or count unknown outcomes as failures. Retain error categories and correction rules, then recalculate affected windows where necessary. Dashboards should distinguish zero completions from no valid data.

Exercise: connect purpose and acceptance

Design a completion event and explain each field's purpose and retention. Include valid, duplicate, incomplete, unsupported, conflicting, and late records. Define acceptance, rejection, and isolation rules, then trace the event into a conversion metric.

Accept the design when duplicates cannot increase completion counts, unknown versions stay out of results, and recent windows expose lateness. General logs must contain no bodies or credentials. Describe deletion propagation into derived data and identify legal and backup conditions the exercise does not verify. Check error categories and denominators as well as the final count.

Sources & further reading

Sources checked on 2026-11-10. Original engineering explanation; examples are teaching data, not production measurements.