AlgoViz

Envoy

medium 28 min

Envoy is an open source network proxy that runs at the edge or beside every service.

See it run

One request through the filters, a safe config change, ejecting a bad host, a retry budget and picking a host.

Operations

One request

Listener, filters, router, endpoint. The first endpoint refuses and the request is retried.

Step 1 of 6

Connect

Our systemClientListenerTLS, by SNIHTTP filtersRouterEndpoint 1Endpoint 2

One worker thread accepts the connection and keeps it for life. The listener picks the filter chain.

Step 1: Connect

def handle(conn):    chain = listener.match(conn)          # by SNI, address    req = chain.decode(conn)    for f in chain.http_filters:          # auth, limits, ...        if f.on_request(req) == STOP: return f.answer    cluster = route(req)                  # the router is last    for _ in range(1 + retries):        resp = pick(cluster).send(req)        if not retriable(resp): break    return resp                           # filters in reverse
Work
1 request
Where state lives
One worker thread

The router is always the last HTTP filter.

In the real world

The same envoy doing real jobs. Pick one and step through it.

Data plane and control plane fail separately.

Step 1 of 4

Normal

Our systemxDSCallersControl planestreamingEnvoyconfig v12Host 1Host 2

The control plane streams routes and hosts. Requests do not pass through it.

Step 1: Normal

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Retries at every hop

    critical

    Three hops with two retries each can turn one request into 3 x 3 x 3 = 27 at the bottom.

    Wrong
    # every serviceretry_policy: { num_retries: 2 }
    Right
    # one layer retries, with a budgetretry_policy: { num_retries: 1, retry_on: "connect-failure" }retry_budget: { budget_percent: { value: 20 } }
  • The admin port on all addresses

    critical

    The admin page can change logging, drain listeners and stop the process, and shows the configuration.

    Wrong
    admin:  address: { socket_address:    { address: 0.0.0.0, port_value: 9901 } }
    Right
    admin:  address: { socket_address:    { address: 127.0.0.1, port_value: 9901 } }
  • A stream cut after 15 seconds

    major

    The route timeout is 15 seconds by default and covers the whole answer, so long downloads and streams end early.

    Wrong
    route: { cluster: events }
    Right
    route: { cluster: events, timeout: 0s }# the stream idle timeout (5 minutes) still applies
  • Route before cluster

    major

    A route to a cluster that Envoy does not know yet answers 503.

    Wrong
    push(RDS, "/ -> v2")push(CDS, "v2")
    Right
    push(CDS, "v2"); push(EDS, "v2")push(RDS, "/ -> v2")
  • Outlier detection that can do nothing

    minor

    max_ejection_percent is 10 by default. With three hosts, one is 33 percent, so no host is ever ejected.

    Wrong
    outlier_detection: {}
    Right
    outlier_detection:  consecutive_5xx: 5  max_ejection_percent: 34   # 1 of 3 hosts

Interview tips

  • How to explain it

    • A proxy beside every service.
    • Apps talk to localhost.
    • Config arrives by API, not by file.
  • Five words

    • Listener, filter, route.
    • Cluster, endpoint.
    • The router is the last filter.
  • Safe defaults to check

    • Route timeout 15 s.
    • 1,024 connections per cluster.
    • No retries until you ask.
  • Before production

    • Admin on localhost.
    • A retry budget.
    • Alerts on rejected config.