SmartDNS System Architecture Design
OpenFlare SmartDNS pairs a control-plane multi-window network quality matrix, node capacity metrics, and a visual JSON Decision Model (JDM) rule engine with an EDNS0 Client Subnet (ECS)-aware authoritative DNS data plane to deliver low-latency, overload-protected traffic steering.
1. Topology and Anti-Corruption Boundary
- Decoupled storage boundary: Neither the Go SmartDNS control plane (
internal/apps/openflare/smartdns) nor the standalone Rust DNS server (components/dns/) queriesnetqualityorpkg/netinteltables directly. Both consume normalized link-quality predictions andCompactQualitySnapshotartifacts throughinternal/apps/openflare/qualityapi.Provider(mirrored on Rust bycomponents/dns/src/quality.rs::QualityOracle), enforced in tests byinternal/apps/openflare/smartdns/imports_test.go. - Snapshot compilation and offline resilience:
SnapshotManagercompiles online, non-quarantined nodes (with tags, capacities, and live loads), enabled routing policies (with JDM JSON),target_mode = smartdnsdomain mappings, andCompactQualitySnapshotinto an immutable, versionedDNSSnapshotEnvelopewith a strongETag.- Configuration or pointing updates emit
listener.EmitSmartDNSSnapshotDirtyto trigger a 250 ms debounced rebuild and pushdns:snapshot_changedwakes over/api/v1/dns-agent/wsalongside 10-second polling/heartbeat convergence. - Standalone
openflare-dnspersists the latest snapshot to--cache-dir/last-snapshot.binso authoritative serving continues cleanly if the control plane becomes temporarily unreachable.
2. Authoritative Data Plane (openflare-dns and Embedded Mode)
OpenFlare supports both a standalone Rust server (openflare-dns) and an embedded Go server, sharing identical decision semantics:
- Multi-core socket handling (
components/dns/src/server.rs): Built onhickory-server, binding per-workerSO_REUSEPORTUDP sockets and TCP listeners on Unix systems. Authoritative responses handleA,AAAA,NS, andSOA; non-authoritative zones returnREFUSED, and empty record types return RFC-compliantNODATAwith anSOAauthority record. - ECS extraction, sharded RRL, and L1 answer cache (
components/dns/src/cache.rs): Uses valid non-private ECS client subnets for Geo/ASN resolution and echoes/24(IPv4) or/48(IPv6) response scope prefixes. NormalizedClientPrefixKeykeys drive a 64-shard token-bucket Response Rate Limiter (RRL) and amokaL1 answer cache isolated by(version, qname, qtype, prefix, from_ecs). - Async JDM isolation (
components/dns/src/engine.rs): Compiles JDM decision graphs viazen-engine. BecauseDecision::evaluateholds!Sendfutures, evaluations run on a dedicated blocking-poolcurrent_threadruntime only on L1 cache misses. - Remote updates:
openflare-dnssupports heartbeatUpdateReceiptreporting and staged self-update requests (components/dns/src/update.rs) under managed hosts.
3. Shared JDM Evaluation and Four-Stage Node Selection
Control-plane Go (smartdns/scoring.go, embedded_go_dns.go) and Rust (components/dns/src/engine.rs) share the same JDM output contract and four-stage scoring flow:
- Candidate filtering: Applies policy
filters(node_ids,countries,tags,network_groups) across online, unquarantined nodes in eithersmartorload_balancemode. - Multi-factor scoring:
LoadIndex: Weighted composite of CPU (45%), memory (25%), and capacity utilization (30%); nodes exceeding0.92are flagged overloaded and excluded from the primary pool.- Latency quality score (
S_lat): Combineseffective_rtt_ms, dynamicp95_weighttail penalty, andloss_ratepenalty. Rust resolvesregion→country→ country any-ASN fallback → node/geo prior in O(1) hash lookups (see Network Intelligence and Link Quality Architecture). - Geographic proximity (
S_geo): Smooth Haversine distance decay (2000 kmscale). - Tag multipliers & weighted load balancing: Scales scores by active node tag multipliers (
[0.25, 4.0]). Inload_balancemode, deterministic weighted ordering (Efraimidis-Spirakis) hashes client prefix, domain, and node ID. - Bounded exploration budget: Allocates
0.5%–3%time-bucketed traffic (with TTL capped at25s) to verify stale or exploratory candidates without causing route flapping.
- 5% hysteresis anti-flapping: Retains the sticky node tracked for
(policy_id, client_prefix, qtype)over a 10-minute window unless a non-overloaded challenger beats it by more than1.05×(5%). - Guaranteed fallback chain: If strict filtering yields zero healthy candidates, falls back sequentially through configured fallback node IDs → overloaded online nodes → unfiltered online nodes → unquarantined nodes so valid answers still return whenever possible.
4. Telemetry and Multi-Database Storage
Standalone openflare-dns instances record latency percentiles (p50, p95, p99) with a 16-shard hdrhistogram and report QPS, query outcome counts, cache hit ratio, snapshot version, CPU, and RAM usage on heartbeats. The control plane writes snapshots via logstore.Observability.InsertDNSMetricSnapshot into ClickHouse or PostgreSQL/SQLite (of_dns_metric_snapshots).