Implementing Service Mesh Patterns

1. Service Mesh Pattern

AspectDetail
DefinitionInfrastructure layer providing service-to-service comms (mTLS, retry, LB, telemetry)
ArchitectureData plane (proxies) + Control plane (config)
ToolsIstio, Linkerd, Consul Connect, Cilium Service Mesh
BenefitCross-cutting concerns out of application code

2. Sidecar Proxy Pattern

AspectDetail
MechanismProxy container co-deployed with app container; intercepts traffic
ExamplesEnvoy (Istio), linkerd2-proxy
ProsApp language-agnostic; uniform behavior
ConsResource overhead per pod; latency adds
AlternativeSidecar-less mesh (Cilium, Istio Ambient)

3. Control Plane Pattern

ResponsibilityDetail
Config DistributionPushes routing/policy to proxies (xDS API)
Service DiscoveryTracks endpoint changes
Cert ManagementIssues mTLS certs (Citadel/Istio)
Telemetry CollectionAggregates from proxies
ExamplesIstiod, Linkerd control plane

4. Data Plane Pattern

ResponsibilityDetail
Traffic Interceptioniptables redirect to sidecar
RoutingL7 routing per request
Policy EnforcementmTLS, authz, rate limit
TelemetryEmit metrics, traces, logs
Performance~1-5ms latency overhead per hop typically

5. Service Mesh Security Pattern

FeatureDetail
Automatic mTLSIdentity for every workload; encrypt all traffic
AuthorizationPolicyAllow/deny by SPIFFE identity, namespace, method
JWT ValidationEnd-user auth at sidecar
Cert RotationAutomatic, short-lived (hours)

6. Traffic Management Pattern

CapabilityDetail
Routing RulesHeader / weight / path-based
Traffic SplittingCanary / A-B
Retries / TimeoutsPer-route policy
Fault InjectionTest resilience (delay, abort)
MirroringShadow traffic to new version

Example: Istio VirtualService Canary

apiVersion: networking.istio.io/v1
kind: VirtualService
metadata: { name: order }
spec:
  hosts: [order]
  http:
  - route:
    - destination: { host: order, subset: v1 }
      weight: 90
    - destination: { host: order, subset: v2 }
      weight: 10

7. Service Mesh Observability

SignalProvided By Mesh
Golden MetricsRPS, error rate, latency p50/p95/p99 per service
Service GraphAuto-generated dependency map (Kiali)
Distributed TracesAuto-spans for sidecar hops
Access LogsL7 request/response

8. Circuit Breaking in Service Mesh

SettingDetail
maxConnectionsPer upstream
maxPendingRequestsQueue depth
maxRequestsPerConnectionHTTP/2 stream cap
Outlier DetectionEject unhealthy hosts (consecutive 5xx)

9. Service Mesh Retry and Timeout

ParamDetail
attemptsTotal retry count
perTryTimeoutPer-attempt cap
retryOnConditions (5xx, gateway-error, reset)
retryBudgetCap retries vs total req (e.g., 20%)

10. Canary Traffic Routing

StrategyDetail
WeightedStart 1% → 10% → 50% → 100% based on metrics
Header-BasedInternal users / specific tenants
Auto-PromoteTools: Argo Rollouts, Flagger watch metrics, advance/rollback
RollbackImmediate weight=0 if SLO breach