Sidecar proxy concept (Envoy) in Kubernetes - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the work done by a sidecar proxy like Envoy grows as the number of service requests increases.
How does Envoy handle more requests and what costs grow with more traffic?
Analyze the time complexity of the following Envoy sidecar proxy configuration snippet.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: myapp
image: myapp:latest
- name: envoy
image: envoyproxy/envoy:v1.22.0
args: ["-c", "/etc/envoy/envoy.yaml"]
This snippet shows a pod running two containers: the main app and the Envoy sidecar proxy that intercepts and routes traffic.
- Primary operation: Envoy processes each incoming network request by inspecting and routing it.
- How many times: Once per request, so the number of operations grows with the number of requests.
As the number of requests increases, Envoy must handle each one, so the work grows steadily.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 request processing steps |
| 100 | 100 request processing steps |
| 1000 | 1000 request processing steps |
Pattern observation: The work grows directly with the number of requests, doubling the requests doubles the work.
Time Complexity: O(n)
This means the time Envoy takes grows in a straight line with the number of requests it handles.
[X] Wrong: "Envoy processes all requests at once, so the time stays the same no matter how many requests come in."
[OK] Correct: Envoy handles each request individually, so more requests mean more work and more time.
Understanding how sidecar proxies scale with traffic helps you explain real-world service mesh behavior clearly and confidently.
"What if Envoy used multiple threads to handle requests in parallel? How would the time complexity change?"
Practice
Solution
Step 1: Understand the role of sidecar proxies
Sidecar proxies like Envoy run alongside the main app to handle network tasks such as routing, security, and monitoring.Step 2: Identify what sidecars do not do
They do not replace the app, store data, or run databases; they only assist with traffic management.Final Answer:
To manage network traffic for the application without changing its code -> Option AQuick Check:
Sidecar proxy = traffic manager [OK]
- Thinking sidecar replaces the app container
- Confusing sidecar with storage or database
- Assuming sidecar changes app code
Solution
Step 1: Identify the correct container name and image
The sidecar container should be named clearly (e.g., 'envoy') and use the official Envoy image 'envoyproxy/envoy'.Step 2: Check the options for correctness
containers: - name: envoy - image: envoyproxy/envoy correctly names the container 'envoy' and uses the right image. containers: - name: app - image: envoyproxy/envoy misnames the container as 'app'. containers: - name: envoy - image: nginx uses the wrong image 'nginx'. containers: - name: envoyproxy - image: envoyproxy/envoy uses a different container name but correct image.Final Answer:
containers: - name: envoy - image: envoyproxy/envoy -> Option BQuick Check:
Envoy container name and image must match [OK]
- Using wrong container name for Envoy
- Using incorrect image like nginx
- Mixing app container with sidecar container
Solution
Step 1: Understand Envoy's role as a sidecar proxy
Envoy intercepts outbound requests from the app container to manage traffic, security, and monitoring.Step 2: Trace the request flow
The app's request is routed through Envoy before reaching the external service, enabling control and visibility.Final Answer:
The request is intercepted and routed through the Envoy sidecar proxy before reaching the external service. -> Option DQuick Check:
Envoy intercepts outbound traffic [OK]
- Assuming app bypasses Envoy for external calls
- Thinking Kubernetes blocks outbound requests
- Believing requests are duplicated
Solution
Step 1: Analyze Envoy sidecar traffic issues
Envoy needs proper network permissions (like NET_ADMIN) to intercept and forward traffic.Step 2: Evaluate other options
App image version or node CPU issues may affect performance but not specifically Envoy forwarding. A pod with one container means no sidecar exists.Final Answer:
The Envoy container is missing required network permissions or capabilities. -> Option CQuick Check:
Envoy needs network permissions to forward traffic [OK]
- Blaming app container image for Envoy issues
- Ignoring network capabilities needed by Envoy
- Assuming pod must have one container only
Solution
Step 1: Understand sidecar pattern in Kubernetes
Sidecars run as additional containers in the same pod, so modifying the pod spec to add Envoy is the standard way.Step 2: Evaluate alternatives
Replacing app image changes code, separate pods lose pod-local benefits, and init containers run before app start and can't run sidecars.Final Answer:
Modify the deployment YAML to add an Envoy container in the pod spec as a sidecar -> Option AQuick Check:
Add Envoy as sidecar container in pod spec [OK]
- Replacing app image instead of adding sidecar
- Using separate pods losing sidecar benefits
- Misusing init containers for sidecar functionality
