Every dependency edge is a claim, so make it carry its evidence

Our service catalog, a generated map of which service calls which, said that a front-end monolith called a Lambda function, and that Lambda only ever wakes up when a message lands on a queue. It has no HTTP surface at all. There is no function URL, no API Gateway route, nothing that accepts an inbound request. The call cannot happen. Production traces showed it anyway, and the catalog had written it down as a fact.

I had built the catalog so that people and coding agents could ask "what depends on this service" without reading fifty Terraform directories first. It covers roughly 160 services across about 40 repositories, and at the snapshot I am quoting here it held 418 directed dependency edges, meaning 418 recorded claims that service A talks to service B.

That false edge was the smaller of the two problems I found that week. The bigger one was that I had been treating one data source as ground truth when it was only a witness with a narrow field of view.

Config and traces are wrong in opposite directions

Every source of dependency information has a specific blind spot, and the blind spots do not overlap.

Configuration sees what is permitted, not what runs. A security-group rule that allows service A to reach service B is evidence that someone intended that call. It says nothing about whether the code path still exists. A client library listed in a package.json is stronger evidence, since a person had to import it, but a dead import is still an import.

Runtime traces see what ran, not what is quiet. If a service only calls another one during a monthly billing job, a 28-day trace window might catch it or might not, and a 7-day window will report the edge as absent. Absence in a trace window is not evidence of absence in the architecture.

I measured the gap rather than guessing at it. Of the 418 edges in the catalog, 266 had never been observed in a 28-day window of production traces. That is 64%. Some of those are dead code. Some are the monthly billing job. Nothing in the trace data distinguishes the two, so a service map built only from traces would have silently deleted almost two thirds of the graph and looked clean doing it.

The reverse case is smaller but sharper. 38 edges, about 9%, existed only in traces, with nothing in any configuration file declaring them. Those turned out to be older services reached by a hand-rolled HTTP call to a base URL, or through a reverse proxy. The calling repository contains literally zero mention of the target: no client library, no security-group rule, no shared contract. Configuration is structurally blind to them and always will be.

I did not expect two sources agreeing to be the minority case. Counting edges by which source found them, the biggest groups were 110 found only by the client-library scan, 98 only by Terraform, 89 by Terraform and confirmed in traces, 38 only in traces, and 30 by Terraform and the client-library scan together. Build this by intersecting sources and you ship a graph with under a third of the real edges in it.

How the edges get derived

Five separate programs derive the edges, one per kind of evidence. Each one reads a checkout of the cloned repositories and derives edges from it, with no language-model calls anywhere in the pipeline, so a rebuild is reproducible and a diff between two runs means something. I call them derivers, and the names below are the values that end up in each edge's sources field.

The Terraform deriver reads security-group rules and infers who is allowed to talk to whom. The SDK deriver is that client-library scan. It reads @company/*-sdk dependencies from each repository's root and per-app package.json, and maps the package to the service it targets. Two more read our ts-rest API contracts, which are TypeScript declarations of an HTTP interface shared by server and client: one learns what a service serves, the other finds the call sites. The fifth asks our tracing vendor for a count of spans grouped by peer service, the service on the other end of each call, over a 28-day production window.

The hard part is none of those five. It is the merge, which has to decide what to do when two sources disagree.

The first version believed the traces

My first merge treated the trace graph as the authoritative live view and configuration as supporting material. Edges carried a status from a six-value enum. An edge in both configuration and traces was confirmed-live. An edge in configuration with no traffic was intended-not-observed. An edge only in traces was observed-undocumented. Each edge also carried an observedCalls count, so you could see that a meetings API had made 280,000 calls to a users API in the window.

This felt right. It reads like a live system view rather than a pile of static declarations, and the numbers made it feel precise.

Both of those feelings were wrong, and I found out by using the thing.

The counts were off by about 2,900x

I was reviewing the catalog through its own query tool and cross-checking a number against the tracing vendor's own UI. For one API's inbound traffic, the catalog had reconstructed about 1,559 calls over 28 days from indexed spans. The real request-hit metric for the same service over the same window was about 4.5 million.

The catalog was counting indexed spans, and indexed spans are sampled. The sample rate is not uniform across services, which is the part that killed the idea entirely. If every service were undersampled by the same factor, the counts would still be a valid relative signal and I could label them as such. They are not, so comparing observedCalls between two edges tells you nothing reliable. A number that is wrong by three orders of magnitude, and wrong by a different amount per service, is worse than no number, because the reader assumes it means something.

The counts had a second problem. A language model does a lot of the reading here, pulling the catalog in over the Model Context Protocol. A field called observedCalls sitting next to a number will be read as traffic volume every single time, no matter what the surrounding documentation says.

The trace-only edges included things that cannot happen

The false edge I opened with has a mechanical explanation. Distributed tracing stitches a whole asynchronous chain into a single trace. A request hits the front-end monolith, the monolith publishes an event, the event lands in a queue, the queue triggers a Lambda several hops downstream, and every span in that chain shares one trace id. Group the spans by peer service and the far-upstream entry point looks like a direct caller of the Lambda.

The relationship between those two services is real. The word calls is the part that is wrong.

The fix is one condition in the merge, called isDirectlyCallable. A trace-only edge survives only if the target is a Fargate service or a Lambda that actually serves an HTTP API surface. Anything else that appears only in traces gets dropped, because the true relationship there is produce-and-consume, and that belongs in a different part of the schema.

On the run that introduced the check, by which point the catalog had grown to 496 edges, 18 of them disappeared. All 18 pointed into the same two Lambdas. I went to AWS to check, and neither has a function URL. One is triggered by SQS, the other is invoke-only. Both are correctly not directly callable, and all 56 hand-rolled HTTP trace edges, the ones configuration is blind to, survived untouched.

What an edge looks like now

My instinct after finding a false edge was to make the trace source smarter, with more filters and better resolution of which service a peer name refers to.

I did the reverse. I demoted the runtime source from a quantitative signal to a boolean that says one thing only, which is that this edge existed at least once in the window. observedCalls is gone. If you want volume, query the tracing vendor live, where the sampling is at least visible to you.

The status enum collapsed from six values to three. declared means a configuration source declared the call, async-declared means the two services are connected through an event or a queue rather than a direct call, and observed-only means traces are the sole witness. After the regeneration the distribution went from 317 declared, 105 confirmed-live and 74 observed-undocumented to 422 declared and 56 observed-only. The catalog lost a dimension it was never able to measure honestly.

Every edge now carries the evidence for its own existence.

{
  "to": "users-api",
  "sources": ["terraform", "sdk"],
  "status": "declared",
  "observed": true,
  "confidence": 1.0,
  "attribution": "per-app",
  "via": "@company/users-sdk",
  "sourceFiles": [
    "service-meetings/apps/api/package.json#31",
    "service-meetings/apps/api/terraform/sg.tf#88"
  ]
}

sources says which derivers found it. observed records existence and nothing else, and the schema documentation says that in as many words. attribution records how the client-library dependency was credited, whether it was found in the app's own manifest or hoisted up from the repository root, which is a real source of over-reporting. via names the package or the security-group rule. sourceFiles gives file and line, so anyone can open the claim and check it.

The read path lets the caller decide how much evidence to require. The get_service tool takes minConfidence and excludeRootHoisted, so a caller who only wants edges confirmed in configuration or seen in real traffic can ask for exactly that instead of getting an opinionated merge they cannot inspect. Every response also reports, for each deriver, whether its last run succeeded, when it ran and how many edges it produced, so a partial rebuild shows up on every call instead of being served as though it were current.

The rule that matters more than the schema

The runtime source may only add an edge or upgrade one to confirmed. It may never remove one.

The asymmetry is the whole point. Configuration over-reports, which gives you extra edges you can see and argue about. Traces under-report, which gives you a graph that quietly omits 64% of itself and still looks authoritative. An over-full graph makes you investigate something harmless. An under-full graph makes you delete a service that something still calls once a month.

So do not merge your sources into a single answer and call it the truth. Annotate them. Let every edge record who saw it and where, and write down which source is allowed to delete evidence. In my case exactly one is, and it is not the one that looks most alive.