Skip to content
tezvyn:
Menu

Design a Schema Validation System for Analytics Events

Source: twilio.comMediumHow cards are made

This tests your ability to balance data quality, performance, and developer experience. A good answer defines a central 'Tracking Plan,' enforces it on the client for feedback and the server for integrity, and quarantines failed events.

What's really being asked

This question tests your understanding of data governance trade-offs. The interviewer is looking for a nuanced answer that balances the need for pristine data with practical realities like developer experience, client-side performance, and the cost of server-side processing. It's about designing a robust, multi-layered system, not just a simple validation function.

The full answer

A good answer covers four key areas in order. First, establish a source of truth by defining a centralized, version-controlled 'Tracking Plan' or schema registry (e.g., using JSON Schema, Protobuf). Second, discuss client-side enforcement, which should be non-blocking and primarily for developer feedback in dev builds to catch errors early. Third, detail server-side enforcement, which is the critical, authoritative gate where every event is validated upon ingestion. This is non-negotiable for data integrity. Fourth, explain failure handling: invalid events are never silently dropped but are routed with error details to a 'violations' stream or dead-letter queue (e.g., a separate Kafka topic) for analysis.

The mistakes people make

A major red flag is suggesting enforcement only on the client. It is naive to trust the client, as it can be bypassed, old versions exist, and malicious actors can send anything. Another weak answer is enforcing only on the server; this is better but misses the chance for fast developer feedback, slowing down iteration. The worst answer is to simply drop invalid events. This constitutes data loss and prevents you from analyzing the root cause of the failure. Finally, suggesting that production client-side validation should block event submission is a performance anti-pattern; analytics should never break core application functionality.

What usually comes next

Expect questions about schema evolution and versioning (support both old and new schemas during a transition period). You might be asked how to manage the cost of the system (server-side compute, efficient dead-letter storage). Another common follow-up is how to handle a bug causing 100% of events to fail, which tests your knowledge of alert rate-limiting or circuit breakers to prevent alert storms.

A concrete example

A user submits a 'Product Viewed' event with a 'price' property as a string "29.99" instead of the number 29.99 required by the Tracking Plan. The client-side dev build console logs an error. The event is still sent. The server-side ingestion service validates it, sees the type mismatch, and routes the original event plus an error object to the 'analytics-violations' Kafka topic. It also increments a Prometheus counter validation_errors{event="Product Viewed", reason="type_mismatch"}. An analyst can later query the violations topic, and an engineer is alerted if this error rate spikes above 5% in a 5-minute window.

Interview question

When an analytics event fails server-side validation in the described system, what is the prescribed method for handling it?

  • a.The client application is notified to prevent future similar errors.
  • b.The event, along with its error details, is sent to a dedicated violations stream.Correct
  • c.The event is silently discarded to maintain data cleanliness.
  • d.The system immediately triggers an alert and temporarily pauses all event ingestion.
Why?

The card explicitly states that invalid events are routed with error details to a 'violations' stream or dead-letter queue for analysis, preventing data loss. Silently dropping events (Option C) is identified as a 'worst answer' because it constitutes data loss and prevents root cause analysis.

Just read this? Test yourself on what you have been reading.

Read the original → twilio.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on system design — each one lists the topics its interview covers.

See open roles