envoy-guide
Module 7 · Going Deeper·14 min·advanced

Outlier detection — passive health checks done right

Eject misbehaving endpoints from the load-balancing pool based on real traffic signals.

Active vs passive health checks

Two ways to detect a broken upstream:

  • Active (health_checks on the cluster) — Envoy sends synthetic probes on a timer. Cheap to reason about; slow to react. A 10-second interval misses 9.9 seconds of broken traffic.
  • Passive (outlier_detection on the cluster) — Envoy watches real request outcomes and ejects misbehaving endpoints from the load-balancing pool. Zero extra requests; reacts within a few real failures.

The two are complementary, but outlier detection is the single biggest resilience win in Envoy — and the most commonly misconfigured feature.

Minimal envoy.yaml

YAML
clusters:
- name: backend
  connect_timeout: 1s
  type: STRICT_DNS
  load_assignment:
    cluster_name: backend
    endpoints:
    - lb_endpoints:
      - endpoint: { address: { socket_address: { address: api-a, port_value: 80 }}}
      - endpoint: { address: { socket_address: { address: api-b, port_value: 80 }}}
      - endpoint: { address: { socket_address: { address: api-c, port_value: 80 }}}

  outlier_detection:
    consecutive_5xx: 5                  # 5 in a row from one host -> eject
    consecutive_gateway_failure: 3      # 3 connect-fail/502/503/504 in a row
    interval: 10s                       # how often to sweep
    base_ejection_time: 30s             # first ejection length
    max_ejection_time: 300s
    max_ejection_percent: 50            # never eject more than half
    enforcing_consecutive_5xx: 100      # % chance to actually enforce
    success_rate_minimum_hosts: 3
    success_rate_request_volume: 50
    split_external_local_origin_errors: true

common_lb_config:
  healthy_panic_threshold:
    value: 50.0                         # default — and a footgun

Three knobs that bite you

max_ejection_percent defaults to 10%

With three endpoints and the default, Envoy will never eject anyone — 10% of 3 rounds down to 0. Set max_ejection_percent explicitly. 50% is sane for small clusters; combine with max_ejection_time so a flapping endpoint gets longer and longer timeouts (base × consecutive_ejections).

consecutive_5xx and consecutive_gateway_failure are separate counters

A 502 increments BOTH; a 500 only increments the 5xx counter. People assume one subsumes the other and end up with permissive thresholds. Configure both. Turn on split_external_local_origin_errors so client-induced 5xx (an upstream returning 500 because of bad input) doesn't falsely eject a healthy host.

The panic threshold silently disables outlier detection

If outlier detection ejects so many endpoints that fewer than healthy_panic_threshold percent (default 50%) remain healthy, Envoy enters panic mode and load-balances across all endpoints, including the ejected ones. "Better to try them all than serve nothing." Operators see ejected endpoints still receiving traffic and conclude outlier detection is broken. It isn't — you just need either more endpoints or a lower panic threshold (e.g. value: 0.0 to disable, accepting the risk of zero healthy upstreams).

Hands-on: prove the math, then prove the panic

Hands-on · Eject, panic, then fix the panic
  1. Run three upstream containers — one configured to return 500 on every request (httpbin.org/status/500 works in a pinch via DNS).

  2. Confirm outlier detection ejects the bad host within ~5 requests by polling the admin endpoint:

Shell
watch -n 1 'curl -s localhost:9901/clusters | grep -A2 backend'

The bad endpoint flips to outlier_check_failures_active::1.

  1. Now make two of the three fail. With default max_ejection_percent: 10 only one gets ejected. Raise max_ejection_percent to 67 — both get ejected, panic mode kicks in, and all three (including the dead two) start receiving traffic again.

  2. Lower healthy_panic_threshold to 0:

YAML
common_lb_config:
  healthy_panic_threshold: { value: 0.0 }

The dead ones now stay ejected. You'll see 503s for that fraction of traffic, but you won't get the worse "all hosts get traffic" failure mode.

  1. Add success_rate_* to use statistical detection: send 100 requests with one host failing 50% and others failing 1%. The slow host gets ejected based on success-rate stddev, not just consecutive failures.
Watch the right stats

The clarifying counters are outlier_detection.ejections_active (how many are ejected right now), ejections_consecutive_5xx (why), ejections_total (lifetime), and cluster.<name>.health_check.healthy (overall pool size). Watch them in Grafana.

Real-world example · Triton Gaming (matchmaking)
Problem
Their matchmaking API runs across 12 pods behind Envoy. A bad deploy landed on 2 pods that returned 500s on a specific code path. Active health checks pinged /healthz (still 200) so they kept getting traffic. P99 errors spiked, on-call paged.
Envoy solution
Outlier detection saw consecutive_5xx >= 5 on the bad pods within seconds, ejected them, traffic shifted to the healthy 10 pods. On-call got a clean 'elevated 5xx rate' alert instead of an outage. The bad pods rolled back automatically when their CrashLoopBackoff state was finally noticed by k8s.

Active + passive together

Use both. Active checks catch endpoints that look healthy but aren't serving real traffic (cold starts, just-restarted pods). Passive detection catches endpoints that look fine to a probe but mishandle real workloads (bad code path, hot-spot DB rows, GC pauses).

YAML
  health_checks:
  - timeout: 1s
    interval: 5s
    unhealthy_threshold: 2
    healthy_threshold: 2
    http_health_check:
      path: "/healthz"
      expected_statuses: [{ start: 200, end: 300 }]

  outlier_detection:
    consecutive_5xx: 5
    max_ejection_percent: 50
    base_ejection_time: 30s

That combo catches both classes of failure with sub-second reaction times.

Quick check

By default, with 3 endpoints, why does outlier detection appear to never eject anyone?

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3