Exercise 2: Highest-Value-Wins Reconciliation — Possible Solution ==================================================================== THE NEW STRATEGY ------------------------------ winner_node = node_a if node_a.data['stock'] > node_b.data['stock'] else node_b Instead of comparing timestamps (this chapter's own last-write-wins), this strategy picks whichever node's own recorded value is numerically larger. RESULT ------------------------------ highest-value-wins picks: A - final stock = 45 true combined value: 37 discrepancy: 8 Since node_a's value (45) is larger than node_b's (42), highest-value- wins picks node_a - discarding node_b's own recorded sale entirely, the mirror image of what last-write-wins did (which discarded node_a's sale). COMPARING TO THIS CHAPTER'S OWN LAST-WRITE-WINS RESULT ------------------------------ last-write-wins: final = 42, discrepancy = 5 highest-value-wins: final = 45, discrepancy = 8 Highest-value-wins is actually WORSE here - a bigger discrepancy from the true combined value (8 vs. 5), not better. This is not a coincidence specific to a badly-chosen strategy; it's a structural result: for a value that only ever DECREASES from real events (stock being sold), "highest value" always picks the write representing the FEWEST real sales - systematically the worst possible choice for this specific kind of data, since it discards whichever conflicting update recorded the MOST real-world change. WHY THIS CONFIRMS RECONCILIATION STRATEGIES AREN'T INTERCHANGEABLE ------------------------------ This chapter's own text already showed one strategy (last-write-wins) losing real information. This exercise confirms a second, plausible- sounding strategy loses MORE information for this specific kind of data - proving there's no universally "safe" reconciliation choice. The right strategy depends entirely on what the conflicting values actually represent: for a monotonically-decreasing quantity like stock depleted by sales, neither strategy tested here is actually correct - the genuinely correct reconciliation would need to UNDERSTAND that both writes represent real, additive decreases (a sum, not a pick), which neither last-write-wins nor highest-value-wins attempts to do. WHY THIS WORKS AS AN ANSWER ------------------------------ The new strategy is implemented and tested against this chapter's own exact scenario, its result is directly compared against this chapter's own last-write-wins figure rather than reported in isolation, and the counter-intuitive finding (this strategy performs worse, not better) is explained by tracing the specific reason it systematically picks the wrong node for this kind of decreasing-value data.