Envoy
medium 28 minEnvoy 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
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
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
criticalThree 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
criticalThe admin page can change logging, drain listeners and stop the process, and shows the configuration.
Wrongadmin: address: { socket_address: { address: 0.0.0.0, port_value: 9901 } }Rightadmin: address: { socket_address: { address: 127.0.0.1, port_value: 9901 } }A stream cut after 15 seconds
majorThe route timeout is 15 seconds by default and covers the whole answer, so long downloads and streams end early.
Wrongroute: { cluster: events }Rightroute: { cluster: events, timeout: 0s }# the stream idle timeout (5 minutes) still appliesRoute before cluster
majorA route to a cluster that Envoy does not know yet answers 503.
Wrongpush(RDS, "/ -> v2")push(CDS, "v2")Rightpush(CDS, "v2"); push(EDS, "v2")push(RDS, "/ -> v2")Outlier detection that can do nothing
minormax_ejection_percent is 10 by default. With three hosts, one is 33 percent, so no host is ever ejected.
Wrongoutlier_detection: {}Rightoutlier_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.