Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal-proxy

Lightweight proxy server for Kamal

View on GitHub

15 documents · Updated Nov 18, 2026

docs / traffic-controls

Traffic pause and rollout controls

Traffic controls let an operator temporarily hold service requests or send a known share of requests to a second target set. They sit between the proxy's service routing and its upstream load balancing, so they can change traffic without changing the service's public host and path rules.

Control model

Each registered service has an active target group and can have a separate rollout target group. A pause state controls whether requests may proceed, while rollout settings decide which eligible requests use the rollout group.

ControlMain purposeAffects
PauseHold new work while existing work drainsThe whole service
StopReject service work with an operator messageThe whole service
Rollout splitSelect some requests for a new target groupRequests with a rollout cookie
Rollout enablementTurn the split on or off without removing targetsRollout selection only

The controls are independent of a normal deployment. A deployment can replace the active targets while the service stays paused, and a rollout can be prepared before any request uses it. See services and upstream targets for the target lifecycle.

Pause behavior

Pause states

The pause controller gives each service one of three states: running, paused, or stopped. A running service forwards requests. A paused service waits for new requests for a limited time. A stopped service rejects them and can include a stop message in the response.

Paused and stopped services still return success for their configured health-check request. This keeps an upstream service from removing the proxy from its own pool while an operator holds traffic. Other paused requests receive a gateway-timeout response when the pause limit expires. Other stopped requests receive a service-unavailable response.

References: internal/…/pause_controller.go• L9-15 internal/…/service.go• L642-666 internal/…/service_test.go• L199-223

Pause and drain sequence

Pausing first changes the service state, then drains connections in both the active and rollout target groups. The drain timeout limits how long existing work may continue. The pause timeout limits how long new work may wait before the proxy sheds it.

This diagram shows how a pause separates existing work from new work.

flowchart TD
    A[Pause service] --> B[Set state to paused]
    B --> C[Drain active and rollout connections]
    B --> D{New request}
    D -->|Health check| E[Return success]
    D -->|Resume before limit| F[Forward request]
    D -->|Pause limit expires| G[Return gateway timeout]

Resuming changes the state back to running and releases requests still waiting in the pause. Stopping a paused service releases those waiters as failures instead. The state remains separate from target deployment, so replacing active targets does not resume the service.

References: internal/…/service.go• L448-481 internal/…/service.go• L505-517 internal/…/pause_controller.go• L84-129 internal/…/router_test.go• L322-341

Progressive rollout behavior

Rollout target groups

A rollout is a second target group held beside the active group. The proxy can deploy it and check its health before enabling traffic. Replacing an existing rollout group drains the old rollout connections after the new group is installed.

The rollout group is not a fallback pool. It is selected only when the rollout controller matches the request. All other requests continue to use the active group.

References: internal/…/router.go• L151-205 internal/…/service.go• L241-255 internal/…/service.go• L527-535

Request selection

Rollout selection uses the kamal-rollout cookie as the request's stable value. When rollout is enabled, an allowlisted value always selects the rollout group. Other cookie values enter the group when their stable hash falls within the configured percentage. Requests without the cookie stay on the active group.

The allowlist and percentage work together. This lets an operator test a fixed set of users first, then increase the share without changing the target group. Disabling rollout keeps its settings and targets in place but sends all requests to the active group.

References: internal/…/rollout_controller.go• L9-16 internal/…/rollout_controller.go• L40-77 internal/…/rollout_controller_test.go• L11-62

Rollout lifecycle

The rollout lifecycle moves through target preparation, split configuration, traffic enablement, and cleanup. The operator can stop at any stage while the active group continues to serve normal traffic.

  1. Deploy healthy rollout targets for a registered service.
  2. Set a percentage, an allowlist, or both.
  3. Enable the rollout split.
  4. Observe the rollout and adjust the split as needed.
  5. Disable the split or remove the rollout targets.

Removing the rollout group clears its split settings. The proxy drains the removed group's existing connections, then routes matching requests to the active group because no rollout group remains.

References: internal/…/router.go• L180-258 internal/…/service.go• L258-311 internal/…/router_test.go• L830-924

Operator control surface

The command line interface sends control requests to the proxy over its local RPC control socket. Pause accepts separate drain and maximum-pause limits. Rollout commands deploy or remove target groups, set selection rules, and enable or disable selection.

Command familyRuntime action
pause <service>Hold new requests and drain current work
rollout deploy <service>Prepare rollout targets
rollout set <service>Set percentage and allowlist rules
rollout enable / disableStart or stop rollout selection
rollout remove <service>Remove rollout targets after draining

These controls complement the wider service operations and service deployment workflows. Deployment prepares target state; traffic controls decide when that state receives requests.

References: internal/…/pause.go• L16-39 internal/…/rollout.go• L9-21 internal/…/rollout_deploy.go• L15-41 internal/…/rollout_set.go• L15-39 internal/…/rollout_remove.go• L15-36 internal/…/commands.go• L84-167

State visibility and persistence

The service description exposes pause state and rollout status so an operator can see whether traffic is running and which rollout rules are active. The proxy saves these controls with service state, then restores them when it loads the service registry.

The saved state includes the pause controller, rollout controller, active targets, and rollout targets. Restoring a paused or stopped service restores its request behavior rather than only restoring a display value.

References: internal/…/service.go• L325-400 internal/…/service.go• L403-445 internal/…/router.go• L209-258

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the rollout cookie name and matching rules aligned with the client or deployment system that assigns rollout values.
  • Keep pause response behavior aligned with downstream health checks. A health check must remain successful during a deliberate pause or stop.
  • Keep target replacement and drain handling aligned for both active and rollout groups.
  • Keep service state serialization aligned with controller restoration so a restart does not silently change traffic state.
  • Keep CLI flags and RPC argument types aligned for drain, pause, percentage, allowlist, and rollout target operations.

Important failure modes

TriggerConsequenceGuard
A pause lasts past its maximum wait timeNew non-health requests return gateway timeoutResume the service or set a pause limit that covers the planned hold
A service is stoppedRequests return service unavailable with the configured messageResume the service when it should accept traffic again
Rollout is enabled without a rollout target groupThe control request fails because no rollout target existsDeploy and health-check rollout targets first
A request has no kamal-rollout cookieIt stays on the active target group even when rollout is enabledProvide the cookie through the rollout client or test path
Rollout targets fail health checks during preparationThe rollout group is not installedFix target health or use an explicitly forced deployment path where supported

Key files

FileWhy to read it
internal/…/service.goConnects pause decisions and rollout selection to request handling, target groups, state, and draining.
internal/…/pause_controller.goDefines the service pause, stop, resume, and wait behavior.
internal/…/rollout_controller.goDefines cookie-based allowlist and percentage selection.
internal/…/router.goExposes the runtime operations that install, configure, enable, disable, and remove rollout state.
internal/…/commands.goConnects the local RPC control surface to router operations.
internal/…/pause.goShows the operator inputs for pausing a service.
internal/…/rollout.goShows the rollout command family and its lifecycle actions.