Exercise 3: Extending the Chain to Four Services — Possible Solution ==================================================================== THE NEW SERVICE AND THE EXTENDED CHAIN ------------------------------ def service_d(should_be_slow): if should_be_slow: time.sleep(0.3) return 'D says OK' def service_c(should_be_slow): result_d = service_d(should_be_slow) # C now calls D synchronously return f'C got: {result_d}' # service_b and service_a are UNCHANGED from this chapter's own code service_c is the only existing function that needed editing - it now calls service_d instead of returning its own fixed string, following the exact same "call synchronously and wait" shape as every other link in this chapter's own chain. VERIFYING THE FAST BASELINE ------------------------------ all fast - A total: 0.0 ms VERIFYING A SLOWDOWN THREE HOPS AWAY STILL REACHES A ------------------------------ Making ONLY service_d slow (service_c itself stays fast - it has no sleep() call of its own): only D slow (300ms, three hops away) - A total: 300.4 ms result: A got: B got: C got: D says OK service_a's total response time is still ~300ms, matching this chapter's own two-hop result almost exactly, even though the slow service is now one hop further away and two intermediate services (service_b and service_c) are both individually fast. WHY THIS CONFIRMS THE CHAIN LENGTH DOESN'T MATTER, ONLY THE WAITING ------------------------------ This chapter's own two-hop chain and this exercise's three-hop chain produced essentially the same total delay (300.3ms vs 300.4ms) despite the slow service moving further from A. That's because every link in a synchronous chain WAITS for the one below it before returning anything - the total delay is the SUM of however many links are slow, not diluted by how many fast links sit in between. A chain of ten synchronous hops with one slow service anywhere in it would show the same result: whichever service is slow, its delay reaches every caller above it in full, regardless of how many hops separate them. WHY THIS WORKS AS AN ANSWER ------------------------------ The new service and modified link follow this chapter's own established chained-call shape exactly, and both the fast-baseline and slow-case results are verified directly and compared against this chapter's own original two-hop numbers - showing the underlying finding generalizes to a longer chain rather than being specific to exactly two hops.