MATIH Platform is in active MVP development. Documentation reflects current implementation status.
8. Platform Services
Service Routing

Service Routing

The API Gateway manages service routing by registering backend services and their routes with Kong. The GatewayManagementService maintains an in-memory cache of service and route configurations and synchronizes them with the Kong Admin API. Routes map incoming request paths, methods, and headers to specific backend services.


Service Configuration

A service represents a backend microservice that the gateway proxies requests to. Each service is defined with connection parameters and timeout settings.

ServiceConfig Properties

PropertyTypeDefaultDescription
nameStringrequiredUnique service identifier
urlStringrequiredBackend service URL (e.g., http://ai-service:8000)
connectTimeoutint60000Connection timeout in milliseconds
writeTimeoutint60000Write timeout in milliseconds
readTimeoutint60000Read timeout in milliseconds
retriesint3Number of retry attempts on failure
tagsListnullTags for categorization and filtering

Register a Service

Endpoint: POST /api/v1/gateway/services

curl -X POST http://localhost:8080/api/v1/gateway/services \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "name": "ai-service",
    "url": "http://ai-service.tenant-acme:8000",
    "connectTimeout": 60000,
    "readTimeout": 120000,
    "retries": 3,
    "tags": ["data-plane", "ai"]
  }'

List All Services

Endpoint: GET /api/v1/gateway/services

curl http://localhost:8080/api/v1/gateway/services \
  -H "Authorization: Bearer ${TOKEN}"

Delete a Service

Endpoint: DELETE /api/v1/gateway/services/:serviceName

curl -X DELETE http://localhost:8080/api/v1/gateway/services/ai-service \
  -H "Authorization: Bearer ${TOKEN}"

Route Configuration

Routes define how incoming requests match to backend services. Routes are attached to services and can match on paths, methods, hosts, and headers.

RouteConfig Properties

PropertyTypeDefaultDescription
nameStringrequiredUnique route identifier
pathsListnullURL path prefixes to match (e.g., /api/v1/ai)
methodsListnullHTTP methods to match (e.g., GET, POST)
hostsListnullHostnames to match
headersMapnullHeaders to match (key to list of values)
stripPathbooleanfalseWhether to strip the matched path prefix
preserveHostbooleantrueWhether to preserve the original host header
tagsListnullTags for categorization

Create a Route

Endpoint: POST /api/v1/gateway/services/:serviceName/routes

curl -X POST http://localhost:8080/api/v1/gateway/services/ai-service/routes \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "name": "ai-service-route",
    "paths": ["/api/v1/ai", "/api/v1/conversations"],
    "methods": ["GET", "POST", "PUT", "DELETE"],
    "stripPath": false,
    "preserveHost": true,
    "tags": ["data-plane"]
  }'

Delete a Route

Endpoint: DELETE /api/v1/gateway/routes/:routeName

curl -X DELETE http://localhost:8080/api/v1/gateway/routes/ai-service-route \
  -H "Authorization: Bearer ${TOKEN}"

Routing Patterns

Path-Based Routing

Route by URL path prefix to direct requests to the correct microservice:

Path PrefixBackend Service
/api/v1/ai/*ai-service
/api/v1/billing/*billing-service
/api/v1/audit/*audit-service
/api/v1/tenants/*tenant-service
/api/v1/iam/*iam-service

Host-Based Routing

Route by hostname for multi-tenant isolation:

{
  "name": "tenant-acme-route",
  "hosts": ["acme.matih.ai"],
  "paths": ["/api/v1"],
  "preserveHost": true
}

Header-Based Routing

Route by custom headers for service versioning or tenant routing:

{
  "name": "v2-api-route",
  "paths": ["/api"],
  "headers": {
    "X-API-Version": ["v2"]
  }
}

Caching Behavior

The GatewayManagementService maintains an in-memory ConcurrentHashMap cache for both services and routes. When a service or route is created or updated via the API, the cache is updated alongside the Kong Admin API call. On service deletion, the cache entry is removed.

The cache serves as a fast lookup for management operations. Actual traffic routing is handled by Kong directly and does not depend on this cache.