ML Feature Pipelines and Feature Stores Questions
Data infrastructure for machine learning: feature pipelines, feature stores, online/offline consistency, training-serving skew, and data preparation for models. Covers building reliable feature platforms and preventing leakage in the data path feeding models. The data-engineering-for-ML topic.
Explain schema evolution: what it is, why it matters for feature pipelines, and how commonly used serialization formats (Avro, Parquet, Protobuf) support it. Describe a process for handling a breaking schema change in a production streaming pipeline that has multiple downstream consumers.
Sample Answer
Direct answer: Schema evolution is the practice of changing a data schema over time (adding, removing, or modifying fields) while keeping existing producers and consumers working, and formats like Avro, Parquet, and Protobuf support it through explicit compatibility rules and a schema registry that tracks versions.
Structured elaboration:
- Why it matters for feature pipelines. A feature pipeline has many producers (upstream services or teams writing events) and many consumers (transformation jobs, models, other teams' pipelines); if a schema change breaks any consumer, the failure can be silent (a consumer misinterprets a field) or loud (a consumer crashes), and both are costly to debug after the fact, so having explicit rules for what changes are safe is far cheaper than discovering the hard way.
- How Avro, Parquet, and Protobuf support it. Avro attaches the writer's schema to the data (or references it via a schema registry) and defines resolution rules for reading data written with an older or newer schema than the reader expects; adding a field with a default value is backward compatible, removing a field a reader depends on is not. Parquet stores its schema in the file's footer and supports schema merging across files with compatible-but-not-identical schemas (commonly used when a table's schema evolves over time across many files), though it relies more on the query engine to reconcile differences than Avro's explicit reader/writer resolution. Protobuf uses numbered fields, where adding a new numbered field is safe (old code ignores it, new code sees it as absent/default in old data) and reusing or renumbering an existing field number is unsafe (it silently reinterprets old data incorrectly).
- Compatibility models. Backward compatibility means new code can read data written by old code (safe: adding an optional field); forward compatibility means old code can read data written by new code (safe: old code ignoring a new field it doesn't know about); full compatibility requires both directions to hold simultaneously, which is the strictest and safest guarantee for a shared schema used by many independent consumers who upgrade on different schedules.
- Handling a breaking change with multiple consumers. For a genuinely breaking change (renaming a field, changing its type incompatibly), the standard process is: introduce the new field alongside the old one (dual-write), migrate consumers to the new field on their own schedule, monitor until no consumer is still reading the old field, then remove the old field in a later, separate release, rather than attempting an atomic cutover across every consumer simultaneously.
Worked example: Adding a new optional device_type field to an event schema with a default value of "unknown" is backward compatible under all three formats: existing consumers that do not know about the field simply ignore it, and consumers upgraded to read it get "unknown" for historical data that predates the field's introduction, with no reprocessing required.
Trade-offs & pitfalls: A schema registry enforcing compatibility checks at write time (rejecting a producer's schema change that would break existing consumers) is the strongest guardrail, but it requires the discipline of registering every schema change through the registry rather than a producer silently writing a new shape; a team that bypasses the registry (writing raw JSON with no enforced schema, for example) loses this protection entirely and reintroduces the risk the registry exists to prevent. The dual-write-then-migrate-then-remove pattern for breaking changes is the safe default, but it is slower than a direct cutover, and teams under time pressure sometimes skip the migration step and go straight to removing the old field, which breaks any consumer that had not yet migrated, often silently.
Design a feature store that must sustain 100,000 feature writes per second while keeping average online read latency under 50ms. Outline the architecture layers (ingestion, transformation, offline store, online store, materialization jobs), the partitioning strategy, and the online storage technology choice, with emphasis on the write path.
Sample Answer
Direct answer: Sustaining 100,000 writes per second while keeping reads under 50ms means the write path and read path need to be architecturally separated: an ingestion and transformation layer absorbs the write volume and batches it efficiently into the offline store, while materialization jobs push a summarized, read-optimized copy into the online store on a cadence the read SLA (service-level agreement) can tolerate, rather than the online store taking every write synchronously.
Structured elaboration:
flowchart LR
Producers["Producers (100k writes/sec)"] --> Log["Kafka log"]
Log --> Xform["Transform layer"]
Xform --> Offline["Offline store (Parquet/Iceberg)"]
Xform --> Materialize["Materialization job"]
Materialize --> Online["Online store, 20 shards (DynamoDB / Cassandra)"]
Reader["Reads, under 50ms"] --> Online
- Ingestion layer. A message queue (Kafka or similar) absorbs the 100k writes/sec as an append-only log, decoupling producers from the rate the downstream stores can actually sustain and giving replay capability if a downstream consumer falls behind.
- Transformation layer. Stream or micro-batch processors (Flink/Spark Structured Streaming) consume the log, compute or pass through feature values, and write to both the offline store (for training, at full fidelity and volume) and a materialization pipeline feeding the online store.
- Offline store. Columnar, append-friendly storage (Parquet on object storage, or a table format like Iceberg/Delta) handles 100k writes/sec easily since it is optimized for high-throughput sequential writes, not point lookups.
- Online store and materialization. Rather than writing every one of the 100k events/sec directly into the low-latency online store, materialize periodically (e.g. every few seconds to a minute) into the online store's write path, or use an online store designed for high write throughput (a wide-column store like Cassandra, or a managed store like DynamoDB with provisioned write capacity) if genuinely every write must be reflected online quickly.
- Partitioning strategy. Partition by entity ID (consistent hashing) across enough shards on both the write and read side that no single partition absorbs a disproportionate share of the 100k writes/sec; monitor for and rebalance around emerging hot partitions.
- Online storage technology choice. DynamoDB or Cassandra are natural fits here because they are built for high sustained write throughput with horizontal scaling, unlike a single-node Redis instance which would need careful cluster sharding to sustain 100k writes/sec reliably.
Worked example: At 100k writes/sec, if you partition into 20 shards, each shard handles 5,000 writes/sec, which is comfortably within a single Cassandra or DynamoDB partition's sustained write capacity when the partition key is well-distributed (recall DynamoDB's roughly 1,000 WCU per-partition soft limit, so 5,000 writes/sec on one logical shard would actually need to be spread across at least 5 underlying partitions, reinforcing that partition-key design, not just shard count, determines whether the write path holds up).
Trade-offs & pitfalls: A store optimized for 100k writes/sec is not automatically also optimized for sub-50ms reads; the two workloads have different access patterns (append-heavy, roughly uniform writes vs. skewed, latency-sensitive reads), so the same store often needs different tuning (or a different store entirely) for each, which is why materializing into a separate, read-optimized online copy is the standard pattern rather than serving reads directly off the write-optimized store. Under-partitioning the write path is the single most common way this design fails in practice: a partition key that looks well-distributed in aggregate can still have local hot spots (a batch of correlated writes for related entities arriving together), so monitoring per-partition write rates, not just the aggregate, is necessary to catch it before it causes write throttling.
Design an end-to-end CI/CD and testing strategy for feature pipelines. Cover unit tests, integration tests, contract and schema tests, data diffs, canary rollouts for new feature computations, automated backfill validation, and the gates that must pass before a feature change reaches production.
Sample Answer
Direct answer: A CI/CD strategy for feature pipelines needs tests at multiple levels (unit tests for individual transforms, integration tests against realistic data, contract and schema tests that catch breaking changes early) plus deployment mechanics (canary rollouts, data diffs, and automated backfill validation) so a bad feature change is caught before, not after, it reaches production models.
Structured elaboration:
- Unit tests. Test individual transformation functions in isolation with small, hand-crafted inputs and known expected outputs, covering edge cases (nulls, empty inputs, boundary values) the way any well-tested code would be, run on every commit as the fastest feedback loop.
- Integration tests. Run the full pipeline (or a meaningful slice of it) against a realistic sample dataset (production-like, ideally a sampled and PII (personally identifiable information)-scrubbed slice of real data) to catch issues that only appear when components interact, such as a join that behaves differently at realistic data volume or with realistic key distributions.
- Contract and schema tests. Validate that a feature's output schema (types, nullability, value ranges) matches its declared contract before deployment, catching a breaking change (a column type change, a newly-nullable field) at CI time rather than when it silently breaks a downstream consumer in production.
- Data diffs. Before promoting a changed feature-computation job, run both the old and new logic against the same input and diff the outputs; a large, unexpected diff (more rows changed than the intended fix should cause) is a strong signal something is wrong, and this check catches classes of bugs that unit and integration tests, which only check known cases, would miss.
- Canary rollouts for features. Deploy a changed feature computation to a small percentage of traffic or to a shadow/parallel path first, comparing its output against the existing production version before fully cutting over, so a subtle bug affects a small blast radius and is caught by automated comparison rather than a full-scale incident.
- Automated backfill validation. When a feature change requires backfilling historical data, validate the backfilled values against expected statistical properties (row counts, null rates, value distributions matching expectations) before the backfill is considered complete and the new values are trusted.
- Deployment gates. Require all of the above to pass, plus perhaps a required review for schema-breaking changes specifically, before a feature-pipeline change reaches production; a failed data diff or schema-contract check should block the deploy automatically, not just warn.
Worked example: A change to a "days since last purchase" feature's calculation logic (fixing a timezone bug) would run: unit tests confirming the fix against hand-crafted timezone-boundary cases; an integration test against a sampled production dataset; a data diff comparing old vs. new logic across that same sample, expecting changes concentrated near timezone-boundary timestamps and flagging the deploy for review if the diff shows unexpectedly widespread changes; and a canary rollout materializing the new logic for 5% of entities and comparing model performance metrics on that slice before rolling out to 100%.
Trade-offs & pitfalls: Data diffs and canary rollouts add real latency to the deployment process (a canary needs to run long enough to gather a meaningful comparison), which is a genuine trade-off against shipping fixes quickly; the mitigation is scaling the rigor to the risk (a typo fix in a log message needs less ceremony than a change to a core feature's transformation logic feeding dozens of models). Contract/schema tests are only as good as the contracts being enforced; a pipeline that never formally declared a schema contract for a feature has nothing for the CI check to validate against, so establishing contracts is a prerequisite this strategy assumes, not something it can retrofit automatically.
The top 0.1% of user IDs receive 90% of read traffic for a set of online features, saturating the online store (a hot-key problem). Propose a multi-pronged mitigation strategy and analyze the cost and complexity trade-offs of the techniques you choose.
Sample Answer
Direct answer: Hot-key mitigation for online feature serving combines three layers that compose: caching close to the caller to absorb most of the skewed traffic, replicating the hot keys themselves so no single shard owns the whole load, and routing/throttling changes so the system degrades gracefully instead of falling over when a key gets even hotter than expected.
Structured elaboration:
- Caching. Add a local (in-process or co-located) cache in front of the online store for the hottest keys. Because the traffic is so skewed (top 0.1% of keys getting 90% of reads), even a small cache with a short TTL (time-to-live) captures most of the benefit: a cache holding only the top few thousand keys can absorb the majority of read volume.
- Replication of hot keys specifically. Rather than replicating every key uniformly, detect the hot ones (see detection below) and replicate just those onto multiple shards or nodes, so reads for a hot key fan out across several replicas instead of hammering one.
- Request routing. Route requests for a hot key round-robin or hash-based across its replicas, and route requests for cold keys normally; this requires the routing layer to be hot-key-aware rather than using a single static hash.
- Adaptive prefetching. For predictable hot keys (a trending item, a celebrity user), prefetch and pin them into cache ahead of the traffic spike rather than reacting after the first cache miss storm.
- Throttling and backpressure. As a last line of defense, apply per-key or per-shard rate limiting so one runaway hot key cannot starve the rest of the traffic on the same shard; combine with a fallback response (serve a slightly stale cached value or a default) rather than failing the request outright.
- Detection. Continuously track per-key or per-shard request counts (a sliding-window counter or a sketch like Count-Min Sketch for cheap approximate top-K tracking) so the system can flag a new hot key automatically rather than relying on someone noticing degraded latency first.
Worked example: If the top 0.1% of user IDs account for 90% of reads at 100k QPS (queries per second), that is roughly 90,000 QPS concentrated on a key set that might be only a few thousand entities. A cache holding those few thousand keys, even with a modest hit rate of 95%, removes on the order of 85,000 QPS from the backing store, turning a saturating hot-partition problem into a manageable ~15,000 QPS of cache-miss traffic spread across the full keyspace.
Trade-offs & pitfalls: Caching hot keys introduces a staleness window; for features where freshness matters (a just-updated fraud flag), a short TTL or a write-through cache invalidation is needed instead of a pure time-based expiry, which adds complexity. Replicating hot keys onto multiple shards breaks the simple "one key, one owner" mental model and complicates writes: a write to a hot key now has to fan out to every replica, or you accept eventual consistency across them. Detection systems based on a fixed threshold can be slow to react to a sudden spike (a key that goes from cold to hot in seconds, e.g. breaking news); a sketch-based or exponentially-weighted detector reacts faster than a simple rolling count but adds its own tuning surface.
Compare orchestration tools for ML feature pipelines: a DAG-based batch scheduler such as Airflow or Dagster versus an event-driven streaming runner. For which kinds of feature jobs would you choose DAG-based batch orchestration versus streaming, and how would you coordinate backfills and cross-dependencies across both?
Sample Answer
Direct answer: DAG (directed acyclic graph)-based batch orchestration (Airflow, Dagster) fits scheduled, dependency-driven feature jobs (nightly aggregates, periodic backfills); an event-driven streaming runner fits continuously-computed features that must react to data as it arrives. Coordinating backfills and cross-dependencies across both requires treating the streaming path's output as another dependency the batch DAG can wait on or validate against, and vice versa.
Structured elaboration:
- When DAG-based orchestration fits. Jobs with clear time-bounded inputs and outputs, explicit dependencies between steps (raw ingestion must finish before transformation, which must finish before materialization), and a natural retry/backfill model (rerun a specific date's DAG run). Airflow and Dagster both excel here, with Dagster's asset-based model making data lineage and backfills somewhat more explicit than Airflow's task-based model.
- When streaming fits. Features that must update continuously and cannot wait for a scheduled run; there is no natural "DAG run for 2pm-3pm" concept, the job simply runs continuously and reacts to each event.
- Coordinating backfills across both. A batch backfill (recomputing a feature for a historical date range) needs to know what the streaming path already computed for that range and either supersede it cleanly or reconcile with it, typically by having the batch backfill write to the same offline store with an explicit "this is the authoritative recomputed version" marker, and having downstream consumers prefer the batch-backfilled value over the original streaming-computed one for that historical range.
- Coordinating cross-dependencies. If a batch job's daily aggregate depends on the streaming path having fully processed all of that day's events (not just "close enough"), the batch DAG needs an explicit readiness check (a sensor or a completeness marker the streaming path emits) rather than just running on a fixed schedule and hoping the streaming path is caught up.
Worked example: A daily "total unique active users" batch job that also wants to cross-check against the streaming path's near-real-time running total would have its Airflow DAG include a sensor task that waits for the streaming path to emit a "day N fully processed, watermark passed midnight" signal before running the aggregation task, rather than firing at a fixed time (say, 1am) and risking reading an incomplete streaming-derived dataset if the streaming path is running behind for any reason that day.
Trade-offs & pitfalls: Treating the streaming path's completeness as always available by a fixed clock time (rather than checking an explicit signal) is a common source of silent, intermittent incorrectness in hybrid pipelines: on most days the streaming path is caught up by 1am, but on a day it falls behind (a burst of traffic, a brief outage), the batch job silently reads a partial dataset and nobody notices unless something is actively comparing the two paths' outputs. A DAG scheduler that is not natively aware of streaming completeness (most are not, out of the box) needs that awareness built as an explicit custom sensor or dependency, which is real additional engineering work, not something that comes for free just by having both an orchestrator and a stream processor in the stack.
Unlock Full Question Bank
Get access to all 46 ML Feature Pipelines and Feature Stores interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.