Managing Backend Services

1. Registering Upstream Services

FieldDescriptionExample
nameService IDorders-svc
protocolhttp/https/grpc/tcphttps
hostDNS or upstream nameorders.internal
portTCP port8443
pathBase prefix on upstream/api

Example: Multi-target upstream (Kong)

upstreams:
  - name: orders-pool
    algorithm: round-robin
    targets:
      - target: orders-1.internal:8080
        weight: 100
      - target: orders-2.internal:8080
        weight: 100
      - target: orders-canary.internal:8080
        weight: 10
services:
  - name: orders-svc
    host: orders-pool   # references upstream
    port: 8080

2. Configuring Service Health Checks

TypeHowWhen
ActiveGateway pings /healthContinuous monitoring
PassiveTrack real request failuresAlways (free)
TCPOpen socket checkNon-HTTP backends
HTTPStatus code checkWeb services
gRPCgrpc.health.v1gRPC services

Example: Active health check

healthchecks:
  active:
    type: http
    http_path: /health
    timeout: 2
    interval: 5          # seconds between checks
    healthy:
      successes: 2
      http_statuses: [200, 204]
    unhealthy:
      tcp_failures: 3
      http_failures: 3
      http_statuses: [429, 500, 503]

3. Setting Service Timeouts

TimeoutPhaseDefault
connect_timeoutTCP/TLS handshake5s
read_timeoutReceive response60s
write_timeoutSend request body60s
per_try_timeoutSingle retry attempt= read_timeout

4. Managing Service Metadata

MetadataUse
tagsGroup by env, team, criticality
labelsK8s-style selector matching
annotationsTooling hints (Prom scrape, etc.)
versionMulti-version routing

5. Implementing Service Discovery Integration

DiscoveryMechanismExample
DNSSRV/A record lookuporders.svc.cluster.local
ConsulCatalog + healthorders.service.consul
EurekaSpring Cloud registryREST polling
KubernetesEndpoints APIService object
StaticHardcoded listTargets in config

6. Configuring Multiple Service Versions

Example: Header-based version routing

routes:
  - name: orders-v2
    paths: ["/orders"]
    headers:
      X-API-Version: ["2"]
    service: orders-v2-svc
  - name: orders-v1
    paths: ["/orders"]
    service: orders-v1-svc   # default fallback

7. Configuring Retry Policies

SettingDescriptionDefault
retriesMax attempts5
retry_onConditions: 5xx, gateway-error, reset5xx
per_try_timeoutSingle attempt limit10s
backoffexponential, base 25msjittered
retriable_status_codesExplicit list[502,503,504]
Warning: Never retry non-idempotent methods (POST) unless using idempotency keys.

8. Setting Circuit Breaker Thresholds

SettingDescriptionTypical
max_connectionsTrip if exceeded1024
max_pending_requestsQueue cap100
consecutive_5xxEject after N errors5
base_ejection_timeOpen duration30s
max_ejection_percentHosts ejected cap50%

9. Configuring Service Fallbacks

Example: Fallback to cached/static response

plugins:
  - name: proxy-cache
    config:
      response_code: [200]
      content_type: ["application/json"]
      cache_ttl: 300
  - name: fallback-response
    config:
      on_error: true
      status: 200
      body: '{"items":[],"degraded":true}'

10. Setting Up Blue-Green Deployments

Blue/Green Cutover

  1. Deploy green stack alongside blue
  2. Smoke test green via internal route
  3. Switch gateway upstream from blue → green
  4. Monitor error rate and latency
  5. Keep blue warm for instant rollback (30 min)
  6. Decommission blue after stability window
StrategyRiskRollback
Blue/GreenLowInstant (flip route)
CanaryVery lowReduce weight to 0
RollingMediumRe-deploy old