Exercise 2: Deployment Order With a New Logging Service — Possible Solution ==================================================================== GIVEN ------------------------------ This chapter's own Step 4 graph: auth->api, database->api, cache->api, api->frontend, api->notifications New edge: api->logging (nothing depends on logging in return) STEP 1: IN-DEGREES AT THE START ------------------------------ auth: 0 (nothing points to it) database: 0 (nothing points to it) cache: 0 (nothing points to it) api: 3 (incoming from auth, database, cache) frontend: 1 (incoming from api) notifications: 1 (incoming from api) logging: 1 (incoming from api - the new edge) STEP 2: RUN KAHN'S ALGORITHM ------------------------------ Initial queue (in-degree 0): auth, cache, database Process auth: output auth. No effect on any in-degree (auth's only edge goes to api, which stays at in-degree 2 for now). Wait - auth->api exists, so processing auth decrements api's in-degree from 3 to 2. Process cache: output cache. Decrements api's in-degree from 2 to 1. Process database: output database. Decrements api's in-degree from 1 to 0 - api joins the queue. Process api: output api. Decrements frontend, notifications, and logging each from 1 to 0 - all three join the queue. Process frontend, notifications, logging (in that order): output each in turn. No further edges to decrement. RESULT ------------------------------ Valid deployment order: auth, cache, database, api, frontend, notifications, logging logging slots in alongside frontend and notifications as one of api's three dependents, all three becoming deployable at the exact same moment - the instant api itself finishes deploying - since none of the three have any dependency relationship with each other. WHY THIS WORKS AS AN ANSWER ------------------------------ Every service's in-degree is computed correctly including the new logging service and api's own updated in-degree of 3, and Kahn's algorithm is traced step by step exactly as this chapter's own method specifies - a service only joins the queue the moment its in-degree reaches zero, not before.