← Back to the chapter · Previous detail

Technical detail · Storage Design Case Studies

Validate the storage event envelope

The validator requires event time, ingest time, source id, schema version, quality, and payload. It rejects missing fields and quality outside 0–100; the wider canonical contract also carries trace id.

REQUIRED_FIELDS = {
    "event_time",
    "ingest_time",
    "source_id",
    "schema_version",
    "quality",
    "payload",
}

def validate_storage_event(event: dict) -> tuple[bool, list[str]]:
    missing = sorted(REQUIRED_FIELDS - event.keys())
    if missing:
        return False, [f"missing:{field}" for field in missing]
    if event["quality"] < 0 or event["quality"] > 100:
        return False, ["quality_out_of_range"]
    return True, []

← Back to the chapter · Previous detail