Skip to main content

Define your Service Levels

Beyond structure and quality, a data contract can declare service levels — the promises a provider makes about when the data arrives and how long it is kept. In ODCS these live in the top-level slaProperties block, and the CLI turns two of them into executable checks:

slaProperties:
- property: freshness
value: 24
unit: h
element: orders.order_timestamp
- property: retention
value: P1Y
element: orders.order_timestamp

Run them with datacontract test like any other check:

datacontract test --checks servicelevel datacontract.yaml

Omit --checks to run service levels alongside the schema and quality checks.

Freshness

property: freshness asserts that the data is recent. The CLI reads the newest value of the referenced timestamp column (MAX) and compares its age against the threshold:

slaProperties:
- property: freshness
value: 24
unit: h
element: orders.order_timestamp

Passes when now − MAX(orders.order_timestamp) < 24 hours.

Freshness unitMeaning
d, day, daysdays (the default when unit is omitted)
h, hr, hour, hourshours
m, min, minute, minutesminutes

Retention

property: retention asserts the opposite end: that data older than the retention period has been deleted. The CLI reads the oldest value of the column (MIN) and compares its age against the threshold:

slaProperties:
- property: retention
value: 1
unit: y
element: orders.order_timestamp

Passes when now − MIN(orders.order_timestamp) < 1 year.

Retention unitMeaning
y, yr, year, yearsyears (365 days)
m, mo, month, monthsmonths (30 days)
d, day, daysdays (the default when unit is omitted)
h, hr, hour, hourshours
min, minute, minutesminutes
s, sec, second, secondsseconds
caution

unit: m means minutes for freshness but months for retention. Spell the unit out (minutes / months) if you want to be unambiguous.

Retention also accepts an ISO 8601 duration as the value, in which case unit is ignored:

slaProperties:
- property: retention
value: P1Y # also P6M, P30D, PT12H, PT30M, PT10S
element: orders.order_timestamp

The element reference

element must be a fully qualified schema.property reference — exactly one dot — pointing at a date or timestamp column:

element: orders.order_timestamp # schema "orders", property "order_timestamp"

Timestamps without a timezone are interpreted as UTC, and the age is measured against the current UTC time.

note

ODCS also defines a contract-level slaDefaultElement. The CLI does not use it — spell out element on every SLA property that should be checked.

When no check is generated

A service level is skipped — without failing the run — when:

  • the property is anything other than freshness or retention (for example latency, frequency, or timeOfAvailability, which are documentation only),
  • element or value is missing,
  • element is not exactly one schema.property reference,
  • the referenced schema is not in the contract, or
  • the unit is not one of the values listed above.

Run with --debug to see the reasons. If the check does run but the column is empty or entirely NULL, the check fails with No timestamp value found in '<field>'.

Where service levels are used

  • testfreshness and retention run as servicelevel checks.
  • SodaCL export — both become Soda freshness and retention checks.
  • Markdown, HTML, and Excel exports render the full slaProperties block, including the properties that are documentation only.
  • changelog reports added, removed, and changed service levels between two versions.

Learn more