Ch.38: System Design: The Price Drop Alert That Lied
Outline
- 0:00 The zero-dollar alert
- 1:05 The extracted number is not truth
- 2:15 What the product must do
- 3:08 Fresh, fair, and unwilling to lie
- 3:45 Follow the trust boundaries
- 5:05 Quarantine the cohort, not the store
- 6:21 Bind the watch to the exact offer
- 7:11 Schedule one listing, not millions of timers
- 8:09 Give every source a budget
- 8:51 Store evidence before parsing
- 9:34 Fence stale workers from declaring truth
- 11:00 Alert on a threshold transition
- 11:56 Survive flash-sale fanout
- 12:50 Replay the lie and the real sale
- 13:51 Return to the trusted architecture
Transcript
0:00 Mia's phone lights up: “Price drop. Headphones now 0 dollars.” She opens the product page. It still shows the regular price. The alert is wrong. Nothing was free. A page template changed; our extractor read an absent field as zero. Now every watcher at that store is about to receive the same lie. Missing one discount hurts. Turning one parser defect into millions of confident lies is worse. How do we stop it before it spreads to every watcher? Right. A number earns authority only after it is bound to Mia's offer and survives validation. Until then, every extracted number is only a claim; it cannot update history or wake an alert.
0:40 Okay. Put the whole path on screen for a moment. Watches and shared scheduling sit on the left. Saved evidence and verification sit in the middle. Trusted history, threshold state and delivery sit on the right. We will follow Mia across those boundaries, then bring back this exact map. By then, we should know why the parser's false zero stops and a genuine sale still gets through. Before those trust boundaries exist, a system-design candidate may say, “One cron per watch: fetch, parse, compare, alert.” That was my first thought on a whiteboard too.
1:14 Where does it start lying? It wastes work before it lies. In this fictional example, 50 people watch the same headphones, so one listing gets fetched 50 times. Worse, the parser can actually collapse distinct offers into one number: public, member-only or another storage size. The clean number is what makes it dangerous: we've all relaxed when a parser returns one, though it may describe the wrong offer. Google's merchant-listing documentation distinguishes active, crossed-out and member prices; our watch separately binds the exact product variant.
1:48 So we need three definitions. A candidate is what one parser claims it found, tied to the raw response. An accepted observation is a candidate that matches the bound offer and passes validation. A watch rule is Mia's exact offer-and-threshold test. That shortcut is familiar: if parsing returned a number, call the job successful. Here, that is the bug. Proof status keeps the stages apart: extracted, then validated, then evaluated. Those definitions lead to Mia's functional requirements. For example, changed retailer markup makes her extractor propose zero; validation quarantines the claim, and Mia keeps the prior trusted value under a stale badge instead of receiving a false alert. What detail should that badge add?
2:29 Oof. Show the last trusted value, visibly stale, with its observation time. The badge is disappointing, but honestly, it beats being awakened for imaginary free headphones. Right. That timestamp is what lets her trust the stale badge. She can manage the exact watch and receive one logical alert only when a validated offer crosses her rule. On-call needs a different promise. Yes. A trail showing why each candidate was accepted, quarantined or superseded. That trail closes the loop. Our contract ends with the durable alert record; channel delivery is separate. A stale product is frustrating, but its freshness claim must remain true.
3:07 That product scope raises the non-functional requirements. Now make the promise survive our fictional worst day. The queue slips past 5 minutes while Red throttles. What reaches Mia, and does Blue suffer too? Mia sees the last accepted price marked stale. Reserve capacity per source so Red cannot starve Blue. At our fictional 5,000-check-per-second peak, Red's queue may fall behind; Mia's badge tells the truth while Blue's checks continue. That makes the contract harsher: latency may degrade, but truth may not.
3:40 A retry cannot advance trusted history twice or duplicate a logical alert. Now the requirements and targets tell us how to read the map. A trust boundary is where data gains new authority. Follow Mia. Her watch is stored once and bound to one retailer listing, shared by everyone watching that offer. When due, the scheduler creates one stable check through that retailer's queue. Wait. The fetch worker still does not actually get to name the price. Let's hear it: exactly where does zero lose authority?
4:10 First in the evidence store. Save the response before interpreting it; that boundary lets one fetch survive a parser rollback. A versioned extractor creates a candidate. Validation can reject it, quarantine every candidate from that parser release or accept the next observation. Suppose it passes. How does that fact survive a crash between storage and alerting? The observation and an outbox row commit together. If storage succeeds and the relay crashes before publish, that row survives; restart retries the same observation ID.
4:41 Only this accepted observation may compare Mia's trusted price with her threshold. If a sale matches two million watchers, alert rows are written in resumable chunks. Now I see why you called these trust boundaries. Each stop changes who may claim what: a response becomes evidence, evidence may become a candidate, and only a validated candidate may advance the trusted price. That validation boundary is where Mia's zero must stop. The extractor misses the active-price field and emits zero. Local checks catch missing currency or the wrong variant.
5:14 But a real promotion can also look extreme. How do we tell a broken parser from a real clearance sale? I wouldn't claim a universal magic percentage; that would be false precision. For example: release 42 reports zero across thousands of unrelated products. Quarantine it while replay tests it. The pattern indicts that parser cohort; it does not prove every surprising price is wrong. Hold on. If I run an alternate parser over the same payload and it agrees, is that independent evidence? No. Two parsers may share a blind spot.
5:47 Independent comparison needs separate provenance, meaning a separately controlled source or representation, such as a retailer feed or another approved path. Agreement across a bounded sample can clear a legitimate broad promotion. Oh, right. Same payload, potentially the same blind spot. And if no separate path exists? Leave the prior value stale, roll back and inspect the replay before a fresh authorized check. One strange thermometer may be right; a whole new batch failing together indicts the instrument.
6:17 The quarantine contains that one parser release. Now the cohort check narrows into Mia's offer. The same product page sells her headphones and a cheap charging cable. What must the watch name so that cable cannot impersonate her deal? Variant, merchant, currency, quantity and offer class. If Mia wants the public one-unit price, a member-only offer or a pack of two cannot satisfy it. That identity is the comparison key. A candidate missing any part stays outside Mia's trusted history. I mean, that's a nasty bug: the number is plausible, but it belongs to the wrong product.
6:52 So the rule is an offer identity plus a comparison. It also gets a version. If Mia changes the threshold or switches to member pricing, an in-flight evaluation cannot use the version she replaced. Now one shared listing can safely serve 2000 watches without mixing the products they meant. That exact offer creates the next scale question: 2000 people watch one listing. Do we really fetch it 2000 times? No. Keep one due record per listing, then let one accepted observation evaluate all 2000 rules.
7:25 A managed scheduler exposes the same trap: Amazon EventBridge sets separate quotas for stored schedules and invocations. Remembering work is not firing it. Ugh, we've all watched a clean hourly schedule become one ugly wall of spikes. For example, a million jobs wake together like a stampede with a cron expression. How do we spread them and survive a publish timeout? In one transaction, claim the listing under a short lease, an ownership window that expires if the worker stalls. Move its next-check time by a small random offset and record one stable dispatch ID.
8:00 If queue publication times out, retry with that ID; downstream sees one logical check, so Mia never receives a duplicate evaluation. That durable dispatch raises a source-boundary question. When Red exhausts its budget, what happens? Red's checks wait and Mia's Red price turns stale; Blue keeps reserved fetch slots. We wait instead of dodging Red's limit through another route. Fine. Can an approved call at least avoid hauling the whole unchanged page? Yes. For instance, send the prior ETag as an opaque change marker.
8:32 If the server returns 304 Not Modified, it sends no response body, so the parser receives no price claim to misread as zero. Ah, then no candidate is created. The request may still count toward quota, but throttling becomes visible staleness for Red instead of a fabricated price. That bodyless check points to the next rule: save what Red actually sent before parsing. Which evidence settles whether the retailer sent zero or our extractor invented it? The retained body itself. If it contains the normal displayed value, the parser invented zero.
9:06 If the body contains zero, the source sent it. Keep its hash plus fetcher and parser versions so the replay names the exact input and code. Good. A repaired parser can run over that same response without another network call, while the old candidate stays quarantined. Replay answers the incident without refetching Red. Yes. Retrieval remains durable; interpretation stays replaceable. The incident runbook has Mia's evidence, a named parser version and a claim barred from trusted history. Now saved evidence tells us which input we saw; fencing tells us which worker may speak now.
9:39 Walk me through it: how can a cheaper result be valid yet forbidden from alerting? Picture two workers. Worker One claims generation seven, then stalls past its lease. Worker Two claims generation eight and finishes. The listing's fenced generation is now eight. When One returns, seven remains evidence but cannot move current price or publish. So generation eight gets the pen even if generation seven finishes later. Wait, the older lower-price result may be accurate but still barred from alerting?
10:09 Yes. The fence records authority, not arrival time. We may lose a short sale rather than send a late alert that was never proven current. She sees the previous accepted value marked stale until an authorized check lands. Oh, that stings. My instinct is to rescue that old low price. Now I'm realizing the fence decides which price may speak, but not whether the price and its event survive together. How do we bind those? One transaction stores the immutable observation, advances the pointer and writes an outbox record.
10:42 Think of one receipt with the price and its shipping label: after commit, both lines exist or neither does. A relay may publish twice after a timeout, but the observation ID stays stable. Consumers recognize the repeat, and only validated-price events reach threshold evaluation. That accepted event opens the next bug: Mia's prior price was above her rule and the new one is below. How do we avoid alerting every hour during the sale? Give each watch a small state machine. `Armed` is the alarm ready to sound; `Triggered` is that alarm latched after firing.
11:16 The first accepted price at or below the threshold writes the logical alert. So “still cheap” is not a new event; crossing the line is. Before changing state, compare the evaluated rule version with Mia's current one so an in-flight old rule cannot fire. Exactly. One transaction changes the state and writes an alert whose key names the watch, rule version and triggering observation. A retry reconstructs that same row. For Mia, the watch rearms only after an accepted price rises more than 5 dollars above her threshold. Another category may choose a different band, while delivery retries still cannot invent another durable alert. That unique alert key creates a different scale problem.
11:59 Take the legitimate flash sale from our scenario: one famous console drops below two million users' rules. A database engineer may push back: “One transaction means safe. Why not write all two million alerts there and commit the sale as one unit?” That can turn into a lock-and-log nightmare. A giant transaction can hold locks, bloat the log and fail as one unit. Treat the audience like numbered trays instead of one sealed crate. Process one range of watcher IDs, commit its alert rows and cursor, then take the next range.
12:31 Okay, the cursor is the label on the last finished tray. A worker stores it, crashes, and its replacement resumes there. If that tray repeats, stable alert IDs turn the duplicate writes into harmless conflicts. Bound concurrent chunks per listing, so the console sale cannot monopolize every alert worker. Now replay both incidents through the same design and make them choose different paths. Give me the fork, not every component. Where does the false zero stop? Its response survives as evidence, but the zero stays a candidate.
13:04 When unrelated listings move together under that deployment version, the cohort is quarantined. Mia's screen retains the proven number and labels it stale, while her rule state never receives the claim. Show me the recovery, then imagine the genuine sale taking the other path. Right. Repair the parser and replay the saved response. If it recovers the ordinary price, history refreshes without an alert. Later, an approved response proves the lower offer; observation and outbox commit together, one rule transition triggers and chunked fanout resumes safely after crashes.
13:36 That is the fork: the invented claim stops before truth. The sale reaches alerting because it proves each boundary. When a source throttles us, freshness degrades visibly. The system can be late, but it does not have to lie. Back on the opening map, which boundary actually saves Mia? No single one. Scheduling shares the work, saved evidence keeps the raw claim, validation grants authority and rule state creates one alert decision. So the map is a chain of custody for a price. Missing proof stays stale, even if a brief sale slips past.
14:11 Exactly. Mia receives the real 249-dollar sale without ever seeing the parser's 0: schedule the check, preserve the evidence, prove the offer, then notify. Thanks for listening to Learning Podcasts.