← Back to blog
·6 min read

The coupling nobody draws: shared tables, headers, env vars and JWT claims between services

Services couple without a single call: a shared table, header, env var or JWT claim. How a code graph records those contracts and refuses to guess the rest.

code-intelligencecloud-architecturedeveloper-tooling

Two services can be coupled without either one calling the other. One writes a table the other queries, one signs a JWT claim the other trusts, one sends a tenant header the other reads, and several read the same environment variable that names one of the others. None of those edges appears on the architecture diagram, and none appears in any single repository's code graph, because the edge is not in either repository. It is in the agreement between them. Since bin-v0.8.1, CGraph, our open-source code graph engine, records each of those agreements as a contract and joins them across repositories, so an impact query that starts at a migration or a token signer reaches the code in the other services that depends on it.

The problem

The diagram shows HTTP arrows, and even those go wrong. When we mined the incident history of the service estates we work in, 52 incidents reconstructed from pull requests and session logs, the two largest categories were a missed cross-service consumer (17) and schema coupling (12), counted for the HTTP contracts that are on the diagram. The lead incident was a change in an identity service that broke a client application's revoked-session detection in another repository. Nothing in the client's repository changed. The agreement had moved under it.

The agreements below are the ones nobody draws at all, and they fail the same way.

That pattern repeats with every kind of shared thing. Rename a column, and the reporting job that runs SELECT ... FROM invoices against it fails. Rename the roles claim the accounts service signs, and the navigation code that decodes it stops showing the billing page. Change which header carries the tenant, and a server quietly reads an empty value. A per-repository graph answers what breaks if I change this inside the repository, which is exactly where these changes do not break anything.

What we did

The first version of CGraph's cross-service support, the seam, joined repositories through one kind of edge: an HTTP endpoint one serves and another calls. Phase 3 of that work added five more. Every extractor records the same two facts, this code provides a contract or this code uses one, and each contract becomes a node with a plain id that two repositories can hold by construction. What differs by kind is when two repositories' nodes are allowed to meet:

Kind Node id Provided by Used by Joins across repos
HTTP header header:x-tenant-id a server reading it a client sending it by name, except standard headers
JWT claim claim:roles a signer a typed decoder and its reads by name, except standard claims; scoped by a declared issuer
SQL table table:local:invoices the migration that creates it a query string, a mirrored Drizzle model only inside a database you declare
DynamoDB table dynamo:sessions-dev a write a read by name, no declaration
Env var env:ACCOUNTS_URL the service you name every read only when you declare it

The key decision is that the rules are deliberately uneven, and the alternative we rejected was the obvious one: join everything by name. Headers and claims carry their meaning in their name, so x-tenant-id in two repositories is very likely the same agreement. Table names and environment variable names are not like that. Every service reads NODE_ENV, and two repositories with a users table may be talking to two different databases. Nothing in the code proves those join, so the graph does not guess. You declare them where repositories meet:

cgraph seam discover \
  --graph accounts=out/accounts/graph.json \
  --graph web=out/web/graph.json \
  --graph reports=out/reports/graph.json \
  --database billing=accounts,reports \
  --env ACCOUNTS_URL=accounts \
  --issuer accounts=accounts,web \
  --out seam

Each flag states one fact the code cannot: these two repositories share the billing database, this variable addresses the accounts service, and accounts mints the tokens web reads. The per-repository graphs never change; the declarations are applied where the graphs are joined, so a repository's graph does not depend on which workspace it happens to sit in.

The same caution runs the other way. Some things never bridge, by rule: the standard HTTP headers (authorization, content-type, x-request-id, traceparent), because every service uses them for its own reasons; the registered JWT claims (sub, exp), because they describe the token, not a value one service hands another; anything read in test code, because a test's fake server stands in for another service rather than being one. A missed edge is visible and fixable with one flag. A wrong edge sends every impact query into code that has nothing to do with the change, forever. This is the same principle behind refusing to guess a call target, applied one level up.

The result

The artifact is the same impact query asked twice. We built three small services to show it: an accounts service in TypeScript that owns the invoices table and signs tokens, a web front end in TypeScript that calls it and decodes those tokens, and a reports job in Python that queries the database directly. The reporting job serves no endpoint and calls none the graph resolves, so a seam built from endpoints alone has no edge to it at all.

Asked of the accounts graph alone, "what depends on the invoices table" returns one node, the table's own contract:

total=1
  d1 handled_by accounts::table:local:invoices

That is the correct answer for what the graph was told. Asked of the fused graph, with the database declared:

  d1 HANDLED_BY table:billing:invoices
  d2 CONSUMES reports::reports_job_py_monthly_total
  d2 CONSUMES service:reports
  d3 contains reports::reports_job_py

The Python function that would break is two hops from the migration. The same fused graph puts the web function that checks roles two hops from the token signer, and puts both senders of the tenant header, one in each consuming service, two hops from the server function that reads it. And the fuse step refuses to run if it is given different declarations from the discover step, rather than silently producing a graph with the join cut in half.

The honest limits are listed in the full write-up: environment names built at runtime are not read, lower-case SQL is skipped, DynamoDB is TypeScript and JavaScript only, and a token issuer is declared rather than inferred from signing keys.

Takeaway

Before a modernization, a service split, or a schema change you are nervous about, map the agreements, not just the calls. Build a graph per repository, run seam discover with no flags to see what already joins by name, add one declaration for a coupling you know exists, and ask the impact question about the migration or the signer. That map is the kind we build at the start of a modernization engagement, and the first thing an AI coding agent needs before it touches a shared table on the cloud platforms we run. The complete walkthrough, with every command and every edge the three-service example produced, is on NxtSoft Labs.

Building something like this?