Online Offline Consistency
Problem
Chronon produces data in two contexts. Offline as hive tables and Online via a low latency kv-store. In the context of a machine learning application, training uses offline data and inference uses online data. To achieve best model performance, offline data and online data need to be consistent with each other. Or there would be a difference in model performance while training vs. inference, usually in a bad way. This framework allows users to measure inconsistency automatically.
Causes of inconsistencies
While 100% consistency is desirable, it is not always possible.
Realtime features consume streams of data (Kafka topics) that have inherent network latencies. For Kafka, in at-least-once mode producers need to write to multiple disks before the message can be sent to the consumers. Finally, there is additional latency to write to the KV store before the model can fetch the updated feature for inference. This is usually in the order of ms to seconds.
Computing and uploading non-realtime features to the KV store takes time. For example, midnight accurate features need to wait for their upstream data to arrive and then need to be transformed into features and uploaded into the KV store. The total time to refresh batch features could be in the order of minutes or hours. This inconsistency is usually centered around midnight until the bulk upload of new features to the KV store finishes - for features that need to be refreshed daily.
Design
We log inference queries, Chronon's responses along with their timestamps.
CREATE TABLE IF NOT EXISTS <namespace>.query_logs (
key_bytes STRING COMMENT 'Avro encoded key bytes',
value_bytes STRING COMMENT 'Avro encoded value bytes',
ts_millis BIGINT COMMENT 'Timestamp of the fetch',
query_source STRING COMMENT 'Name of environment or service calling fetch'
)
PARTITIONED BY (
ds STRING,
join_name STRING
)
TBLPROPERTIES (
'retention' = '90'
)We use the joins uploaded from metadata and schemas in batch uploads to construct the avro schema of join keys and values. This step happens in the spark driver.
We want to apply sampling in such a way that we capture all instances of a subset of keys, instead of randomly selecting a subset of all queries. This is to reduce amount of keys that the join's bloom filter accepts while scanning source data.
Filtering in fetcher using: hash(key_bytes) % 100 * 1000 <= sample_percent * 1000
Spark job logic
- Filter on
join_name = '<join_name>' andds between earliest_unavailable_ds AND run_ds
- Expand key_bytes & value bytes into separate columns and save as table
<namespace>.<join_name>_logged
- Fetch join conf from kv store
- Replace left source with logged table. (prefix value_columns with logged)
- Compute offline join. (earliest unavailable ds till now)
- Save to
<namespace>.<join_name>_comparison.
- Save to
- Consistency Metrics to compute
- equality comparison: (universal to all types)
- count(a != b) / count(*), (mismatch)
- count(a = null & b != null) / count(*) (missing)
- count(a != null & b != null) / count(*) (extra)
- numeric comparison: (specific to numeric types, everything will be cast to doubles)
- sum(abs(a - b))/sum(a+b) (smape)
- b - a (delta distribution)
- a (logged distribution)
- b (backfilled distribution)
- sequence comparison:
- length(a) (logged_length distribution)
- length(b) (backfilled_length distribution)
- edit_dist(a, b) (Levenshtein distance distribution)
- inserts and deletes are counted separately to distinguish extra vs missing
- replacements are not allowed
- map comparison: [TODO]
- missing_keys,
- extra_keys,
- mismatched_keys,
- left_keys,
- right_keys
- values are also compared according to 1, 2, 3
- equality comparison: (universal to all types)
- Consistency metrics are produced as a hive table per join
<namespace>.<join_name>_consistency_metrics- partition columns: ds, hr_minute, group_by_name,
- metadata columns: feature_name, metric_name
- metric columns: histogram, number (only one of histogram or number is present)
Choosing the right quantile sketch
"Compressing" a series of values into a histogram is what we want - to "summarize" inconsistencies across various data points. There are several available sketching algorithms in Java. These algorithms broadly fall into two categories, "practical" & "theoretical". Where theoretical ones have a proven lower bound on errors and practical ones don't. Leading both the packs are t-digest and ReqSketch. We will only be considering these two sketches.
Summarily, ReqSketch is accurate at all ranges compared to t-digest. ReqSketch takes slightly more space(2.75 kb vs 2.65 kb) - but is much faster(>2x) to update, serialize and deserialize. Since we are only going to hold one sketch per feature name per executor, space is less of a factor than the speed of update during aggregation.
Choosing the right aggregation strategy
Merge-combine shuffles deltas across all machines in the combine stage to all machines in the merge stage. Tree aggregate rolls up deltas (imagine a binary tree). Tree aggregate mandates that all data eventually fit in a single machine. Merge-combine is more suited to situations where output data is still large.
Consistency metric outputs are decidedly - "small data". Pessimistically assuming that each join has 1000 features and feature has 10 metrics that are heavy(distribution), We will have at most 30MB of consistency summary data (as deltas) per machine.
Estimating size of consistency summary
Once we have the final merged sketch for distribution, we will "bin" the quantiles into float values. So for min, p5, p25, p50, p75, p95, max - 28 bytes.
Currently, will have a maximum of 4 distributions, 3 Longs and 1 double per feature. About 400 Bytes. For a join with 1000 features, this comes to 118 KB per day of data. For 100 features, it is 12 KB. For a three-month range, it will be 9 MB and 0.9 MB respectively.
Which is to say that displaying 10,000 metrics at one time is the current breaking point of the design.
Future work
Specify groupBy lag
Chronon could allow users to specify a write-lag as milliseconds. Offline, joining with observations/query log would shift the query timestamps ahead by the specified amount. One could use this consistency-measurement framework to estimate the time interval to shift. Since this would vary by data source, this needs to be set at group-by level. Once set, this would make any join that uses features from the group-by more consistent.
Visualization
- Upload to kv store - key is join, value is metrics summary json, ts is unix_time(ds) * 1000
- charts needs to work from local laptop, where submitting spark job is hard / not possible.
- Download from kv store, and serve using cask + scalatags + uplot.js
- cask + scalatags backend example
- uplot.js charting
Standalone groupBy consistency
- Sometimes, people directly use a groupBy without using a join. But, consistency and logging is still desired for the groupBy.
- We add one more column
typewhich is eithergroupByorjoin.
Payload request
- Join request, and group by request sometimes consists of additional columns
- Like session_id and search_id etc, that are not join keys.
- These columns are required by users who consume the
_loggedtables directly. - This is not related to consistency but more related to logging.
Enabling and Consuming Consistency Checks
Computation of OOC metrics can be turned on by setting the sample_percent and check_consistency in the join config like so:
my_join = Join(
...
sample_percent=10.0, # Logs 10% of online requests; percentages use the range 0–100.
check_consistency=True
)The sample_percent param will enable logging during fetching phase, and the check_consistency param will enable the online offline consistency check to compare the logged events with offline join job after data landing in the warehouse.
If using Zipline.AI: Configure a raw logging staging query, then enable the independent OOC workflow described below. Results appear in the join's Metrics tab.
If self-hosting: Orchestration must be configured. See sample Airflow implementation here.
The Spark job will write the result to a flat Hive table in the pattern of <output_namespace>.<team_name>_<join_name>_consistency.
OOC workflows in Zipline.AI Hub
OOC uses the MONITOR workflow mode. Its terminal node runs alongside the join's operational workflows, with its own schedule. OOC failures do not block the join's backfill or online deployment.
The first version supports daily ds partitions in yyyy-MM-dd format. It requires a configured metrics KV store on both the batch runner and Hub. APIs that do not implement metrics KV storage cannot publish OOC results.
Configure raw logging once
Reference the raw logging StagingQuery from the join. OOC runs missing staging work, extracts published schemas, decodes response logs, and compares offline values. These steps share the monitor schedule; a separate flattener schedule is unnecessary.
The staging query must preserve response rows and SCHEMA_PUBLISH_EVENT rows. Its output requires ds, name, ts_millis, key_base64, value_base64, and schema_hash. Payloads remain encoded until the flattener selects their published schema by hash.
from ai.chronon.types import ConfigProperties, StagingQuery, TableDependency
raw_logs = StagingQuery(
query="""
SELECT ds, name, ts_millis, key_base64, value_base64, schema_hash
FROM logging.feature_responses
WHERE ds BETWEEN {{ start_date }} AND {{ end_date }}
""",
output_namespace="features",
dependencies=[TableDependency(table="logging.feature_responses", partition_column="ds")],
start_partition="2026-10-01",
offline_schedule="@never",
step_days=1,
conf=ConfigProperties(common={"spark.executor.memory": "8g"}),
)Export this query from a staging_queries module and import it in the join module. The query owns its SQL, dependencies, Spark configuration, cluster configuration, and environment. Declare dependencies for each raw input table. Adapt the projection to the landing table's names and encoding; the example assumes the required base64 columns already exist.
Set start_partition before the first schema publication needed by the retained response logs. Schema extraction reuses the logging-schema GroupBy: filter SCHEMA_PUBLISH_EVENT, decode its key and value as UTF-8, and keep LAST(schema_value) per schema_hash. For each requested day, it reads raw history from start_partition through that day. The flattener reads response rows only for the requested dates and uses that day's schema snapshot.
A missing schema fails with the missing-hash count, source tables, and requested dates. Keep schema-publish events in the raw query and retain their history. A retry reuses completed partitions. OOC never decodes old responses using the current join schema. A feature added after a request was logged counts as a missing online value.
The generated tables are <join_output_table>__logging_schema and <join_output_table>_logged. Requests must be unique on the serving lookup keys, request time ts, and ds. OOC reapplies selected lookup-key expressions to the logged request inputs and preserves contextual inputs for derivations. Training row_ids and bootstrap values do not participate in comparison; feature values are recomputed from their sources.
Set schema-extraction and flattening resources through the join's existing mode overrides, using schema_extraction and log_flattener. The consistency mode controls comparison resources. The raw staging query keeps its own settings. Uploading and syncing the join includes the raw query in its monitor plan. The raw query can also be deployed independently when another workflow needs it.
Enable and run OOC
my_join = Join(
...,
online=True,
sample_percent=10.0,
check_consistency=True,
logging_source=raw_logs,
consistency_sample_percent=5.0,
consistency_schedule="0 6 * * *",
)consistency_sample_percent selects a deterministic subset of logged requests for both offline recomputation and comparison. Five percent means 5% of the requests already retained by logging. sample_percent controls logging at fetch time; consistency_sample_percent controls OOC compute after flattening.
Set OOC Spark, cluster, or environment overrides under the consistency mode in the join's existing configuration fields. Raw staging, schema extraction, and flattening retain their separate settings. Leave consistency_schedule=None for on-demand runs, or set @never to remove its schedule when deploying configuration. Deploy schedules through the existing zipline hub schedule or schedule-all commands.
Run a bounded OOC range from the join's Metrics tab with Run OOC, or use:
zipline hub monitor compiled/joins/team/my_join__1 --start-ds 2026-10-01 --end-ds 2026-10-02 --concurrency 2The node persists results in <join_output_table>__consistency and publishes per-feature hourly buckets to the configured metrics KV store. Results are isolated by the OOC node's semantic hash. A retry republishes saved results if a previous KV upload failed.
The UI shows compared counts, consistency, mismatches, and one-sided null values labelled Missing offline values and Missing online values. Consistency includes mismatches and one-sided nulls; values that are null on both sides agree. A requested raw day with no response rows fails with an actionable error. A valid raw day whose deterministic sample selects no requests produces an empty sample instead of reporting 100% consistency. Historical results use logged-request timestamps, not job execution time.
Numeric error magnitude
New OOC runs also publish mean SMAPE for numeric features:
100 × mean(2 × abs(online − offline) / (abs(online) + abs(offline))).
It ranges from 0% (equal) to 200%. Both-zero pairs contribute 0%; null and non-finite pairs are excluded. Buckets store a sum and a valid-pair count so the UI weights each numeric comparison equally across time. Missing values remain visible through the separate null rates. Categorical features, older metric buckets, and buckets without valid numeric pairs show no SMAPE value.
Mismatch rate answers how often values differ; SMAPE answers how large those numeric differences are. A count that is consistently one low can have 100% mismatch with a small SMAPE. Neither metric explains the cause of a discrepancy. Existing persisted OOC output is not rewritten automatically; new comparisons are needed to populate SMAPE for historical dates.