Load Balancing and Traffic Management Questions
Distributing requests across capacity: load-balancing algorithms (round-robin, least-connections, consistent hashing), L4 versus L7 balancing, health checks, and traffic shaping. Covers sticky sessions, canary and blue-green routing, rate limiting, and graceful draining. The traffic-distribution layer that keeps a scaled system balanced and available.
Explain TLS termination patterns at the load balancer: edge termination (decrypt at the edge), passthrough (forward TLS to the backend), and re-encryption (terminate and re-establish TLS to the backend). For each, describe certificate management and rotation, the security trade-offs, and the performance implications. How would you rotate certificates across a fleet of edge load balancers with zero downtime?
Sample Answer
Direct answer
Edge termination is simplest and fastest but leaves the network between the load balancer and the backend unencrypted, so it's appropriate when that network is genuinely trusted or segmented. Passthrough preserves end-to-end encryption but blinds the load balancer to anything above TCP (no L7 routing, no WAF, Web Application Firewall: a layer that inspects and can block malicious HTTP traffic before it reaches a backend). Re-encryption gets you both: L7 visibility and encryption all the way to the backend, at the cost of extra CPU and a second certificate/trust relationship to manage. It's the default choice for anything regulated or zero-trust.
Comparison
| Pattern | Certificate management | Security | Performance |
|---|---|---|---|
| Edge termination | One certificate (or set) on the LB, centrally rotated; backends need none | Weakest: the LB-to-backend hop is plaintext, relies on network trust/segmentation | Fastest: TLS cost is paid once at the LB, enables caching and L7 features |
| Passthrough | Certificates live on every backend instance, rotated per-instance (or via shared config management) | Strongest confidentiality: encrypted end to end, but the LB can't inspect or route on L7 content, SNI (Server Name Indication, the hostname the client sends in cleartext at the start of the TLS handshake, before encryption begins) is all it sees | LB is cheap, but backends each pay full TLS cost, and cert rotation ops scale with fleet size |
| Re-encryption | Two certificate sets: a public certificate on the LB for clients, an internal certificate (often short-lived, PKI-issued, meaning issued by a public key infrastructure: a trusted system of certificate authorities that issue and validate certificates) for LB-to-backend, ideally mutual TLS | Strong: encrypted end to end, and the LB can inspect or enforce policy since it briefly holds the plaintext; mTLS adds backend authentication of the LB itself | Most expensive: decrypt once and re-encrypt once at the LB, plus backend TLS cost |
Worked angle: re-encryption plus mutual TLS
When re-encryption also uses mutual TLS on the LB-to-backend hop, the backend authenticates the load balancer's identity, not just the reverse, which closes the gap that pure re-encryption leaves open: without mTLS, anything that can reach the backend's plaintext-adjacent port on the internal network can impersonate the LB. This is the pattern to reach for whenever the internal network can't be assumed trusted (multi-tenant clusters, zero-trust internal networking, compliance requirements for encryption in transit end to end).
Zero-downtime certificate rotation across a fleet
The sequencing matters more than any single step:
- Provision the new certificate (and, if the intermediate CA is changing, the new chain) alongside the old one, don't replace in place.
- Push the new certificate to a small canary subset of edge load balancers first, and verify handshakes succeed and the chain validates from real clients before going further, the same caution as a canary code deploy.
- Roll the new certificate out to the rest of the fleet; most LB software can hot-reload a certificate without dropping existing connections (an SNI-based reload swaps the certificate used for new handshakes only, in-flight connections keep using whatever certificate they already negotiated).
- Only after the entire fleet is confirmed serving the new certificate, retire the old certificate and, if applicable, the old intermediate CA; some clients cache the old chain, and dropping it too early breaks them.
- Automate this: private keys should never be manually copied between hosts. Use a PKI or secrets system (short-lived certificates issued per instance, or a central certificate manager pushing rotations) so rotation is routine, not an incident.
Trade-offs and pitfalls
- Passthrough looks like the "most secure" default, but it forfeits L7 routing and WAF entirely; that's not a security trade-off, it's a capability you're giving up, so confirm you actually don't need it before choosing passthrough.
- Re-encryption's extra CPU cost is real but mitigated by TLS session resumption/reuse between the LB and backend, reusing the internal session instead of a full handshake per request; skipping that optimization is the most common reason re-encryption "feels too slow" in practice.
- An intermediate CA change is the rotation scenario that breaks people: old certificates signed by the old intermediate remain valid until they expire, but new certificates from the new intermediate need the new chain distributed everywhere first, or clients that haven't cached the new intermediate will fail to validate.
- Never let certificate expiry be the trigger for rotation; monitor days-to-expiry and rotate on a schedule well ahead of it. An expired certificate during an incident is a wholly avoidable outage.
You're the on-call SRE lead when the global load balancer's TLS certificate unexpectedly expires, causing global 503 errors. Walk through your immediate triage steps, the short-term mitigation to restore traffic, how you'd communicate with stakeholders and customers, and the long-term remediation and process changes you'd propose.
Sample Answer
Direct answer
This is a deterministic-cause outage: the fix is to restore traffic through a path that has a valid certificate (failover to a standby LB, hot-load a backup cert, or temporarily terminate TLS elsewhere) as fast as possible, communicate on a fixed, predictable cadence while that happens, and then treat the root cause as a monitoring and automation gap rather than a one-time human mistake, since a cert that reached expiry without anyone acting means the process that was supposed to catch it failed silently well before the outage.
Immediate triage (first ~15 minutes)
- Confirm scope and cause: check LB logs for TLS handshake failures and the certificate's expiry timestamp to distinguish a cert issue from an application or network issue reporting similar symptoms (global 503s can also come from a bad deploy or DNS problem).
- Freeze churn: pause any in-flight deploys or automated config pushes so the incident isn't complicated by unrelated changes landing mid-triage.
- Pull in the right people: notify infra/network/security on-call and declare an incident commander if this is genuinely global impact.
Short-term mitigation
- Fastest path: if a hot-standby LB or path with a valid certificate exists, shift traffic to it (DNS weight change or traffic steering) rather than trying to fix the primary path under pressure.
- If the LB supports multiple certs or hot-reload, load a previously-issued backup/rollover certificate if one exists.
- If neither is available, use automated ACME (Automatic Certificate Management Environment, the protocol that lets software request and renew certificates without a human) / CA (certificate authority, the trusted party that issues certificates) tooling to issue a short-lived emergency certificate and install it, prioritizing the automated path over manual cert generation to reduce the chance of a second mistake under time pressure.
- As a last resort only, and only if policy allows, terminate TLS at a CDN or edge proxy that already has a valid cert and forward over a private/trusted link to the backend.
- Validate before declaring resolved: run synthetic TLS handshakes and smoke tests against key endpoints, not just "the dashboard looks green."
Stakeholder and customer communication
- Acknowledge within the first ~10 minutes: post to the status page and internal channels with scope, known impact, and a time for the next update, even if the next update is "still investigating."
- Update on a fixed cadence (every 15-30 minutes) regardless of whether there's new information, since silence reads worse than "no change yet" during a global outage.
- Close the loop once restored with an accurate timeline and a plain-language root cause, then follow with a fuller postmortem summary to execs, product, and customer-facing teams so they can answer customer questions consistently.
Long-term remediation and process changes
- Automate the full certificate lifecycle (issuance and renewal) end to end so a human is never the trigger for routine renewal; the emergency manual path should exist only as a fallback, not the primary mechanism.
- Alert on the action, not just the deadline: a single "certificate expires in N days" alert is not enough, because it doesn't distinguish "renewal will happen automatically before then" from "renewal has already been silently failing." A stronger design pages a human if both conditions hold: fewer than a threshold of days remain, and there has been no successful renewal within the automation's normal cycle. For example, with a 90-day certificate and automation that renews at the 30-days-remaining mark, an escalation alert at 14 days remaining plus "no successful renewal event logged in the last 16 days" catches a silently-failing automation with real margin before it becomes a repeat of this incident, rather than firing on the same schedule the (broken) automation was supposed to act on.
- Rehearse the failure: run a game day where the cert automation is deliberately disabled and confirm the escalation alert actually fires and the manual fallback actually works, rather than assuming it does.
- Track the postmortem to closure with named owners and deadlines for the automation and alerting changes, not just the incident write-up.
Trade-offs and pitfalls
- A pure "days until expiry" alert is the common mistake: it looks reasonable until you realize it fires on the same cadence the automation was already supposed to satisfy, so if the automation silently breaks right after a renewal, the alert doesn't add meaningfully more warning time than the automation's own schedule did. Tying the alert to "no successful renewal observed" closes that gap.
- Emergency manual certificate issuance under time pressure is itself a risk (wrong domain, wrong chain, wrong key usage); preferring automated emergency issuance over a fully manual process reduces that risk even during an incident.
- Communicating on a fixed cadence even with "no update" costs credibility less than going silent, but it does require someone dedicated to comms so the person fixing the issue isn't also the one writing status updates.
Compare the common load balancing algorithms: round robin, weighted round robin, least connections, and consistent hashing. For each, explain how it behaves under variable request latencies, long-lived connections such as WebSockets, and heterogeneous backend capacity, and give one production use case and one drawback. When would health checks and session affinity change which algorithm you pick?
Sample Answer
Direct answer
Round robin, weighted round robin, least connections, and consistent hashing differ mainly in what signal they use to pick a backend: round robin uses none (pure sequence), weighted round robin uses a static capacity ratio, least connections uses live connection counts, and consistent hashing uses a deterministic key (session id, user id) rather than load at all. That difference in signal is exactly why they behave so differently under variable request latency, long-lived connections, and mixed backend capacity.
Structured elaboration
| Algorithm | Behavior | Variable request latency | Long-lived connections (WebSockets) | Heterogeneous capacity | Production use case | Main drawback |
|---|---|---|---|---|---|---|
| Round robin | Cycles requests through servers in fixed order | Poor: ignores how long a prior request is taking | Poor: a server holding several long connections still gets the next new one | Poor: treats all servers as equal capacity | Homogeneous fleet, short uniform requests (static assets) | Blind to actual load; one slow server keeps getting new work |
| Weighted round robin | Same cycle, but servers get requests proportional to a static weight | Same blind spot as round robin, just scaled by weight | Same as round robin, scaled by weight | Good, if weights reflect real capacity | Mixed instance sizes with known, stable capacity ratios | Weights are static; does not react to a live spike |
| Least connections | New request goes to the server with fewest active connections | Good: naturally favors servers not stuck on slow requests | Good: avoids piling more work on a server already holding many long sessions | Needs weighting; assumes equal cost per connection otherwise | Variable-duration requests, streaming, WebSocket-heavy services | Needs an accurate, ideally shared, connection count; degrades to round robin if counts are only local per LB replica |
| Consistent hashing | Deterministic key (e.g. session id) maps to a server via a hash ring (both servers and keys are hashed onto points on a circle; a key is served by whichever server's point comes first walking clockwise from the key's own point) | Neutral: does not react to load at all | Excellent: same client always lands on the same server without a central session store | Needs virtual nodes weighted by capacity | Caches, CDNs, or any workload that needs strong affinity without a session store | Balances key placement, not load; a single hot key still lands entirely on one node |
When health checks and session affinity change the pick: if backends must hold session state without an external store, consistent hashing (or cookie-based affinity layered on any of the other three) becomes close to mandatory regardless of its load-balancing weaknesses. If health checks are slow to detect a failing node, least connections is more forgiving than round robin because it naturally routes fewer new requests to a node that is already accumulating unanswered connections, buying time until the health check catches up.
Worked example
Two backends, A and B, where A has twice the capacity of B (weight ratio 2:1). A weighted round robin scheduler realizing that ratio with a repeating pattern of period 3, "A, A, B", sent over 9 requests: A, A, B, A, A, B, A, A, B. Counting assignments: A receives requests 1, 2, 4, 5, 7, 8 (6 total), B receives requests 3, 6, 9 (3 total). That is 6:3, which simplifies to 2:1, exactly matching the configured weight, with no need to observe live load at all.
Consistent hashing, traced the same way: using a simplified illustrative hash (real systems use SHA-256 or similar, not this), sum a key's ASCII codes and take the result mod 100 to place it on a 0-99 ring. Three servers sit at fixed ring positions: X = 25, Y = 60, Z = 90 (a key is served by the first server whose position is at or after the key's hash, walking clockwise and wrapping to X if the hash is past the last position).
| Key | ASCII sum | mod 100 | Routed to |
|---|---|---|---|
| "session-42" | 919 | 19 | X (25) |
| "session-77" | 927 | 27 | Y (60) |
| "session-3" | 868 | 68 | Z (90) |
Now remove X from the ring (a node failure or a planned decommission): "session-42" (hash 19) has no server at or after position 19 until Y at 60, so it remaps from X to Y. "session-77" and "session-3" are untouched, since Y and Z were never X's successor for their hashes. This is the traced version of the bounded-remap claim in the table above: removing one of three nodes only disturbs the keys that node actually owned, not the whole ring.
Trade-offs & pitfalls
- Least connections needs an accurate, ideally shared, view of active connections per backend. Behind multiple load balancer replicas each keeping its own local count, the counts are only approximations, and the algorithm's advantage over round robin shrinks.
- Consistent hashing balances key placement, not load. A single popular key still lands entirely on one node no matter how good the hash function is; that is a cache-hot-key problem, not something the algorithm fixes.
- Common wrong turn: reaching for consistent hashing "for scalability" when the actual requirement is even load distribution. It solves affinity and cache locality, not general load balancing; without capacity-weighted virtual nodes it can be less balanced than plain least connections.
A client asks you to choose between a managed cloud load balancer (like AWS ALB/NLB), an open-source proxy (NGINX/HAProxy), and an Envoy-based service mesh. Build a selection rubric covering scalability, supported protocols and features, management overhead, and cost, and recommend an approach for a 200-service enterprise.
Sample Answer
Direct answer
Build the choice as a scored rubric across scalability, protocol/feature support, management overhead, and cost, then let the traffic pattern decide the split: use a managed cloud LB at the edge for north-south traffic regardless of the rest of the answer, and reserve the OSS-vs-mesh decision for east-west, service-to-service traffic, since the three options aren't really mutually exclusive at 200-service scale, they're complementary layers.
Structured elaboration: the selection rubric
Score each option 1 (weak) to 5 (strong) per dimension for the specific environment (here: multi-AZ cloud deployment, moderate-to-high east-west traffic, mTLS and fine-grained observability required, team can grow SRE capacity but wants cost discipline):
| Dimension | Managed cloud LB (ALB/NLB) | OSS proxy (NGINX/HAProxy) | Envoy-based mesh |
|---|---|---|---|
| Scalability | 5, autoscaled by the provider, no capacity planning | 3, scales well but you own the capacity planning and HA | 4, scales roughly linearly with services, but the control plane needs its own scaling plan |
| Protocol/feature support | 4, HTTP/1.1, HTTP/2, WebSocket, basic L7 routing; limited deep app-level policy | 4, rich routing and scripting (e.g. Lua), broad protocol support, config is fully in your hands | 5, first-class gRPC/HTTP2, retries, timeouts, circuit breakers, fault injection, weighted/subset routing |
| Management overhead | 5, lowest, provider-operated | 2, you own deployment, scaling, patching, and config management end to end | 3, moderate to high: control plane (the centralized system that computes and pushes routing/policy configuration out to every proxy) and sidecar (a small proxy process deployed alongside each service instance that the mesh routes traffic through, instead of the app talking to the network directly) lifecycle, certificate rotation, upgrade coordination |
| Security | 4, TLS at the edge, WAF (web application firewall, which filters malicious HTTP requests) integration available | 3, you manage TLS termination and rotation yourself | 5, mTLS (mutual TLS: client and server both authenticate each other via certificates) and per-service identity largely by default |
| Observability | 3, access logs and aggregate metrics, no per-call tracing without app-level work | 3, custom metrics/logs, requires your own instrumentation | 5, distributed tracing, per-route metrics, service maps near-automatically |
| Cost (TCO) | 4, higher per-request pricing offset by near-zero ops cost | 4, low infrastructure cost, higher people cost | 3, sidecar CPU/memory overhead per instance plus control-plane and ops investment |
Worked example: scoring the recommendation
Summing the six dimensions above (unweighted, for illustration; a real rubric would weight dimensions by what the org actually cares about):
ALB/NLB total=5+4+5+4+3+4=25 NGINX/HAProxy total=3+4+2+3+3+4=19 Envoy mesh total=4+5+3+5+5+3=25The tie between the managed LB and the mesh is the point, not a coincidence: they score highest on different dimensions (ops simplicity vs. observability and policy control) because they solve different problems. That's the argument for a hybrid rather than picking a single winner from the sum.
Recommendation for a 200-service enterprise
- Edge (north-south): managed cloud LB (ALB/NLB). Handles TLS termination, WAF, and DDoS protection with near-zero operational burden, this is not where the interesting trade-off is.
- East-west (service-to-service): Envoy-based mesh, adopted incrementally. This is where the mesh's mTLS-by-default, fine-grained retry/circuit-breaker policy, and automatic tracing earn their operational cost at 200-service scale, a scale where manually wiring TLS and tracing per service would be far more expensive than the mesh control plane.
- Reserve plain NGINX/HAProxy for specific pockets: legacy monoliths not yet mesh-integrated, or workloads needing custom scripting the mesh's policy surface doesn't cover.
Rollout plan to bound risk:
- Pilot the mesh on 10 to 20 non-critical services first; validate mTLS, tracing, and latency overhead against real traffic before wider rollout.
- Automate sidecar injection and policy-as-code so config changes are reviewed the same way application code is.
- Watch sidecar CPU/memory overhead and control-plane push latency as adoption grows past the pilot, this is the axis most likely to surprise a team scaling past a few dozen services: at 200 services averaging 20 instances each, a naive full-state config push touches roughly all 4,000 sidecars (200 x 20) on every single endpoint change, so a mesh control plane needs incremental, delta-only pushes, or a routine pod restart anywhere in the fleet turns into a mesh-wide config storm.
Trade-offs and pitfalls
- A rubric with unweighted dimensions can mislead. The 25-25 tie above only makes sense once you decide which dimensions actually matter for this org, a security-and-compliance-heavy environment should weight the security and observability rows far higher than the raw sum suggests.
- "Managed" reduces ops burden but also reduces control. A managed LB's feature roadmap and support SLAs become dependencies you don't own; that's a real cost even when it doesn't show up as a rubric number.
- Mesh adoption cost is back-loaded, not front-loaded. The pilot phase looks cheap; the real cost shows up in certificate lifecycle management, control-plane HA, and upgrade coordination once hundreds of services depend on the mesh being correct.
- Don't let the rubric replace a pilot. Scores are directional; only a real pilot against production-shaped traffic reveals whether the latency overhead and operational load are actually acceptable for this specific org.
What observability signals (metrics, logs, traces) would justify automatically removing an instance from load balancer rotation before users see errors? For each signal, describe roughly what threshold or pattern would trigger removal and one way that signal could produce a false positive.
Sample Answer
Direct Answer
Pull an instance automatically only when a signal shows a sustained departure from its own steady-state baseline, smoothed over a short window, and prefer requiring at least two independent signals to agree before removing an instance, rather than trusting any single metric. The one exception is a hard, unambiguous signal, like a completely unresponsive health-check endpoint, which should short-circuit straight to removal since there's nothing left to corroborate.
Signals, Triggers, and False-Positive Modes
The table below spans all three signal categories the question names, metrics, logs, and traces, not just the metrics-heavy ones that are easiest to instrument first.
| Signal | Example trigger pattern | A way it produces a false positive |
|---|---|---|
| Error rate (5xx / exceptions) | Sustained error rate over 5% for 2 minutes, or a spike over 20% for 30 seconds | A misbehaving upstream client, or a brief warm-up period right after deploy |
| Latency / SLO breach | p95 over the SLO (service-level objective, the reliability target you've committed to) target for 3 consecutive windows | A GC pause during a low-traffic period, or one unusually large request skewing a small sample |
| Failed readiness probes | 3 consecutive failed probes at a 10s interval | A brief network blip between the load balancer and the instance, unrelated to the instance's actual health |
| Resource exhaustion (CPU, memory, file descriptors) | CPU over 90% for 5+ minutes, or FD usage over 95% | A scheduled batch job or legitimate traffic surge, not an actual degradation |
| Connection/thread pool saturation | Pool at max for 2+ minutes with a growing queue | A slow downstream dependency backing up the queue, not a fault in this instance itself |
| Downstream timeout rate (from traces) | Over 10% of traces show upstream-to-downstream timeouts in a 5 minute window | A scheduled maintenance window on the downstream service, not a problem with this instance |
| Structured error-log pattern (logs) | A specific stack-trace signature, or a rate of "connection refused" / "out of memory" log lines, exceeding N occurrences within a 2-minute rolling window | A noisy but harmless dependency that logs every retry attempt as an error line even though the retry itself eventually succeeds, inflating the log-based count without any real user-facing failure |
Smoothing and Windowing
Use a rolling window (not an instantaneous sample) for every signal except hard health-check failure, and require the trigger condition to hold across the whole window rather than at a single point. This is what separates "sustained degradation" from "one bad request." The window length is a direct trade-off against detection speed: shorter windows catch real problems faster but inherit more noise from small sample sizes, especially on low-traffic instances where a 2-minute window might contain only a handful of requests.
Combining Signals to Cut False Positives
Requiring two independent signals to agree before acting cuts the false-positive rate multiplicatively, at the cost of occasionally missing a real problem that only shows up in one signal. Suppose each of three independent signals (error rate, latency, saturation) has an independent 1% chance of a false trigger in any given window (p=0.01). Requiring any 2 of 3 to agree:
P(at least 2 of 3 trigger)=(23)p2(1−p)+(33)p3 =3×0.0001×0.99+0.000001=0.000297+0.000001=0.000298Compared to acting on any single signal alone (p=0.01), that's a reduction of:
0.0002980.01≈33.6×fewer false removals, assuming the signals really are independent. In practice error rate and latency are often correlated (a struggling instance tends to show both), so the real-world reduction is smaller than this idealized number, but the direction and the general logic hold: corroboration is strictly cheaper in false positives than any single signal.
Trade-offs and Pitfalls
- A hard signal (health-check endpoint completely unreachable) should bypass the corroboration requirement entirely; waiting for a second signal to agree that a dead instance is dead only adds latency for no benefit.
- Combining signals reduces false positives but can delay detection of a real problem that manifests in only one signal strongly (say, a memory leak that spikes memory well before latency degrades); the corroboration requirement is a precision/recall trade (catching more real problems, higher recall, versus fewer false alarms, higher precision, pull in opposite directions), not a free lunch.
- Automated removal needs its own safety valve: a cap on how many instances can be removed in a short window, so a correlated event (a bad deploy, a shared dependency outage) that trips the same signal across many instances at once doesn't remove enough capacity to cause the outage it was meant to prevent.
- Removal should default to a graceful drain (stop new traffic, let in-flight requests finish) rather than an immediate hard kill, except when the health signal indicates the instance can no longer serve any traffic at all.
Unlock Full Question Bank
Get access to all Load Balancing and Traffic Management interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.