Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 7s
- Formalize tripartite project organization (guides/, plans/, discussions/) - Localize homelab architectural discussions and restructure dynu-monitor into a trade-off discussion and active Rust daemon plan - Author core operational runbooks: onboarding services, managing secrets/Authelia users, and server maintenance - Rewrite projects/homelab/README with 4-tier architecture, Gitea forge links, open discussions, and active WIP tracking - Standardize subproject nesting under nixos/ and update AGENTS.md conventions
3.8 KiB
3.8 KiB
type, project, date, tags
| type | project | date | tags | ||||||
|---|---|---|---|---|---|---|---|---|---|
| discussion | homelab | 2026-09-11 |
|
🔄 Discussion: Dynu DDNS Polling Frequency, Resolver Rotation, and Rust Migration
1. Problem Statement
The production Dynu dynamic DNS monitor on the server currently runs on a 30-minute systemd timer (OnUnitActiveSec = "30min") and queries a sequential fallback list of 4 external echo providers. When the residential ISP rotates the server's public WAN IPv4 address, external domains on roadtotech.me can remain unreachable for up to 30 minutes before the monitor detects the transition and triggers ddclient.service.
Core Tension:
- Speed of Recovery: To minimize service downtime, the monitor should detect WAN rotations within 30 to 60 seconds.
- Provider Abuse & Rate Limits: Polling a single public echo API (such as
api.ipify.orgoricanhazip.com) every 30 seconds yields 2,880 requests per day from a single IP, which risks temporary bans or API blocking. - Language & Runtime Overhead: The current implementation is written in Python (
pkgs.writers.writePython3Bin), invoking the full Python 3.14 interpreter and standard libraries on every execution of a headless server appliance.
2. Exploration: The 5-Provider Stateful Pool Prototype
On an experimental branch (refactor/dynu-monitor), an alternative Python prototype was designed:
- Increase systemd timer frequency to 30 seconds.
- Distribute queries across an expanded pool of 5 external providers (
api.ipify.org,icanhazip.com,ifconfig.me,checkip.dynu.com,wtfismyip.com). - Use a stateful round-robin pointer stored in
/var/lib/dynu/state.json.
Evaluation of the Prototype:
- Pros:
- Each individual provider is queried at most once every 2.5 minutes (~24 requests/hour), well within public usage guidelines.
- WAN rotations are detected in under 30 seconds.
- Cons & Complications:
- Requires writing local state back and forth from disk on every 30s tick.
- Python startup overhead running 2,880 times a day creates unnecessary CPU and I/O noise on a low-power home server.
- The prototype remained unmerged because maintaining complex state machines in an embedded Nix Python script is brittle.
3. The Resolution: Direct Migration to a Native Rust Daemon
Rather than merging the intermediate Python rewrite into Core, the preferred architectural path is to migrate dynu-monitor directly to a lightweight, compiled Rust daemon.
Why Rust?
- Zero Runtime Dependencies: The compiled binary requires no Python interpreter, virtualenv, or dynamic store dependencies, aligning with the headless appliance philosophy.
- Minimal Footprint: A native daemon can either run as a persistent background process with an internal async timer (
tokio), or as an ultra-fast oneshot binary with zero startup penalty. - Decoupled Architecture: Domain logic (
IpMonitorService) is separated from I/O mechanisms (IpResolver,StateRepository,DdnsUpdater) via traits, allowing comprehensive unit testing without real network or systemd calls. - Hands-on Rust Engineering: Serves as a practical project for idiomatic Rust patterns (traits, structs/enums, dependency injection, and Cargo packaging in Nix).
4. Architectural Invariants for the Rust Implementation
- Gatekeeper Pattern:
dynu-monitoronly triggersddclient.servicewhen a public IP change is verified. - Update Confirmation:
last_ipinstate.jsonis updated only afterddclientexits successfully. A failed update preserves the previous IP so retries continue. - Graceful Resolver Failover: If the current provider in the round-robin sequence fails or times out (5s), the daemon falls back to the next provider immediately without failing the tick.