ThoughtsInWords

East-West API Gateways and Hexagonal Architecture: Decoupling Mock-to-Live Traffic Graduation

Date: November 28, 2026 Last Updated: November 28, 2026 Review: Expert & Architecture Review Report

Scope & Licensing Note: This article strictly covers pure open-source systems. Premium, proprietary/vendor-locked, and community-edition (open-core) systems are currently not included.

Summary

Parallel microservice delivery frequently stalls on the same integration bottleneck: upstream teams are blocked waiting for unfinished downstream APIs, teams scatter brittle mock conditionals across polyglot callers, and “big bang” cutovers turn launch day into an all-or-nothing gamble. Combining an internal East-West API Gateway (handling internal service-to-service traffic, distinct from North-South external ingress) with Hexagonal Architecture (Ports and Adapters) decouples service-to-service communication from deployment and release mechanics. A calling microservice communicates exclusively with a single stable internal gateway endpoint through an outbound adapter, while pure open-source infrastructure—such as Envoy Proxy, Apache APISIX, or Kubernetes Gateway API controllers—manages contract-driven mocking, dark-launch traffic mirroring, safe canary graduation, and full cutover without touching or redeploying the caller.

Key Points


1. How Hexagonal Architecture Maps to East-West Routing

In Hexagonal Architecture (originally formulated by Alistair Cockburn as Ports and Adapters), the business domain sits at the center and interacts with the outside world strictly through explicit interfaces (Ports) and swappable infrastructure implementations (Adapters). When applied to internal microservice communication (East-West traffic, as opposed to North-South external client-to-cluster ingress), this separation ensures the calling service’s business logic never knows—or cares—whether a downstream dependency is a contract mock, a shadow-tested build, a canary slice, or a fully graduated production service.

flowchart LR
    subgraph Caller["Calling Microservice (Hexagonal Architecture)"]
        Core["Domain Core (Business Rules)"]
        Port["Outbound Port (e.g., PaymentPort / InventoryPort)"]
        Adapter["Outbound Adapter (HTTP / gRPC Client + Context Headers)"]
        Core --> Port --> Adapter
    end

    subgraph GW["Internal East-West Layer (Centralized Gateway or GAMMA Mesh)"]
        Router["L7 Routing Engine (Header Overrides, Mirroring, Cohort / Weighted Split)"]
    end

    subgraph Upstreams["Downstream Targets"]
        Mock["Mock Upstream (Microcks / Prism / Direct Response)"]
        Live["Live Downstream Service (Canary / Production)"]
    end

    Obs["Observability (OpenTelemetry Traces + Prometheus Metrics)"]

    Adapter -->|"Single stable URL: https://internal-gw.mesh/v1/payments"| Router
    Router -->|"Stage 0–2 / Override / Safe Read Fallback"| Mock
    Router -->|"Stage 1 Mirror / Stage 2–3 Live"| Live
    Router -.->|"Injects Served-By tag & trace spans"| Obs

Each layer owns a single, well-bounded responsibility:

Two Pure Open-Source East-West Topologies

In Kubernetes environments using Kubernetes Gateway API (Apache-2.0), East-West L7 routing maps to two distinct topologies—conflating them causes subtle manifest and scaling mistakes:

  1. Centralized Internal East-West Gateway (parentRefs: kind: Gateway): Callers send traffic to an internal Gateway resource addressed by spec.hostnames (for example, internal-gw.mesh). This topology is supported by Envoy Gateway (Apache-2.0, a Gateway-bound controller), Apache APISIX (Apache-2.0), Istio (Apache-2.0, CNCF Graduated), and Cilium (Apache-2.0, CNCF Graduated), or standalone Envoy Proxy (Apache-2.0, CNCF Graduated) fleets. It excels when teams want a single shared policy and mocking boundary—at the cost of an extra network hop and a shared gateway blast radius.
  2. Decentralized Service Mesh via GAMMA (parentRefs: group: "", kind: Service): Under the GAMMA (Gateway API for Mesh Management and Administration) initiative, Istio and Cilium attach HTTPRoute or GRPCRoute resources directly to a Kubernetes Service (with spec.hostnames omitted per the GAMMA specification). Local sidecar or ambient node proxies enforce routing rules inline without hairpinning traffic through a central proxy tier. (Envoy Gateway targets Gateway resources rather than GAMMA mesh Service attachments.)

Section 5 compares both topologies against in-process hexagonal test doubles across latency, blast radius, cost, and operational complexity.

Why Keeping Routing Out of the Adapter Matters

Without an East-West routing layer, teams often fall back to conditional logic inside the outbound adapter (if (useMock) callMockClient() else callLiveClient()). Even when backed by an application-level feature flag (see OpenFeature API Specification for when runtime application flags remain the better fit), embedding routing switches inside callers couples deployment topology to application code and forces synchronized rollouts across polyglot services.

Moving mock/live dispatch into the East-West plane keeps the outbound adapter static—yet production-hardened—across the entire lifecycle of the downstream service:

// Outbound Port (Domain boundary — zero infrastructure awareness)
export interface PaymentPort {
  authorize(req: PaymentRequest, ctx: RequestContext): Promise<PaymentResult>;
}

export class PaymentGatewayError extends Error {
  constructor(
    public readonly status: number,
    public readonly servedBy: string,
    public readonly retryable: boolean,
  ) {
    super(`Payment gateway request failed with HTTP ${status} (served-by=${servedBy})`);
  }
}

// Outbound Adapter (Targets one stable East-West route forever)
export class GatewayPaymentAdapter implements PaymentPort {
  // Default to HTTPS/mTLS; plaintext http:// is only safe when a local sidecar
  // or ambient proxy transparently intercepts and upgrades traffic to SPIFFE mTLS.
  constructor(private readonly gatewayBaseUrl = "https://internal-gw.mesh") {}

  async authorize(req: PaymentRequest, ctx: RequestContext): Promise<PaymentResult> {
    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      "Idempotency-Key": ctx.idempotencyKey,
      "traceparent": ctx.traceparent,
      "Tenant-Id": ctx.tenantId,
    };
    if (ctx.tracestate) headers["tracestate"] = ctx.tracestate;
    if (ctx.tenantCohort) headers["Tenant-Cohort"] = ctx.tenantCohort;

    const res = await fetch(`${this.gatewayBaseUrl}/v1/payments`, {
      method: "POST",
      headers,
      body: JSON.stringify(req),
      signal: AbortSignal.timeout(ctx.timeoutMs),
    });

    const servedBy = res.headers.get("Served-By") ?? "unknown";
    if (!res.ok) {
      throw new PaymentGatewayError(
        res.status,
        servedBy,
        res.status === 503 || res.status === 504,
      );
    }

    return (await res.json()) as PaymentResult;
  }
}

When the downstream payments service transitions from a contract mock to a dark-launched candidate, a cohort-pinned canary, and finally 100% production traffic, not a single line of GatewayPaymentAdapter changes—while strict timeouts, idempotency keys, trace context, and explicit HTTP 503 handling keep failures bounded and observable at every stage.


2. Implementing Mocks at the Gateway Layer

Placing mock implementations behind the East-West gateway unblocks upstream and frontend teams immediately after an API contract is ratified (see Design-First Partner APIs for spec-first governance)—allowing parallel integration weeks before the downstream service finishes implementation or infrastructure provisioning.

Three complementary patterns cover most mocking needs:

1. Contract-Driven Mock Servers

Generate a dedicated mock upstream directly from your OpenAPI or Protocol Buffers (.proto) specification and register it as a standard backend target in the gateway:

2. Gateway-Native Mock Plugins, Direct Responses, and Latency Realism

For lightweight stubs, health checks, or deterministic edge cases that do not justify running a separate mock container, return static or templated payloads directly from the gateway without an extra network hop:

Calibrate Mock Latency Early: A mock server responding in 2 ms creates a dangerous illusion of speed. When Stage 2 routes traffic to a live backend with a 150 ms p99 latency, callers configured with overly aggressive timeouts or unbounded retries can trigger retry amplification storms. Inject realistic p50/p99 latency distributions during Stage 0 using Apache APISIX mocking.delay / fault-injection, Envoy envoy.filters.http.fault, or Microcks delay profiles so caller timeouts, circuit breakers, and connection pools are exercised realistically before live cutover.

3. Header-Based Overrides and Fault Injection

Configure the East-West gateway to inspect explicit routing or scenario headers—standardizing on non-X- names such as Route-Target: mock and Test-Scenario: timeout in accordance with IETF RFC 6648 (supporting legacy X- aliases only during brownfield migrations where existing test harnesses require them)—before falling through to default traffic rules.

Header-based overrides let automated CI/CD suites, chaos drills, and local integration tests deterministically force mock responses, HTTP 503 / gRPC UNAVAILABLE failures, or injected latency spikes on isolated requests while regular traffic flows undisturbed to live backends.

Security Boundary: Untrusted external requests entering through a North-South Edge API Gateway must strip all internal routing and test-override headers (Route-Target, Test-Scenario, Tenant-Cohort, Tenant-Id, and any legacy X- aliases) at the perimeter, and East-West overrides must be gated by verified workload identity. See Guardrail #4 in Section 4 for the complete perimeter and mTLS (mutual TLS) / SPIFFE & SPIRE enforcement model.

Comparing the Three Gateway Mocking Patterns

Mocking Pattern Best Use Case Protocol Support Statefulness Extra Network Hop Pure Open-Source Tools
Contract-Driven Mock Servers Full multi-endpoint integration, schema validation, and reusable CI contract suites. REST/OpenAPI, gRPC/Protobuf, GraphQL, AsyncAPI (Microcks); OpenAPI HTTP (Prism). Example-driven or scripted stateful (Microcks); stateless (Prism). Yes (gateway → mock container). Microcks, Stoplight Prism
Gateway-Native Direct Responses Lightweight stubs, health probes, maintenance responses, and calibrated delay/error stubs. HTTP/1.1, HTTP/2 (REST/JSON). Stateless (static or templated payloads). No (synthesized inline at proxy). Apache APISIX (mocking, fault-injection), Envoy Proxy (direct_response, fault filter)
Header-Based Overrides Deterministic CI/CD fault injection, chaos drills, and isolated QA/canary verification on shared clusters. HTTP headers and gRPC metadata. Depends on target upstream (mock or live). Depends on resolved target. Envoy Proxy, Apache APISIX, Kubernetes Gateway API (HTTPRoute / GRPCRoute)

3. Traffic Graduation Strategy (Mock to Live)

Traffic graduation shifts requests progressively from the mock upstream to the real microservice as the downstream implementation matures, turning a high-risk “big bang” cutover into four observable, reversible stages governed by explicit promotion gates.

flowchart TD
    S0["Stage 0: Contract Mock (100% Mock / Calibrated Latency)"] --> G1{"Gate 1: CI Schema & Contract Parity Pass?"}
    G1 -->|"No (Fix Spec / Service)"| S0
    G1 -->|"Yes"| S1["Stage 1: Shadow / Dark Launch (100% Mock + Sampled Mirror to Live)"]
    S1 --> G2{"Gate 2: Shadow Error & Payload Parity Pass?"}
    G2 -->|"No (Disable Mirror & Remediate)"| S0
    G2 -->|"Yes"| S2["Stage 2: Canary (Cohort-Pinned Writes / Weighted Stateless Reads)"]
    S2 --> G3{"Gate 3: Live SLOs, Latency & DB Load Within Budget?"}
    G3 -->|"Regression (Instant Rollback to Mock)"| S0
    G3 -->|"Yes"| S3["Stage 3: Full Graduation (100% Live + Scoped CI Override)"]
    S3 -->|"Post-Cutover Incident (Non-Mutating Only)"| S0
    S3 --> R["Mock Retirement (Remove Stale Routes per Sunset SLA)"]
Stage Traffic Split Routing Mechanism Primary Goal
0. Contract Mock 100% Mock / 0% Live Default route to contract-driven mock server (Microcks / Prism) with realistic delay profiles. Unblock upstream development and exercise caller timeouts/contracts early.
1. Shadow (Dark Launch) 100% Mock (Sampled Live mirror) Async traffic mirroring (request_mirror_policies in Envoy, proxy-mirror in APISIX, or RequestMirror in Gateway API). Verify live service stability, serialization, and payload parity without risking caller impact.
2. Canary / Cohort Graduation Cohort-pinned (stateful) or 10%–50% weighted (stateless) Header-matched cohort routing for stateful APIs; weighted load balancing (traffic-split, weighted clusters, HTTPRoute/GRPCRoute weights) for stateless reads. Validate real latency, error rates, and database load under controlled production-like traffic.
3. Full Graduation 0% Mock / 100% Live Default route to live service (mock retained only for explicit CI overrides or bounded read-only fallback until retired). Complete cutover with fail-closed semantics on state-mutating paths and a clear mock sunset plan.

Declarative Graduation Examples (Kubernetes Gateway API)

With Kubernetes Gateway API (Apache-2.0), routing changes live in version-controlled CRD (Custom Resource Definition) manifests rather than application code. Both manifests below target a centralized internal Gateway (parentRefs: kind: Gateway with spec.hostnames, supported by Envoy Gateway, Apache APISIX, Istio, and Cilium).

Decentralized GAMMA Mesh Variant: If you run Istio or Cilium in GAMMA service-mesh mode instead of a centralized internal gateway, replace parentRefs with { group: "", kind: Service, name: payments-svc } and omit spec.hostnames per the GAMMA specification.

Stage 1 Snapshot: Sampled Dark-Launch Mirroring on a Read-Only Endpoint

During Stage 1, primary traffic still resolves from the mock upstream while a bounded percentage of safe, read-only traffic mirrors asynchronously to the live candidate using Gateway API v1.3+ requestMirror fractional sampling (GEP-3171):

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: payments-quotes-stage1-shadow
  namespace: mesh-internal
spec:
  parentRefs:
    - kind: Gateway
      name: internal-east-west-gw
  hostnames:
    - "internal-gw.mesh"
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /v1/payments/quotes
          method: GET
      filters:
        # Mirror 10% of read-only quote requests asynchronously to warm and test live pods
        - type: RequestMirror
          requestMirror:
            backendRef:
              name: payments-live-svc
              port: 8080
            percent: 10
        - type: ResponseHeaderModifier
          responseHeaderModifier:
            set:
              - name: Served-By
                value: mock-microcks
      backendRefs:
        - name: payments-mock-svc
          port: 8080

Stage 2 Snapshot: Cohort-Pinned Stateful Writes + Weighted Stateless Reads

Notice how Stage 2 separates stateful payment mutations (graduated deterministically by Tenant-Cohort header to avoid write-then-read split-brain) from stateless read-only quotes (safely split by 25%/75% random weights):

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: payments-east-west-stage2
  namespace: mesh-internal
spec:
  parentRefs:
    - kind: Gateway
      name: internal-east-west-gw
  hostnames:
    - "internal-gw.mesh"
  rules:
    # Rule 1: Deterministic CI/CD override
    # Note: Gateway API evaluates precedence by match specificity (path + header beats
    # path-only), not by YAML list order.
    - matches:
        - path:
            type: PathPrefix
            value: /v1/payments
          headers:
            - name: Route-Target
              value: mock
      filters:
        - type: ResponseHeaderModifier
          responseHeaderModifier:
            set:
              - name: Served-By
                value: mock-microcks
      backendRefs:
        - name: payments-mock-svc
          port: 8080

    # Rule 2: Stateful Stage 2 — Pin dogfood/canary cohorts 100% to live (no split-brain)
    # Tenant-Id pinning follows the exact same header-match pattern for single tenants.
    - matches:
        - path:
            type: PathPrefix
            value: /v1/payments
          headers:
            - name: Tenant-Cohort
              value: dogfood
      filters:
        - type: ResponseHeaderModifier
          responseHeaderModifier:
            set:
              - name: Served-By
                value: live-v1
      backendRefs:
        - name: payments-live-svc
          port: 8080

    # Rule 3: Stateless Read Stage 2 — Safe 25% Live / 75% Mock weighted canary split
    - matches:
        - path:
            type: PathPrefix
            value: /v1/payments/quotes
          method: GET
      backendRefs:
        - name: payments-live-svc
          port: 8080
          weight: 25
          filters:
            - type: ResponseHeaderModifier
              responseHeaderModifier:
                set:
                  - name: Served-By
                    value: live-v1
        - name: payments-mock-svc
          port: 8080
          weight: 75
          filters:
            - type: ResponseHeaderModifier
              responseHeaderModifier:
                set:
                  - name: Served-By
                    value: mock-microcks

    # Rule 4: Default stateful fallback for remaining cohorts still in Stage 0/1
    - matches:
        - path:
            type: PathPrefix
            value: /v1/payments
      filters:
        - type: ResponseHeaderModifier
          responseHeaderModifier:
            set:
              - name: Served-By
                value: mock-microcks
      backendRefs:
        - name: payments-mock-svc
          port: 8080

Gateway API Conformance & Header Notes:

Critical Production Mechanics & Protocol Nuances

Mock-to-Live Stage Promotion & Rollback Checklist

Transition Mandatory Entry / Exit Gates Immediate Rollback Trigger
Stage 0 → Stage 1 (Shadow) OpenAPI/Protobuf spec ratified; CI contract gates (oasdiff, self-hosted Pact Broker, Microcks) passing; Stage 0 latency profiles calibrated; shadow endpoints confirmed read-only or isolated via idempotency / shadow DB. Mirroring causes >10% proxy buffer/CPU spike or increases primary mock p99 latency by >15%.
Stage 1 → Stage 2 (Canary) Live candidate sustains ≥99.9% non-5xx rate under sampled shadow load; shadow response-schema/payload parity diffs resolved; stateful endpoints wired with Tenant-Cohort / Tenant-Id pinning rules. Any split-brain state error, 5xx/gRPC UNAVAILABLE rate exceeding SLO budget, or retry amplification spike.
Stage 2 → Stage 3 (100% Live) Dogfood/canary cohorts pass full business-transaction reconciliation; p95/p99 latency, DB lock contention, and downstream async events match production NFR targets; fail-closed 503/UNAVAILABLE behavior verified. SLO breach or elevated error budget burn on non-mutating paths (mutating paths fail closed and roll forward/hotfix rather than falling back to mocks).
Stage 3 → Mock Retirement 14–30 days stable at 100% live; CI tests migrated to ephemeral contract runners; sunset ticket approved to remove permanent mock pods and stale gateway rules. Re-enable ephemeral contract mock in CI only—never restore retired production fallback routes ad hoc.

4. Key Operational Guardrails

Decoupling routing from application code shifts complexity from the codebase into runtime contract governance, failure isolation, and traffic operations. Five operational guardrails keep mixed mock/live topologies safe and debuggable:

Guardrail 1: Enforce Schema Parity, Behavioral NFRs, and Latency Realism in CI

Guardrail 2: Isolate Shadow Traffic & Guard Against Proxy Backpressure (Stage 1)

Guardrail 3: Tag Every Response and Distributed Trace

Guardrail 4: Prevent Header Spoofing Across Traffic Planes

Guardrail 5: Bound Blast Radius, Automate Rollback, and Enforce Mock Retirement


5. Trade-Offs, Socio-Technical Constraints, and Migration

Combining Hexagonal Architecture with an East-West API Gateway solves real cross-team bottlenecks in medium-to-large microservice estates, but it introduces measurable infrastructure, financial, and organizational overhead. Evaluating it honestly requires comparing the available topologies side by side.

Architectural Topology & NFR Comparison Matrix (Pure Open-Source)

Dimension Centralized Internal East-West Gateway (Envoy Gateway / Apache APISIX) Decentralized GAMMA Service Mesh (Istio / Cilium) In-Process Hexagonal Test Double (Unit / Integration Harness)
Added Latency & Hairpinning Medium (~1–3 ms extra network hop; potential cross-AZ hairpinning unless topology-aware routing is tuned). Low (~0.2–1 ms via local sidecar or eBPF/ambient node proxy; no central hairpinning). Zero network overhead (in-memory call within caller process).
Blast Radius & SPOF High if monolithic; requires HA multi-replica fleets and domain-sharded gateways to cap Tier-0 risk. Low per-workload blast radius (data plane distributed; control plane failure degrades config updates, not live traffic). Isolated strictly to a single service’s test process.
Infrastructure & FinOps Cost Moderate–High: HA gateway pods + mock clusters (Microcks/Prism) + self-hosted Pact Broker (MIT). Moderate–High: Per-node/sidecar memory & CPU overhead + mesh control plane + mock/contract tooling. Negligible (runs inside existing CI runners only).
Protocol & Mocking Ergonomics Strongest centralized policy, mocking/direct_response plugins, and unified team visibility for HTTP & gRPC. Strong HTTP/2 gRPC L7 splitting (GRPCRoute) & native SPIFFE mTLS; gateway-native mocking plugins are leaner. Full language-native flexibility, but zero live-traffic shadowing or canary graduation capability.
Operational Complexity Moderate: Familiar gateway lifecycle, but requires GitOps self-service CRDs to avoid platform ticket queues. High: Mesh upgrades, mTLS PKI lifecycle, eBPF/CNI kernel compatibility, and GAMMA spec maturity. Low: Standard language testing frameworks; no cluster routing layer to maintain.

FinOps & Operational Cost Reality: Running highly available East-West gateways, dedicated Microcks or Prism mock fleets, and a self-hosted open-source Pact Broker (MIT) consumes real cluster CPU, memory, and engineering maintenance hours. That investment pays back rapidly when 5+ polyglot teams integrate asynchronously across shared contracts—and burns unnecessary budget when a 3-person team could test against in-process adapters instead.

Socio-Technical Constraints: Beyond the Infrastructure Diagram

Architecture patterns fail far more often on human incentives than on YAML syntax. Adopting this pattern means trading application-level code coupling for disciplined organizational and operational craft:

3-Step Brownfield Migration Path

Teams inheriting legacy microservices cluttered with if (USE_MOCK) environment variables do not need a rewrite to adopt this pattern:

  1. Wrap & Route (Zero Behavior Change): Extract an explicit Outbound Port (PaymentPort) in the caller and point its adapter through the East-West gateway while temporarily retaining the legacy flag behind a thin shim—verifying baseline latency, mTLS, and OpenTelemetry tracing first.
  2. Stand Up Calibrated Mocks & Mirror: Deploy contract-driven mocks (Microcks or Prism) with realistic latency profiles behind the gateway, turn on CI schema parity (oasdiff + self-hosted Pact Broker), and validate Stage 1 read-only mirroring on a single low-risk endpoint.
  3. Shift Authority & Delete Legacy Flags: Move mock/live switching to declarative HTTPRoute / GRPCRoute manifests, confirm Served-By observability across dashboards, and permanently delete application-level mock conditionals and environment toggles.

When Not to Use This Pattern



References


Changelog