Video in progress

You have 300 microservices and their dependencies. How do you use graph algorithms to analyze deploy order, cycles, and "if one service goes down, who suffers"?

I model the dependencies as a directed graph. I find the strongly connected components with Tarjan or Kosaraju; those are the cycles. I collapse the cycles into single nodes to get a DAG and derive the deploy layers with a topological order. The blast radius is a BFS on the reversed graph.

📖 Answer

The source of the graph matters. The "who calls whom" list in a config is usually out of date. I assemble the real call graph from distributed tracing (OpenTelemetry) data and compare it with the declared one; the differences themselves are interesting findings.

Let's start with cycles. A → B → C → A is usually an architecture smell: they can't be deployed separately, and they're really a single distributed monolith. Tarjan's algorithm finds all the SCCs in a single DFS in O(V+E). For a graph with 300 nodes, that's milliseconds.

Deploy layers. After collapsing the SCCs, the graph is a DAG. I run Kahn's algorithm layer by layer: the first layer is the ones that depend on nothing, and they deploy in parallel. The number of layers is the longest path, which is the minimum deploy time. That's the critical path: slow deployment of a service on that chain makes everyone wait.

Blast radius. Reverse the edges and run a BFS from payments: every service that depends on it directly or indirectly. This list shows whom to notify during an incident and which services should have a degraded mode.

To look for single points of failure, use articulation points in the undirected version: nodes whose removal splits the graph apart. Often these are auth, the config service, or the "common" library service everyone uses.

All of this is algorithmically easy. The hard part is turning the results into action:

  • if a new cycle appears in CI, the PR is blocked (ArchUnit within modules, traces between services);
  • for the top-10 services by "most dependents", check that each has timeouts, a circuit breaker and a fallback;
  • rebuild the graph weekly and watch the trend: a service whose out-degree keeps growing is the next problem candidate.

I mark synchronous calls and asynchronous (through Kafka) dependencies separately in the graph. An asynchronous edge doesn't affect deploy order, but it does affect data schema compatibility.