Skip to content

Dynamic Config ​

zero keeps runtime-mutable config as remote-polled values: an endpoint you control exposes the value, the app polls it on a cron schedule, and the latest value is applied in-process. There is no config server, port, or admin route — the app is always the caller (pull, not push), and the feature is off unless a URL is set.

The shipped instance is remote log-level sync. REMOTE_LOG_URL plus a cron is also the pattern to copy for your own feature flags.

How REMOTE_LOG_URL works ​

  1. Register the endpoint as an outbound service. The service name zero-remote-log resolves auth and circuit-breaker defaults as SERVICE_ZERO_REMOTE_LOG_* — the same as any other outbound call (see Http Service).

    zig
    try self.addHttpService("zero-remote-log", url, .{});
  2. Poll it on a cron. The schedule comes from REMOTE_LOG_REFRESH_INTERVAL (seconds, default 30):

    zig
    // "*/30 * * * * *" — every 30 seconds
    try self.addCronJob(schedule, "remote-log-level-sync", remoteLogLevelSync);

    See Schedule Tasks for the schedule format.

  3. Apply the value. The hook fetches the smallest JSON shape that fits ({ "level": "..." }), rejects unknown values, and applies the level to container.log.logLevel. A bad response is skipped and the next poll retries; the app keeps running with the last good value.

    zig
    fn remoteLogLevelSync(ctx: *Context) !void {
        const client = ctx.getService("zero-remote-log") orelse return;
        const resp = try client.get(ctx, remoteLogLevelResponse, "", null, null);
        if (resp) |r| {
            if (parseLogLevel(r.level)) |level| ctx.container.log.logLevel = level;
        }
    }
  4. Inspect locally. GET /remote.log.service?id=<uuid> returns the current in-process level. The app itself never serves config on an admin port.

Env keys (see Configuration):

bash
# REMOTE_LOG_URL=https://ops.internal/zero/log-level
# REMOTE_LOG_REFRESH_INTERVAL=30

Auth for the poll travels with the service:

bash
SERVICE_ZERO_REMOTE_LOG_AUTH_MODE=ApiKey
SERVICE_ZERO_REMOTE_LOG_API_KEY=...

Generic pattern: your own polled flag ​

Copy the four steps. Example — a remote feature flag polled every 30 seconds:

zig
const flagsService = "zero-flags"; // → SERVICE_ZERO_FLAGS_* env auth/circuit breaker
const FlagResponse = struct { publish_beta: bool = false };

var publish_beta = std.atomic.Value(bool).init(false);

fn syncFlags(ctx: *Context) !void {
    const client = ctx.getService(flagsService) orelse return;
    if (try client.get(ctx, FlagResponse, "", null, null)) |f| {
        _ = publish_beta.swap(f.publish_beta, .seq_cst);
    }
}

// in onStartup (or via app.addCronJob):
try app.addHttpService(flagsService, flags_url, .{});
try app.addCronJob("*/30 * * * * *", "sync-flags", syncFlags);

Rules that keep this safe — the same ones remoteLogLevelSync follows:

  • Parse narrow. Type the response (struct { publish_beta: bool }) so a shape change or garbage payload fails the parse, not your app state.
  • Fail soft. A failed poll is skipped; the last applied value stays hot. The circuit breaker from SERVICE_* env trips against a dead endpoint.
  • Gate with your own URL. No *_URL set → nothing registered → no polling, no outbound traffic. Every zero-pull-* feature is opt-in.
  • Apply atomically where readers race. One boolean is fine in an atomic; for bigger shape changes, swap a pointer to an immutable snapshot.
  • Keep the value cached, not lazily fetched in the hot path: readers should touch a plain field or atomic, never the client.

Why pull, not push ​

  • No inbound surface: the app holds no extra listener, so flags can't be pushed to a server behind a firewall that only allows egress.
  • Same auth and circuit-breaker class as every other outbound dependency in the app — no separate trust path to audit.
  • Cron cadence (*/N * * * * *) is per-feature: 30 seconds for a log level, 60 seconds for anything slower and cheaper.

Related: Logging covers the remote log-level keys from the reader's side; Resilience covers the breaker behavior.