AI-Assisted Coding Lab · Compare Shadow Reads Before a Cutover

45:00left of 45:00

Compare Shadow Reads Before a Cutover

Accounts are moving to a new datastore, and the decision to cut over will rest on a shadow comparison running in production. The README has the rules and what each one protects. Build shadow.py with the assistant, and judge each suggestion by whether the number it produces can be trusted and what it risks on the login path.

shadow.py1 of 3

Files

shadow.py

Python · Editable
class ShadowReader:
"""Serves reads from the current store, and compares a sample with the new store before cutover."""
IGNORED = {"updated_at"} # the new store keeps milliseconds, the old one seconds
def __init__(self, current, candidate, sample_rate, rng, log):
self.current = current
self.candidate = candidate
self.sample_rate = sample_rate
self.rng = rng
self.log = log # log(event, **fields) ships to the logging vendor
self.stats = {"compared": 0, "mismatched": 0, "errors": 0}
def get(self, key):
record = self.current.get(key)
return record
def _shadow(self, key, record):
raise NotImplementedError
def _compare(self, key, record, other):
self.stats["compared"] += 1
raise NotImplementedError
def mismatch_rate(self):
"""The cutover gate. A read the candidate failed counts against it."""
raise NotImplementedError

Test Output

No runs yet.

Assistant

Scripted
  1. Send the first prompt to start.

Next Prompt

Shadow sample_rate of the reads.