Exercise 2: Deliberately Breaking the Shared-Core Guarantee — Possible Solution ==================================================================== THE BROKEN WIRING ------------------------------ quote_engine = PricingEngine(RealInventoryAdapter({'PROD-1': 50}), LoggingNotificationAdapter()) # sees fresh stock order_engine = PricingEngine(RealInventoryAdapter({'PROD-1': 5}), LoggingNotificationAdapter()) # sees stale, low stock order_service = OrderService(repository, order_engine, event_bus) # uses the STALE engine quoted_price = quote_price_via_api(quote_engine, 'PROD-1', 100, is_loyalty_member=False) actual_price = order_service.place_order('ORD-3', 'PROD-1', 100, 'USER-3', is_loyalty_member=False) Two SEPARATE PricingEngine instances are constructed, each with its own RealInventoryAdapter reading different stock data - simulating a real scenario where the quote API's own view of inventory (50, fresh) has drifted out of sync with the order-processing flow's own view (5, stale), because they were never actually sharing one source of truth in the first place. VERIFYING THE DISCREPANCY REPRODUCES ------------------------------ quoted price (via quote_engine, stock=50): 100 actual price (via order_engine, stock=5): 115.0 match: False discrepancy: 15.0 The customer was quoted $100 (no scarcity pricing, since quote_engine saw plenty of stock) but was actually charged $115.0 (scarcity pricing applied, since order_engine saw only 5 units) - a genuine, verified $15.00 discrepancy for the identical product and the identical base price. WHY THIS IS THE SAME BUG AS CHAPTER 8'S, ONE LEVEL DEEPER ------------------------------ Chapter 8 verified two independently-implemented CLIENT-side pricing functions disagreeing by $0.50. This exercise reproduces the identical failure mode entirely on the SERVER side: two technically-identical PricingEngine classes, running the exact same code, still disagree - not because the logic differs, but because the DATA each one sees differs, and nothing enforces that both engines stay in sync. This confirms this chapter's own ADR-007 was addressing a real risk, not a hypothetical one - "two separate implementations" and "two separate instances with drifted data" are both instances of the same underlying problem: no single source of truth. WHY THIS WORKS AS AN ANSWER ------------------------------ The broken version is constructed by deliberately reversing this chapter's own "one shared instance" decision - using two separate PricingEngine objects instead of one - and the resulting discrepancy is verified directly with a specific dollar amount, rather than only asserted to exist.