ORIGINAL COMPANY-CONTEXT PRACTICE
Apply corrected meter readings deterministically
Original practice scenario inspired by NextEra Energy, Inc.'s public business context; this is not a reported interview question or a description of its internal systems. A synthetic meter pipeline receives readings with meter_id, interval_start, revision, and value. Messages arrive out of order and may be duplicated. Explain the update rule and the tests needed for a reliable materialized view.
Written for independent practice using company context; this is not a verified question from a company interview.
A REASONED APPROACH
Model answer.
Use meter and interval as the business key, then accept only the highest valid revision for that key. Delivery order should not determine the final reading when explicit revisions exist.
Work through it
- Validate units, interval alignment, and revision type before updating. Define what to do when two payloads have the same revision but different values.
- Apply a conditional atomic upsert that replaces an older revision and ignores an identical replay. Retain an audit record of accepted corrections.
- Test reversed arrival order, repeated messages, equal-revision conflicts, negative corrections where allowed, and a crash during update. Replaying the same set should produce the same view.
Tradeoffs to discuss
- Keeping raw events and current state costs more storage but permits reconstruction and correction analysis. A quarantine path handles contradictory revisions without silent overwrite.
Common pitfalls
- Using ingestion timestamps as versions makes replay order significant.
- Rejecting all duplicate keys would discard legitimate later corrections.