Skip to content

Distribute traffic across healthy capacity

11 min reading

Choose global/local routing and load-balancing behavior under uneven or failed capacity

Page details

System Design · Follow a request

11 min reading · 24 min with practice

Sources

Published · Last edited:

Prerequisite: Spend a latency budget. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Dev draws two application workers and divides Northwind’s selected fifteen-read-per-second burst between them. In this hypothetical rehearsal, one worker stops answering, yet the drawing still sends half the requests toward it. The earlier capacity estimate counted workers; it did not define how to choose a usable destination.

Dev: “The remaining worker has the example’s twenty-read capacity.”

Priya: “That helps only if requests reach it while the other is unavailable.”

Maya: “Show which evidence changes the routing decision, and what happens before that change.”

You will turn a worker count into a distribution policy: which destination is eligible, what health evidence supports that judgment and how uneven work affects the choice. The product-record service remains a shared dependency, so removing one application worker cannot settle every failure case.

Which capacity is actually eligible to serve?

A load balancer selects among destinations for incoming work. A transport-layer balancer can distribute connections, while an application-layer proxy can make decisions using HTTP requests. These boundaries matter: several requests can travel over one connection. Equal connection counts do not necessarily imply equal request counts or equal work.

In Northwind’s design, an HTTP reverse proxy receives catalogue reads and selects an eligible application worker. The workers do not hold essential visitor state locally, so either can serve the next anonymous read. The existing product-record service remains a downstream dependency. Routing around an application worker cannot repair a product service that every worker needs.

Keep regional destination selection separate from local worker selection. A name-resolution or global routing policy may direct a visitor toward a region. The regional proxy then selects a worker. A change in one layer need not immediately update every other layer, especially where clients reuse connections or cached name-resolution results.

Start with a policy you can explain

Round robin rotates assignments across eligible workers. With similar workers and many similarly costly requests, it is a useful baseline. Weighted routing deliberately gives some destinations a larger share. Neither policy creates capacity; both decide how existing capacity is used.

Least-connections routing uses active connection counts as a signal of outstanding work. It can help when connection counts track occupancy, but that proxy becomes less informative when connections carry different amounts of work. Choosing an algorithm requires understanding the unit it observes and the workload it is meant to balance.

Routing follows the eligible worker setA regional HTTP proxy selects worker A or worker B. A health observation removes B from new assignments after detection. Both workers share the same product service, which is outside this local failure remedy.Regional proxyEligible setWorker A20 reads/sWorker BUnhealthyProductservice
Removing a destination changes assignments. Shared dependency failure remains shared.

Separate request routing from connection placement

Hypothetical scenario. Choose one hundred active HTTP/2 streams carried by a single connection. An L4 balancer that assigns that connection to worker A has made one placement decision; counting connection assignments cannot establish equal request work across A and B. An L7 proxy may distribute eligible HTTP requests separately, while also terminating and managing their upstream connections.

Separate request routing from connection placement — selected design evidence
PhaseNew assignmentsExisting work
HealthyEligible by policyTracked normally
DrainingExclude workerFinish within drain bound
RemovedNo new trafficTerminate or recover by application contract
Draining changes eligibility before process termination; existing requests remain an explicit obligation.Draining changes eligibility before process termination; existing requests remain an explicit obligation. Healthy to Draining: exclude new work; Draining to Removed: finish or bound expires.HealthyDrainingRemovedexclude new workfinish or bound expires
Draining changes eligibility before process termination; existing requests remain an explicit obligation. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Least-outstanding-request routing can avoid a worker with many unfinished requests, but request count is still a proxy for work. One expensive request may consume more CPU or hold more memory than several cheap ones. Keep the selected twenty-qualifying-reads-per-second worker envelope tied to the original request mix.

Separate routing configuration from serving decisions. A control-plane outage need not stop a data plane that can safely use its last valid endpoint set. An endpoint becoming unhealthy, however, requires a bounded observation and removal path. During drain, stop new assignments, track existing work and set an explicit termination bound; removing a name does not migrate a live connection.

Check the survivor, not just the total

Hypothetical worked example. Preserve the selected capacity of twenty qualifying reads per second per worker. At fifteen reads per second, two equal workers receive an ideal long-run average of 15 ÷ 2 = 7.5 reads per second each. If one fails and routing converges to the survivor, fifteen is below twenty. This is the earlier single-failure capacity argument made concrete.

Now preserve the separate stress case of thirty reads per second. With two workers, normal ideal share is 30 ÷ 2 = 15 per second, but one survivor must accept thirty. Demand exceeds its selected capacity by 30 − 20 = 10 per second. Perfect routing cannot remove that deficit. Three workers leave (3 − 1) × 20 = 40 reads per second after one loss, giving a fluid-model margin of 40 − 30 = 10 per second.

Those calculations assume the selected capacity remains valid under the same latency and freshness conditions. If twenty was measured without the product-service wait or with a different connection mix, it cannot be transferred uncritically. Per-worker capacity is a workload-dependent observation to establish, not a hardware label.

Health is an observation with a delay

A passive health check learns from real request failures. An active probe sends separate checks. Either needs rules about what counts as failure, when to remove a worker and how to admit it again. A process answering a shallow probe can still fail catalogue lookups; a transient probe failure can also remove otherwise useful capacity.

Choose an illustrative two-second detection interval after a worker becomes unusable. Under ideal equal routing of fifteen requests per second, its assigned average rate is 7.5 per second. Over that interval, the fluid estimate is 7.5 × 2 = 15 affected assignments. This is not a bound on actual failures: request arrivals, in-flight work, thresholds and connection reuse can change the count.

That delay belongs in the failure model. Claiming seamless failover from a redundant worker count hides the requests sent before detection. Record what callers observe during detection, what can safely be retried and whether the survivor can absorb repeated attempts. Retry policy will receive its own treatment; redundancy alone does not define it.

Removal and recovery need their own behavior

Planned removal can stop new assignments while allowing suitable in-flight work to finish. That is connection or request draining, depending on the boundary. Abrupt failure offers no such cooperation. Distinguish both from deleting a destination name and assuming existing connections immediately disappear.

A recovered worker may have cold caches, empty connection pools or unfinished initialization. Returning its full weight immediately can make the first assignments slower than those on established workers. A gradual return may help, but its availability and precise behavior depend on the chosen proxy. Do not assume every product or edition implements the same controls.

In the wild: inspect the implementation’s unit

NGINX’s HTTP load-balancing guide documents round-robin, weighted and connection-based selection, with product-specific capabilities. It is a concrete place to check the policy’s observation boundary. A diagram labeled “NGINX” is still incomplete until the chosen method, health behavior and recovery policy are stated.

This chapter does not infer Northwind’s performance from that documentation. It uses the documented mechanisms to make a reviewable design. The latency budget and user-level acceptance test remain the evidence needed to evaluate whether that design works for the promotion.

When balanced assignments hide a broken path

Hypothetical failure scenario. Both workers pass a process-level check, but one has lost its connection to the product service. Round robin continues sending it catalogue reads. Infrastructure graphs show even distribution while visitors see intermittent failures. A check of the actual serving capability, combined with request-outcome evidence, reveals the mismatch.

A deeper check also has costs. Probing every dependency aggressively can add traffic or cause every worker to fail readiness during one shared downstream disturbance. Choose the signal to answer a specific routing question, and make shared-dependency behavior explicit rather than treating “deeper” as automatically better.

Use distribution where there is a real choice

Load balancing helps when several eligible destinations can perform the same operation. It cannot safely spread requests across workers with incompatible versions of a required contract, recover local session state that was never replicated, or turn a saturated shared database into independent capacity. These constraints should appear beside the routing choice.

Northwind’s immediate decision is a regional HTTP proxy with a stated eligible set, explicit detection behavior and capacity checked after loss. Keep the simple baseline while gathering duration and occupancy evidence. The next lesson examines the service boundary behind that proxy: what exactly is the worker promising, and how does a new downstream call spend the deadline?

Challenge the proposed mechanism

One zone is lost while a long-lived connection remains on its former endpoint. Does updating discovery finish failover?

Reveal the design reasoning

No. New routing and old connection recovery are separate. Reconnect under bounded retry and admission rules, check survivor capacity and preserve operation identity. Include detection lag and endpoint staleness in the failure ledger.

Decision and reconsideration: Choose routing units and drain policy explicitly. Reconsider the policy when the request-cost distribution or connection lifetime changes.

Challenge the arrows

  1. Two workers handle thirty reads per second normally. Is one-worker-loss capacity sufficient?

    Recompute after the loss

    No. One selected twenty-read-per-second worker remains against thirty demand. The deficit is ten per second. Distribution policy cannot substitute for survivor capacity or an explicit admission policy.

  2. A worker passes a process probe but cannot read product records. Is it eligible?

    Define healthy for the serving responsibility

    Not for a contract requiring that dependency, unless an approved alternative response can meet it. A running process establishes less than a usable catalogue path.

  3. Equal connection counts produce unequal latency. Should the counts be ignored?

    Inspect what each connection carries

    They remain useful observations, but may poorly represent request work. Compare request mix, concurrent exchanges and durations before choosing a more suitable signal or policy.

Routing can choose an eligible worker, but Northwind still needs to define what crosses the application boundary. Page 08 asks which service and API responsibilities belong together, and which extra waiting and failure cases a new boundary introduces.

Northwind decision log

Route only to destinations eligible for the catalogue contract.
Check capacity after loss and record the detection window separately.
Carry worker selection and remaining deadlines into the API boundary review.

Go deeper: routing and service health