Microservices Dependency Graph for Distributed Systems
A small service change can trigger retries, stale events, and a 2 a.m. incident because nobody saw the consumer three repos away. A microservices dependency graph makes those paths visible before your AI assistant edits the “obvious” file.
What matters is not a pretty diagram. You need callers, handlers, topics, shared stores, and config-driven routes tied back to real code, so blast radius is something you can inspect instead of guess.
Start by checking:
- Which endpoints and event consumers reach the changed code
- Where retries, fan-out, or shared data extend the failure path
- Whether a suspected dead handler is still reachable
Change with a bounded risk.
Why Distributed Systems Make Dependency Blind Spots Expensive
You've seen this one. A small change lands in Order Service. The unit tests pass, the PR looks clean, and twenty minutes later a downstream worker starts retrying itself into a small fire because an event shape changed in a way nobody noticed.
That kind of failure isn't rare in microservices. It's normal when the real dependency map exists half in code and half in human memory.
A single repo app can still be messy, but at least most of the mess lives in one place. Distributed systems scatter it everywhere:
- request handlers in one repo
- generated clients in another
- queue consumers nobody has touched in eight months
- environment variables that quietly point traffic somewhere unexpected
- traces, dashboards, runbooks, and tickets that explain just enough to be dangerous
This is why architecture visibility for microservices is harder than plain package dependency mapping. You're not asking "what imports what?" You're asking "what can this change wake up at runtime, who owns the fallout, and what still exists only because nobody can prove it's safe to remove?"
The costs show up in boring, painful ways:
- PR reviews drag because reviewers can't see downstream callers or hidden consumers
- refactors stall when a late-stage consumer appears from another repo
- AI coding assistants make locally sensible edits that ignore system behavior
- dead code survives because "probably unused" isn't enough when a topic consumer might still be live
If you can't see both code level microservice relationships and service level behavior, every change feels bigger than it is. That uncertainty is expensive. It slows good teams down and makes average teams nervous.
What a Microservices Dependency Graph Actually Represents
A microservices dependency graph is a living map of how a distributed system actually connects. Not the slide-deck version. The one you'd want in front of you before touching a shared endpoint or deleting a suspicious handler.
A useful graph includes more than services. It needs nodes for the things changes actually move through:
- services and service modules
- endpoints and handlers
- message topics, queues, and subscriptions
- scheduled jobs and background workers
- databases, caches, and external systems
- shared packages, SDKs, and internal libraries
- integrations selected by environment variables, secrets, or feature flags
The edges matter just as much as the nodes. In practice, you need to distinguish at least a few different kinds:
- synchronous request edges such as HTTP or gRPC
- asynchronous publish and consume edges
- shared data edges where multiple services read or write the same store
- code ownership or import edges
- config edges where a service needs a secret, URL, or flag to reach another system
That distinction is not decoration. A graph that treats every relationship the same becomes pretty fast and useful slow.
Build the graph for questions, not for aesthetics.
Code level microservice relationships are the bridge between architecture diagrams and real implementation. If an endpoint calls a wrapper, which resolves a generated client, which publishes an event after a database write, that path is the work. That's what engineers change. That's what AI assistants need to inspect before editing files.
A good graph should answer practical questions without ceremony:
- What will this change affect?
- Who depends on this endpoint or event?
- Is this code path still reachable?
- Where can failure propagate next?
If it can't answer those, it's a catalog. Not a dependency graph.
Build-Time Dependencies and Runtime Dependencies Are Different Graphs
Teams get into trouble when they confuse "connected in code" with "connected in production." Those are related, but they are not the same graph.
Build-time dependencies include the structural pieces you can extract statically:
- package imports
- shared libraries
- generated clients
- schema packages
- module references across repos
That graph tells you what can compile together. It's useful. It catches coupling that sneaks in through shared code, and it helps explain why a change in one library fans out across a lot of build pipelines.
Runtime dependencies are the edges that actually carry work and failure:
- live service calls
- published and consumed events
- queue fan-out
- retries and fallback paths
- cross-service reads and writes against shared data
That graph tells you what can fail together.
Here's where teams get misled. A service may import almost nothing shared, yet call five downstream services in a hot request path. The build-time graph looks tidy. The runtime graph says otherwise. The reverse happens too: a generated client package may appear everywhere in the repo, but only one path is active in production.
Event-driven coupling makes this worse because it often disappears from build-time analysis entirely. The publisher doesn't import its consumers. The consumers may live in different repos. The only honest answer lives in a merged view.
Service dependency mapping needs both sides in one place. Otherwise your refactor plan, your reliability work, and your PR review each run on a different mental model. That's how teams talk past each other for a week.
| Graph | Includes | Tells You | Section Example |
|---|---|---|---|
| Build-time dependencies | package imports; shared libraries; generated clients; schema packages; module references across repos | what can compile together; shared-code coupling; why one library change fans out across build pipelines | a generated client package may appear everywhere in the repo even though only one path is active in production |
| Runtime dependencies | live service calls; published and consumed events; queue fan-out; retries and fallback paths; cross-service reads and writes against shared data | what can fail together | a service may import almost nothing shared yet still call five downstream services in a hot request path |
| Merged view | build-time and runtime dependencies in one place | the honest answer for refactor planning, reliability work, and PR review | prevents teams from running on different mental models and talking past each other for a week |
The Relationship Types You Need to Capture in a Real System
If the graph only shows service-to-service lines, you're still too far from the truth. Real systems fail along more specific edges.
Synchronous calls
These are the easiest to recognize and the easiest to oversimplify. A request edge needs direction, the calling entry point, and enough context to know whether it's on a critical path.
For example, Order Service calling Payment Service during checkout is not the same kind of edge as an occasional admin lookup. Latency budgets, timeouts, retries, and circuit breakers all hang off that difference.
Short version: who calls whom is not enough. You need to know from where and under what path.
Asynchronous events
Publish and consume edges are where graphs usually get thin. That's a mistake.
One event can fan out to several consumers, some immediate, some delayed, some added months later by another team. A schema change can break consumers you don't know about because the initiating service never sees them directly.
This is where microservices blast radius analysis often falls apart. The request returns 200, everyone relaxes, and the actual break shows up six minutes later in a worker nobody checked.
A measurement caveat: match the graph to the outcome
A trace-derived model tested with chaos experiments on the OpenTelemetry Demo found that treating Kafka edges as non-blocking changed predicted immediate HTTP endpoint availability by at most 0.001 percentage points. In that study, the simpler connectivity model was therefore sufficient for that narrow, immediate-response SLO. The study did not measure eventual event processing, delayed worker failures, or contract compatibility.
That does not make consumer mapping optional. It means a graph should label asynchronous edges clearly enough to query the right question: an immediate checkout response may have a different dependency set from eventual fulfillment, notification, or analytics correctness.
Shared data dependencies
Shared persistence is often stronger coupling than an API call. Two services touching the same table, stream, or cache can interfere with each other even if they never talk over the network.
Backfills are a classic trap here. One service changes write behavior, another relies on old assumptions, and the graph that ignored shared data claims everything is isolated. It isn't.
Operational and human dependencies
Some paths only exist if the right config exists:
- secrets
- environment variables
- feature flags
- service discovery settings
Code may say a call is possible. Production config decides if it actually happens.
Then there are ownership boundaries. A change that crosses three teams is not low risk just because the diff is small. Good graphs carry enough metadata to support coordination, not just code traversal.
Label edges by type, direction, and confidence. If one edge comes from static analysis and another is runtime-confirmed, keep that distinction. Mixed evidence is better than false certainty.
How to Map Dependencies in a Microservices Codebase
Start narrower than you want. Teams fail here by trying to map the whole estate before they can answer one useful question.
First, set the system boundary. Are you mapping one repo, a monorepo, or multiple repos? Are payment, email, and identity providers first-class nodes or just comments off to the side? Be explicit or your graph drifts into hand-wavy territory.
Then work outward from entry points:
Codebase mapping sequence
- Entry points
Inventory HTTP and gRPC handlers.
- Background paths
Add queue consumers, cron jobs, workers, and CLI tasks.
- Outbound tracing
Trace outbound connections from those paths.
- Systems touched
Capture data stores and external systems touched along the way.
When you're tracing outbound behavior, don't stop at obvious API clients. Real systems hide calls behind wrappers, service locators, generated clients, and helper packages with innocent names. We've seen teams miss half the graph because they only searched for raw HTTP usage.
You'll also need config-derived edges. Topic names, endpoint URLs, provider keys, failover targets, and traffic-switching flags often come from environment variables. If you skip them, the map looks cleaner and gets less true.
A practical workflow for how to map dependencies in a microservices codebase looks like this:
- extract build-time edges from imports, modules, schemas, and generated clients
- extract code-level call paths from handlers, publishers, consumers, and data access points
- resolve names so "orders-api", "order-service", and "svc-order" become one stable entity
- attach edge direction and context
- reconcile static evidence with logs, traces, or deployment metadata when you have it
Freshness matters more than diagram quality. A stale architecture diagram is worse than no diagram because people trust it right up until it burns them.
This is where automation stops being nice to have. Pharaoh is one approach we built for exactly this problem. It maps repositories into a knowledge graph so AI coding assistants and engineers can inspect architecture, callers, endpoints, environment variable usage, blast radius, and dead code before changes are made. It's most useful in multi-module or multi-repo systems where context is spread out and change moves fast.
A Worked Example: Dependency Mapping for an Order Flow
Let's keep it concrete. Say your order flow includes:
- API Gateway
- Auth Service
- Cart Service
- Order Service
- Payment Service
- Inventory Service
- Notification Worker
- Event Bus
The synchronous request path might look like this:
API Gateway -> Auth Service
API Gateway -> Order Service
Order Service -> Payment Service
Order Service -> Inventory ServiceThat path is only part of the story. Once the order succeeds, Order Service publishes OrderPlaced to the Event Bus:
Order Service -> Event Bus(topic: OrderPlaced)
Event Bus -> Notification Worker
Event Bus -> Analytics Consumer
Event Bus -> Fulfillment WorkerNow add shared data and config edges:
- Payment Service depends on a provider API key from environment configuration
- Inventory Service and Fulfillment Worker both rely on the same stock data source
- a feature flag may route payment requests to a backup provider
A simple sequence diagram will show the checkout request. It will not show the hidden fan-out after the response returns, the old consumer still listening to a deprecated event, or the retry path that duplicates downstream work when Payment Service times out and Order Service retries without proper idempotency.
That's the difference.
If you turn this into a visual figure, make the node types obvious. Use separate shapes or labels for services, topics, data stores, and config nodes. Keep edge direction visible. Mark synchronous and asynchronous edges differently. If every line looks the same, the picture lies.
How a Dependency Graph Changes Blast Radius Analysis
Microservices blast radius analysis is just pre-change impact estimation with less guessing. Engineers care about it when the change looks small and the risk isn't.
Common triggers are familiar:
- changing an endpoint contract
- renaming or removing an event
- editing shared auth or tenancy logic
- replacing a client library
- deleting code that appears dead
A good graph breaks the blast radius into layers.
First layer: direct callers and consumers. Who invokes this endpoint? Who subscribes to this topic?
Second layer: fan-out and side effects. If one consumer writes to a shared store or emits another event, who depends on that?
Third layer: behavior under failure. Do retries duplicate work? Does a cache mask the break for an hour? Does a fallback route traffic somewhere with different assumptions?
Then there's coordination. Which teams need to know before this merges? This is where many reviews are too optimistic. Code risk and coordination risk are not the same thing.
Event-driven systems hide the largest blast radius in the quietest places.
Pre-change review gets sharper when the graph can answer a few blunt questions:
- who calls this directly
- who consumes the side effects
- what becomes unreachable if we remove this
- what tests cover those paths
- what fails open and what fails closed
This matters even more with AI coding assistants. Fast suggestions are only useful if the assistant can inspect downstream callers, consumers, and dead code risk before it edits anything. Without that context, you're just getting speed without judgment.
What Good Architecture Visibility for Microservices Looks Like in Practice
Architecture visibility for microservices should show up during normal work. Not during a quarterly architecture review. Not in the week after an incident.
If a senior engineer reviewing a PR can't answer "who else depends on this?" in under a minute, the system is still too opaque.
Good visibility changes the daily workflow:
- refactors start with actual dependents instead of guesswork
- PR reviews include downstream impact, not just local diff quality
- incident response traces failure propagation faster
- dead code cleanup becomes evidence-based
- onboarding gets less dependent on whoever happens to be online
- Claude Code, Cursor, Codex, and other MCP clients can query architecture before they propose edits
The shift is from static documentation to queryable context. Instead of reading four repos and slacking two people, you ask the graph. Instead of carrying broad fear about a shared service, you scope the real risk.
Cross-repo visibility is where this gets serious. In many systems, the publisher and consumer for the same event don't live anywhere near each other. If your tooling stops at one repo boundary, your confidence should stop there too.
Pharaoh works across multiple repos and updates mappings on every push, which helps when service relationships change faster than docs ever will. But the larger point isn't the tool. It's trust. Visibility only matters if engineers are willing to use it during reviews and refactors, when time is short and patience is shorter.

Common Mapping Mistakes That Make the Graph Misleading
Most bad graphs fail in predictable ways. The annoying part is they often look polished.
Watch for these:
- treating imports as the whole story and missing network calls, topics, and workers
- skipping asynchronous paths because they're harder to trace
- modeling service-to-service edges without endpoint or handler detail
- ignoring environment-variable-driven integrations and flag-based alternate routes
- maintaining diagrams by hand until they drift past usefulness
- dropping edge direction, which kills upstream versus downstream reasoning
- collapsing all relationships into one edge type
- leaving out external providers, where outages often begin
- confusing possible dependencies with active ones and not marking confidence
One mistake deserves extra attention: service-level maps without code-level anchors. They feel executive-friendly and engineer-hostile. If the graph can't lead you to the actual handler, publisher, or consumer, it won't help when the PR is open and the clock is ticking.
How to Evaluate Tools and Approaches for Service Dependency Mapping
Different approaches solve different slices of the problem.
Hand-drawn diagrams are quick to start and quick to rot. They're fine for discussion. They're weak as decision tools.
Service catalogs tell you what exists and who owns it. Useful, but ownership is not dependency.
Tracing tools show runtime paths well, especially hot paths during incidents. They can miss dormant code, rare workflows, and consumers that didn't fire during the observed window.
Static analysis and code graph tools are strong on structure. They can find call sites, imports, generated clients, and reachable code. They can also overstate paths that aren't active in production.
Hybrid knowledge-graph approaches are usually the strongest fit for distributed systems because they connect code, service relationships, config edges, and change impact in one model. That's the part most teams are actually missing.
When evaluating options, ask blunt questions:
- Does it work across multiple repos?
- Can it represent synchronous and asynchronous edges?
- Can it support blast radius analysis before a PR merges?
- Can AI assistants query it directly?
- Can it identify dead code and unreachable paths?
- How fast does it refresh after code changes?
Pharaoh fits that hybrid bucket. It's MCP-compatible and built for larger repositories where engineers and AI assistants need architecture, callers, endpoints, config usage, blast radius, and dead code context before making changes. You get every piece of it during the trial, and Pro keeps it going. The important part is not the label. It's whether the approach helps you make a safer decision this afternoon, not six months from now.
How to Start Without Turning This Into a Six-Month Architecture Project
Don't start with "map everything." That's how this dies in committee.
Pick one workflow that changes often or breaks expensively. Checkout. Signup. Billing. Deploy orchestration. Something with real consequence.
On the first pass, map only:
- the services involved
- the entry points
- the outbound calls
- the event topics and consumers
- the shared data stores
- the config-based integrations
Then add the high-risk edges first. Auth and identity. Payment and billing. Shared schemas. High-fan-out topics. The places where a "small change" usually isn't.
Use the graph immediately in real work:
- before a refactor sprint
- during a PR review on a shared service
- while checking whether code is actually dead
- before letting an AI assistant make a cross-service edit
Set one hard rule: if the graph isn't refreshed with code changes, don't treat it as a decision tool.
If you're already using AI coding assistants, the next step is straightforward. Add a codebase graph through MCP so the assistant can inspect dependencies before proposing changes. That's where this shifts from documentation to operational safety.
Perfect architecture documentation is not the goal. Better decisions under change is the goal.
Conclusion
A microservices dependency graph earns its keep when it captures the relationships distributed systems actually run on: synchronous calls, asynchronous events, build-time structure, runtime behavior, shared data, config edges, and failure paths.
That gives you clearer service dependency mapping, better architecture visibility for microservices, and more reliable microservices blast radius analysis. It also gives AI coding assistants the context they need to be useful without being reckless.
Pick one high-change workflow this week. Map the direct callers, event consumers, shared data edges, and config-based integrations. Then use that graph in your next PR review before the change ships. That's where the value shows up. Not in the diagram. In the decision.
Article Record
ReferencesPrimary sources used for this article
- Generate microservices dependency graph for your applications
- Service Graph · Haystack
- Visually Analyzing Company-wide Software
- JCallGraph: Tracing Microservices in Very Large Scale Container Cloud Platforms
- Evaluating Asynchronous Semantics in
- Removing dependency tangles in the Atlassian Platform for increased reliability and recoverability - Inside Atlassian
- From distributed tracing to proactive SLO management: a mini-review of trace-driven performance prediction for cloud-native microservices
- Monoliths to Microservices: