Skip to content

Filter Chains

Filter chains let you compose multiple routing steps per DNS query. Instead of locking a service to a single algorithm, you declare an ordered list of filters that are applied in sequence — narrowing the candidate set at each step until a terminal filter selects one endpoint.

License: Filter chains require the paid tier or above. Services with a non-empty filterChain array return HTTP 403 on free and unlicensed installations. Contact licensing@gslb.nexus to upgrade.

Filter Categories

Filters fall into two categories.

Narrowing filters

A narrowing filter reorders or reduces the candidate set. If applying the filter would produce zero candidates, it is skipped (pass-through) and the previous candidate set is kept unchanged. The chain then continues with the next filter.

Filter Behaviour
geo-ip Keeps only candidates whose region field matches the client's resolved region. Falls back to SortByPreference ordering if no members have a matching region or the client's region is unknown. See [Regions(Regions.md) for how the client's region is resolved.
asn Reorders candidates by ASN proximity using SortByPreference. All candidates are kept; matching-ASN endpoints move to the front.
map-file Reorders candidates by CIDR map preference using SortByPreference. All candidates are kept; matched endpoints move to the front.
sticky Pins the client to a single member (LDNS persistence). Narrows to one candidate chosen by rendezvous hashing of the client subnet. Paid tier, like every filter chain — no additional gate. See LDNS Persistence.
signal-weight Biases (never removes) candidates by a per-region carbon/cost value. Requires pro tier. See Signal-Weight Routing and CarbonAwareRouting.md.

Selecting filters (terminal)

A selecting filter picks exactly one candidate and terminates the chain. No further filters run after it.

Filter Behaviour
round-robin Stateful round-robin across the current candidate set. Counter is per-service.
weighted-round-robin Weighted random selection from the current candidate set using member weight values.
failover Returns the highest-priority healthy candidate (lowest priority integer value). Within a priority tier, higher health score wins.
latency Returns a candidate by weighted random selection, weighted by inverse RTT measured from this cluster node.
rum (alias rum-latency) Returns the candidate with the lowest real-user latency measured from the client's subnet by the browser beacon. Falls back to latency behaviour when no measurement covers the client. Requires pro tier. See RUMRouting.md.
prox Orders candidates nearest-first by great-circle distance from the client's resolved coordinates, with subdivision/country/continent fallback tiers (decreasing granularity). Falls through to the next step when the client is unlocatable or has no coordinates and no subdivision/country/continent match — like latency/rum, a conditionally terminal filter. Requires pro tier. See Geo Proximity Routing and GeoProximityRouting.md.

Execution Model

Given a chain ["geo-ip", "asn", "weighted-round-robin"]:

  1. Start with all healthy candidates for the pool, sorted by health score.
  2. geo-ip: narrow to candidates in the client's region. If none match, keep all.
  3. asn: reorder survivors by ASN proximity. Keep all survivors.
  4. weighted-round-robin: weighted-random-select one candidate from survivors. Return it.

If the chain exhausts without reaching a terminal filter (e.g. a chain of only narrowing filters), the first candidate in the current set is returned.

Multi-Answer Responses (maxAddrsReturned)

By default a query returns exactly one A/AAAA record — the winner the chain selected. Set maxAddrsReturned (1-32, default 1) on a service to return more: the chain's full ordered candidate set (winner first) is written into the response, truncated to this count.

Each terminal filter orders the remainder using the criterion that already made sense for it:

Filter Winner Remainder order
round-robin current rotation index subsequent members in rotation order (wrapping)
weighted-round-robin weighted-random pick descending weight
failover highest priority, then score same priority/score order
latency / rum weighted-random / lowest real-user latency ascending RTT

The round-robin counter still advances by exactly one per query regardless of maxAddrsReturned — only the first returned member is part of the strict-alternation guarantee; the rest are extra members riding along in rotation order.

POST /api/v1/services
{
  "name": "web-prod",
  "domain": "www.example.com.",
  "poolId": "pool-uuid",
  "filterChain": ["round-robin"],
  "maxAddrsReturned": 2,
  "ttl": 30
}

The [Query Tracer(QueryTracer.md)'s SimulateResult exposes the full ordered set as selectedIps; selectedIp (selectedIps[0]) is kept for backward compatibility.

Member region Field

The geo-ip filter matches against each member's region field. This must be set explicitly — it is not derived from the member's IP address.

If the tenant has any [Regions or Topology Rules(Regions.md) configured, region should hold a region name (e.g. "au-east") resolved via the full precedence chain (topology → city → subdivision → country → continent). Backward compatibility: a tenant with zero Regions and zero Topology Rules configured keeps the original behavior — region is matched directly against the client's raw ISO 3166-1 alpha-2 country code (e.g. "US", "DE", "JP"). Comparison is case-sensitive either way. Members with region unset default to "unknown" and will not match any client.

POST /api/v1/pools/{id}/members
{
  "ipAddress": "10.0.1.5",
  "port": 80,
  "region": "US"
}

Configuration

REST API

Set filterChain on create or update. When filterChain is present, algorithm is ignored.

POST /api/v1/services
{
  "name": "web-prod",
  "domain": "www.example.com.",
  "poolId": "pool-uuid",
  "filterChain": ["geo-ip", "weighted-round-robin"],
  "ttl": 30
}
PUT /api/v1/services/{id}
{
  "name": "web-prod",
  "domain": "www.example.com.",
  "poolId": "pool-uuid",
  "filterChain": ["geo-ip", "asn", "failover"],
  "ttl": 30
}

To revert to a single algorithm, send algorithm with an empty or absent filterChain:

PUT /api/v1/services/{id}
{
  "name": "web-prod",
  "domain": "www.example.com.",
  "poolId": "pool-uuid",
  "algorithm": "round-robin"
}

The filterChain field is returned in all service responses when set:

{
  "id": "svc-uuid",
  "name": "web-prod",
  "domain": "www.example.com.",
  "poolId": "pool-uuid",
  "algorithm": "",
  "filterChain": ["geo-ip", "weighted-round-robin"],
  "ttl": 30
}

Web UI

When creating or editing a service, click Use filter chain (top-right of the routing section) to switch from the single-algorithm dropdown to the filter chain builder:

  • Add filters from the palette below the chain.
  • Reorder with the ↑ / ↓ buttons.
  • Remove individual steps with ✕.
  • A preview line shows the composed chain: Geo IP → Weighted Round Robin.

Click Use single algorithm to revert to a single algorithm value.

TUI (gslbctl)

When creating or editing a service, the form includes a Filter Chain (optional) field below the Algorithm selector. Enter filter names as a comma-separated list:

Filter Chain (optional): geo-ip,asn,weighted-round-robin

Leave the field blank to use the value from the Algorithm selector instead. The service list view displays the chain in the ALGORITHM column as geo-ip→asn→weighted-round-robin.

Terraform

Use the filter_chain attribute on nexus_service. When set, algorithm is ignored by the API.

resource "nexus_service" "web" {
  name         = "web-prod"
  domain       = "www.example.com."
  pool_id      = nexus_pool.web.id
  filter_chain = ["geo-ip", "weighted-round-robin"]
  ttl          = 30
}

To use a single algorithm, omit filter_chain and set algorithm:

resource "nexus_service" "web" {
  name      = "web-prod"
  domain    = "www.example.com."
  pool_id   = nexus_pool.web.id
  algorithm = "round-robin"
  ttl       = 30
}

Both algorithm and filter_chain are Optional+Computed. If neither is specified, the service defaults to round-robin.

LDNS Persistence (Sticky)

Paid tier — the same gate every filter chain carries. Unlike rum, signal-weight and prox, sticky is not additionally restricted to pro: it is basic session-affinity behaviour that any paid deployment with a stateful backend needs, not an advanced steering signal.

The sticky step gives a client consistent answers over time — the same member on every query — the way F5 BIG-IP DNS (GTM) per-LDNS persistence does. Use it for stateful backends: sessions pinned to a site, licensing servers, legacy apps that don't share state across members.

How it works. sticky narrows the candidate set to a single member chosen by rendezvous (highest-random-weight) hashing of the client's resolver subnet (/24 for IPv4, /64 for IPv6; ECS subnet when present). Place it before the terminal selector:

["geo-ip", "sticky", "weighted-round-robin"]

Here geo-ip narrows to the client's region, sticky pins to one member within that region, and the selector trivially returns it.

Why rendezvous hashing, not a session table. The pin is a pure function of (client subnet, healthy candidate set):

  • Deterministic and node-local-free — every node computes the same answer, so a client hitting a different anycast node still gets the same member. No shared affinity table, no cross-node sync.
  • Survives restarts — there is no state to lose.
  • Minimal disruption — when a member is added or removed, only the clients pinned to that member move; everyone else keeps their pin. (A modulo or round-robin scheme would reshuffle everyone.)

Health always wins over stickiness. Candidates are health-filtered before the chain runs, so a member that fails its health check simply drops out of the set and its clients re-pin to the next-highest-weight healthy member immediately. There is no "sticky to a dead target" window.

No affinity window in v1. Stickiness lasts exactly as long as the pinned member stays healthy — which is the behaviour stateful backends want — so there is no windowSeconds to tune. The tradeoff: the pin follows the current healthy set, so scaling a pool up/down re-pins the clients whose hash winner changed (see minimal-disruption above), rather than holding an expiring lease.

Migrating from F5 BIG-IP DNS. A GTM pool with "Global Availability" or "Ratio" load balancing plus per-LDNS persistence maps to a filter chain of your selecting step (e.g. weighted-round-robin for Ratio) with sticky in front of it. F5's persistence TTL has no direct equivalent — Nexus persists for the lifetime of the member's health rather than a fixed timer.

Query tracer. The [Query Tracer(QueryTracer.md) shows the sticky step as a narrowed action pinning to one member (or skipped when ≤1 candidate remains).

Geo Proximity Routing (prox)

Pro tier.

prox routes each query to the nearest healthy member by great-circle distance, using member-configured coordinates — never GeoIP-derived, since members may sit behind RFC1918/private IPs GeoIP can't resolve.

Member setup. Every enabled member in a pool used by a prox chain must carry latitude/longitude (both or neither) — rejected at service create/update time otherwise, naming the offending pool and member. city is informational only; country/subdivision/continent are separate fallback tiers for a client with resolved geo data but no coordinates — distinct from the region field geo-ip uses. country is a raw ISO 3166-1 alpha-2 code; subdivision is a full ISO 3166-2 code (e.g. "US-CA", "GB-ENG" — country prefix required); continent is one of AF AN AS EU NA OC SA.

The less specific tiers are derived automatically when they'd otherwise be empty. Setting only subdivision fills in country from its ISO 3166-2 prefix (e.g. "GB-WSX" implies "GB" — unambiguous, so this always wins over a stale country value left over from a previous save); country (explicit or just-derived) fills in continent via the GeoIP location catalog (GET /api/v1/geoip/locations), but only when continent is still empty — an explicitly-chosen continent is never overridden, since some countries genuinely span more than one (e.g. Russia, Turkey) and an operator may deliberately want a specific one. This runs on every create/update, for every client (WebUI, gslbctl, Terraform, or the raw API) — a member configured with only a subdivision still participates correctly in prox's coarser country/continent fallback tiers instead of silently having empty ones.

POST /api/v1/pools/{id}/members
{
  "ipAddress": "10.0.1.5",
  "port": 80,
  "latitude": -33.8688,
  "longitude": 151.2093,
  "city": "Sydney",
  "country": "AU",
  "subdivision": "AU-NSW",
  "continent": "OC"
}

The WebUI's member forms (Add Member, topology edit panel, pool detail inline edit) offer all of this through a click-to-pin map (latitude/longitude) plus chained, searchable continent/country/subdivision/city pickers backed by GET /api/v1/geoip/locations — the choices offered are enumerated from whichever GeoIP database is actually loaded on the server (see [Regions(Regions.md)), so a picker can never suggest a country or city the database doesn't actually know about. Subdivision/city are disabled with an explanatory message when no database is configured, or when it's a Country-only edition (no subdivision/city data at that granularity).

Serving algorithm, per query:

  1. Client has coordinates (resolved via the configured GeoIP database — see [Regions(Regions.md)): order candidates by ascending distance-bucket (⌊distance/10km⌋), then descending weight, then ascending exact distance. Members within 10km of each other are tiebroken by weight; otherwise distance alone decides. This order is authoritative — prox terminates the chain here (like latency/rum succeeding).
  2. Client has geo data but no coordinates: filter by member subdivision (tried against every subdivision level the GeoIP database resolved for the client, most-significant first), else country, else continent — decreasing granularity; matches are ordered by weight descending (deterministic — this rare path isn't load-balanced). Also terminates the chain.
  3. Client unlocatable, or no coordinates and no subdivision/country/ continent match: pass through unchanged — falls through to the rest of the chain. The documented pattern for this fallback is ["prox", "weighted-round-robin"], giving unlocatable clients the pool's normal weighted rotation instead of a fixed arbitrary member.

Multi-answer. Because prox produces a fully-ordered candidate list rather than narrowing to one, it composes directly with maxAddrsReturned (see Multi-Answer Responses) — the first N members of the distance-ordered list are returned, nearest first.

Failover is inherent. Distance ordering is computed over the currently healthy candidate set — if the nearest member is down, the next-nearest healthy member wins automatically. No separate failover logic is needed.

Query tracer. Shows a selected action; each candidate in the trace carries a distanceKm field when the client had coordinates (see [Query Tracer(QueryTracer.md)).

See GeoProximityRouting.md for the full walkthrough.

Signal-Weight Routing (Carbon/Cost)

Pro tier.

signal-weight biases candidate ordering by a per-region scalar signal — carbon intensity, cost, or any value where lower is preferred — without ever excluding a healthy member. It's a reorder among already-health-filtered candidates, same as asn/map-file.

Members map to a signal zone via their existing region field (the same field geo-ip uses). Configure the zone table server-side, not per-service:

signals:
  static:
    us-east: 450   # e.g. gCO2/kWh
    eu-west: 120
  weight: 0.5   # 0 disables the bias; 1 lets it dominate. Default 0.5.

v1 ships static, operator-supplied values only — no live feed integration (ElectricityMaps, WattTime) yet. systemctl reload gslbd (SIGHUP) picks up config changes without a restart.

Blend, not override. Candidates are re-scored as score*(1-weight) + bias*weight, where bias is a min-max normalization of the signal value among the candidates present in this query (lowest value → highest bias). A candidate whose region has no configured value keeps its original score untouched — it's never penalized for missing data, though it can still be fairly outranked by a candidate whose blended score legitimately comes out higher.

Query tracer. Shows a reordered action with the zone values used and the configured weight, or skipped when no candidate's region has a configured value.

Observability. gslbd_signal_zone_value{zone} gauge reports the live configured table; gslbd_signal_queries_steered_total{service} counts queries where the step actually changed the top-ranked candidate. Both are visible in the WebUI under Signal Weight (Infrastructure); gslbctl signals list for the CLI.

See CarbonAwareRouting.md for the full walkthrough and the ESG/marketing framing.

Scriptable Steps (Starlark)

Enterprise tier. Requires the scripts:write permission to author.

A chain step may be an inline Starlark script for custom routing logic that the built-in filters don't cover — route by a customer ID embedded in the qname, business-hours weighting, and similar long-tail rules.

A script step is a chain entry of the form script:<body> (the body is a Starlark program). It runs on the DNS hot path against the current candidate set and narrows/reorders it.

Inputs

The script is given these globals:

Global Type Fields
candidates list of dict ip, region, weight, priority, health_score, rtt_ms
client dict ip, subnet, asn, geo
qname string the queried name
qtype string A, AAAA, …
now int current unix time

The script must set the global result to a list of candidate IP strings — the surviving candidates, in the order it wants them. IPs not in the original candidate set are ignored.

Sandbox & safety

  • No I/O: no file, network, or module (load) access.
  • Bounded: a step budget plus a ~2 ms wall-clock deadline (scripts run per query).
  • Fail-open: any compile error, timeout, or a result that filters everything out leaves the candidate set unchanged, increments gslbd_dns_script_step_error_total{service}, and logs (rate-limited). A broken script never blackholes a service.
  • Validated on write: the body is compile-checked when the service is saved, so a syntax error is rejected by the API — not discovered at query time.
  • The [Query Tracer(QueryTracer.md) shows each script step's before/after candidates and run duration.

Examples (cookbook)

Business-hours weighting — only keep the primary region during 09:00–17:00 UTC, otherwise keep all:

hour = (now // 3600) % 24
if 9 <= hour < 17:
    result = [c["ip"] for c in candidates if c["region"] == "primary"] or [c["ip"] for c in candidates]
else:
    result = [c["ip"] for c in candidates]

Route by customer ID in the qname — cust-<n>.svc.example.com → pin even/odd customers to different regions:

label = qname.split(".")[0]        # e.g. "cust-42"
region = "eu" if int(label.split("-")[1]) % 2 == 0 else "us"
result = [c["ip"] for c in candidates if c["region"] == region] or [c["ip"] for c in candidates]

Drop unhealthy, then prefer lowest RTT (narrowing before a later selecting step):

healthy = [c for c in candidates if c["health_score"] >= 0.8]
healthy = sorted(healthy, key=lambda c: c["rtt_ms"])
result = [c["ip"] for c in healthy]

Put a selecting step (e.g. weighted-round-robin) after a narrowing script, or let the script return a single IP to act as the terminal selector.

Common Patterns

Geo-first with weighted fallback — prefer regional endpoints, select by weight among survivors:

["geo-ip", "weighted-round-robin"]

ISP-aware routing — prefer same-region, then same-ASN, then highest-priority failover:

["geo-ip", "asn", "failover"]

Map-file with latency tiebreak — steer by CIDR rule, then pick the fastest survivor:

["map-file", "latency"]

Pure failover — no geographic step; always prefer highest-priority healthy endpoint:

["failover"]

Geo proximity with weighted fallback — nearest healthy member by distance; unlocatable clients get the pool's normal weighted rotation:

["prox", "weighted-round-robin"]

Backward Compatibility

Existing services that use the algorithm field continue to work without change. Filter chains are opt-in: if filterChain is absent or empty, the single algorithm value is used. The two modes are mutually exclusive at query time — filterChain takes precedence when set.

Interaction with Other Features

  • Composite health policy (minHealthy): runs before filter chain dispatch. If the pool is below threshold, no filter chain step executes — the query returns no answer.
  • Health scoring: candidates are pre-sorted by health score before the first filter runs. Unhealthy members (score = 0) are excluded from the initial candidate set.
  • EDNS0 Client Subnet: the geo-ip filter uses the client IP extracted from the ECS option when present, falling back to the resolver's source IP.
  • Multi-tenancy: filterChain is stored per-service and scoped to the owning tenant. It is included in NATS state-sync snapshots and replicated to peer nodes.
  • DNS cache: the domain→service cache stores the full service record including filterChain. Cache is invalidated on every service update.

Limitations

  • A chain of only narrowing filters (no terminal selector) returns candidates[0] — typically the highest-health-score endpoint. Add a terminal filter to control selection explicitly.
  • The geo-ip filter's pass-through applies per-query: if a client's region has no matching members, all members are eligible for the next step. This is intentional — it prevents blackholing traffic when regional capacity is unavailable.
  • Filter names must exactly match the values in the table above. Unknown filter names are rejected by the API with a validation error.
  • The round-robin filter's counter is per-service and is reset when the service is restarted or the member set changes.