Loading…
Loading…
Explains how the system identifies services that share common backend infrastructure, such as servers, web servers, or specific endpoint URLs.
The Service Dependency Repository is a component that analyzes service configurations to identify shared backend infrastructure. It helps API publishers understand the potential "blast radius" of a backend infrastructure failure by reporting which services depend on the same servers, web servers, or exact endpoint URLs.
This component operates by reading service configuration data from the platform's database. It does not modify any data. Its primary functions are to:
The analysis is performed at three distinct levels of dependency:
HOST): Services whose backend endpoint URLs resolve to the same hostname.HOST_PORT): Services whose backend endpoint URLs resolve to the same hostname and port combination.ENDPOINT): Services that use the exact same backend endpoint URL string.The dependency analysis process involves data retrieval, URL parsing, and grouping based on the level of dependency.
flowchart TD
subgraph Dependency Analysis Process
A[API Call: findSharedGroups() or findRelatedServices()] --> B{Load Service Backends};
B --> C[Database];
C -- Raw service data -- > B;
B -- Service list -- > D{For each service};
D --> E[Parse Backend Endpoint URL];
E -- Parsed host, port, host:port -- > D;
D -- Parsed service list --> F{Group Services};
F -- "By HOST, HOST_PORT, or ENDPOINT" --> G[Generate Report];
G -- Dependency report --> H[Return Results];
end
subgraph "URL Parsing (Step E)"
direction LR
U_IN[Endpoint URL String] --> P1{Parse with URI};
P1 -- "host, port, scheme" --> P2{Normalize Host};
P2 --> P3{Infer Default Port};
P3 -- "e.g., http -> 80, https -> 443" --> P_OUT[Parsed Host, Port, Host:Port];
P1 -- on URISyntaxException --> P_ERR{Fallback: Use raw string as host};
P_ERR --> P_OUT;
endData Retrieval: The process begins by executing a SQL query against the platform database to retrieve a list of all active services and their default backend endpoint URLs. The query joins the s2r_service and s2r_backend_profile tables. It explicitly filters out services with a deprecated status or those with a null or empty endpoint_url.
IMPORTANT
The data retrieval is scoped to the services belonging to a single tenant. This ensures that dependency analysis for one API publisher does not include or leak information about services belonging to another.
Endpoint URL Parsing: For each service retrieved, its backend endpoint_url is parsed to extract its constituent parts:
URI class for parsing.@ symbol).http defaults to port 80, and https defaults to port 443. No default port is inferred for other schemes.hostPort string (e.g., api.example.com:443) is constructed.Grouping and Analysis: The parsed service data is then analyzed based on the method called:
findSharedGroups(): Services are grouped by hostname, hostPort, and endpointUrl. Any group containing more than one service is considered a "shared group" and is included in the results.findRelatedServices(serviceId): The system first identifies the "anchor" service specified by serviceId. It then finds all other services that share the same hostname, hostPort, or endpointUrl as the anchor. The results are sorted to show the most closely related services first (Same Endpoint, then Same Web Server, then Same Server).The repository exposes two methods for dependency analysis.
findSharedGroups()Finds all groups of two or more services that share backend infrastructure. The results are sorted by dependency level, then by the number of services in the group (descending), and finally by the shared target identifier.
List of Map<String, Object>, where each map represents a group of services sharing a dependency.Each object in the returned list has the following structure:
| Field | Type | Description |
|---|---|---|
dependencyLevel | String | The level of dependency. One of host, host_port, or endpoint. |
dependencyLabel | String | A human-readable label for the dependency level (e.g., "Same Server"). |
hostname | String | The shared hostname. |
port | String | The shared port, or an empty string if not applicable. |
target | String | The specific shared resource: the hostname for host, host:port for host_port, or the full URL for endpoint. |
exampleEndpointUrl | String | An example backend endpoint URL from one of the services in the group. |
serviceCount | Number | The total number of services in this shared group. |
prodServiceCount | Number | The number of services in this group whose environment is named prod (case-insensitive). |
services | String | A comma-separated string listing the services in the group, formatted as environment/serviceKey. |
findRelatedServices(UUID serviceId)Finds all services that share backend infrastructure with a specific "anchor" service.
serviceId (UUID): The unique identifier of the service to use as the anchor for the analysis.Map<String, Object> containing the analysis results. If the serviceId is not found, the relatedServices and dependencySummary lists will be empty.findRelatedServices Response StructureThe returned map contains the following top-level keys:
| Field | Type | Description |
|---|---|---|
anchor | Map | Details about the anchor service. See the Anchor Fields table below. |
dependencySummary | List | A summary of dependency counts at each level. See the Dependency Summary Fields table. |
relatedServices | List | A list of all services related to the anchor, including the anchor itself. See the Related Service Fields table. |
sharedCount | Number | The number of other services that share a dependency with the anchor service (i.e., relatedServices.size() - 1). |
| Field | Type | Description |
|---|---|---|
serviceId | UUID | The unique identifier of the anchor service. |
serviceKey | String | The service key of the anchor service. |
environment | String | The environment of the anchor service. |
hostname | String | The parsed backend hostname for the anchor service. |
port | String | The parsed backend port for the anchor service. |
hostPort | String | The combined host:port string for the anchor service's backend. |
endpointUrl | String | The full backend endpoint URL of the anchor service. |
Each object in the dependencySummary list has the following structure:
| Field | Type | Description |
|---|---|---|
dependencyLevel | String | The level of dependency: host, host_port, or endpoint. |
dependencyLabel | String | A human-readable label for the dependency level. |
target | String | The specific resource of the anchor service at this dependency level. |
serviceCount | Number | The total number of services sharing this resource with the anchor. |
prodServiceCount | Number | The number of services in this group whose environment is prod. |
Each object in the relatedServices list has the following structure. The list is sorted by dependency rank (endpoint, then host/port, then host), then by environment, then by service key.
| Field | Type | Description |
|---|---|---|
serviceId | UUID | The unique identifier of the service. |
environment | String | The environment of the service. |
serviceKey | String | The service key. |
serviceName | String | The human-readable service name. |
status | String | The operational status of the service. |
debugEnabled | Boolean | Whether debug mode is enabled for the service. |
endpointUrl | String | The backend endpoint URL of the service. |
hostname | String | The parsed backend hostname. |
port | String | The parsed backend port. |
hostPort | String | The combined host:port string for the backend. |
dependencyLevel | String | A label describing the strongest dependency relationship to the anchor: "same endpoint", "same web server", or "same server". |
sameHost | Boolean | true if this service shares the same backend host as the anchor. |
sameHostPort | Boolean | true if this service shares the same backend host and port as the anchor. |
sameEndpoint | Boolean | true if this service shares the exact same backend endpoint URL as the anchor. |
The component retrieves service data using the following SQL query. This is provided for visibility into the exact data source.
select s.id as service_id,
s.environment,
s.service_key,
s.service_name,
s.status,
s.debug_enabled,
bp.endpoint_url
from s2r_service s
join s2r_backend_profile bp on bp.id = s.default_backend_profile_id and bp.tenant_id = s.tenant_id
where s.status <> 'deprecated'
and bp.endpoint_url is not null
and trim(bp.endpoint_url) <> ''
and s.TENANT_ID = ? -- TENANT_SCOPE_SQL is replaced with a tenant predicate
order by s.environment, s.service_key
http://[invalid-host), the parser will fall back to using the entire raw string as the hostname. This may cause the service to be excluded from its correct dependency group or be grouped incorrectly.findRelatedServices, if the provided serviceId does not match an active service with a configured backend URL, the method will return a result with empty relatedServices and dependencySummary lists.http (80) and https (443) schemes. If services use a backend on a non-standard port without specifying it in the URL (e.g., http://api.example.com for a service running on port 8080), they will not be correctly grouped at the HOST_PORT level.