Problem
A product with 132 event schemas needs every behavioral event to match its JSON schema. Snowplow checks each event only after it is sent. An invalid event, for example one with a property of the wrong type, is dropped from enrichment and treated as unrecoverable unless a large incident occurs. The front-end library took a loosely typed object and mapped it to schemas with a growing chain of conditions. The chain was hard to maintain, and the single mapping left event producers little control. Mistakes surfaced in production, when the data was already lost.
Example from the article: an event sent with a missing field or a value of the wrong type is noticed only at run-time, usually in production, when the data is already lost.
Solution in brief
Generate TypeScript interfaces from the Snowplow JSON schemas and build the tracking function around them. A literal SCHEMA_KEY in each interface lets two union types, Event and Entity, restrict what can be tracked. Type errors then appear at compile time, and a pipeline automates type generation.
Questions this case answers
- How to detect invalid tracking events at build time when events are validated against schemas only after they are sent and invalid ones are dropped
- How to keep client-side event code in sync with a versioned schema registry without hand-maintained mapping logic
- How to catch a malformed behavioral event before it reaches production instead of losing it at validation time?
- How to keep application code and event JSON schemas from drifting apart as the schema count grows?
Tools and methods
- Snowplow — behavioral tracking platform with self-describing JSON schemas and the Iglu schema registry
- json-schema-to-typescript — converts the JSON schemas into TypeScript interfaces
- Discriminated union types — restrict the tracking function to known events and entities
- Snowplow Data Structures API — fetches and validates schemas and their metadata for the generator
Google or a one-time email code. No password.