Storage backend implementations
Storage backends give Anubis one place to keep short-lived state such as challenge data, DNS results, and extension data. The selected backend controls whether that state stays in one process, survives a restart, or can be shared by several Anubis instances. See State and storage for the wider state model and Storage contracts for the shared behavior.
Backend selection
Anubis selects one storage backend from the policy store setting. The configuration layer checks the backend name, then its factory builds the store before the policy becomes active.
The selection flow connects policy input to the store used by request handling:
flowchart LR
P[Policy store setting] --> V[Validate backend and parameters]
V --> F[Build selected backend]
F --> S[Shared storage contract]
S --> C[Challenges and stateful subsystems]
Each backend follows the same basic contract: read a value, write it with an expiry, delete it, and report whether it is persistent. This lets higher-level systems choose a deployment role without knowing the storage protocol.
References: lib/…/store.go• L17-43 lib/…/registry.go• L15-42 lib/…/interface.go• L28-45 lib/…/policy.go• L134-148
Deployment roles
The backends differ mainly in where state lives and whether other Anubis instances can see it. The choice should match the process layout and the cost of losing state during a restart.
| Backend | State location | Persistence | Deployment role |
|---|---|---|---|
memory | Anubis process memory | No | Local development or a single instance where state loss is acceptable |
bbolt | A local writable file | Yes | A single Anubis instance with local disk |
valkey | A Valkey or Redis-compatible service | Yes | Several Anubis instances or a separate state service |
s3api | An S3-compatible object bucket | Yes | Shared object storage where request volume and object latency fit the workload |
| Aggregate store | Not provided as a registered backend | Not applicable | No built-in multi-backend or fallback role |
Persistence also affects challenge continuity. When a persistent store is selected, Anubis warns if no stable signing key is configured because stored challenges can outlive the process that created them.
Memory backend
The memory backend keeps expiring values inside one Anubis process. It is the simplest choice for local work and for deployments that use one instance and can accept a clean state after restart.
It does not share values with other instances. It also limits the number of retained entries, so it is not a general replacement for shared state in a scaled deployment.
References: lib/…/memory.go• L14-26 lib/…/memory.go• L56-75 lib/…/memory.go• L91-100
bbolt backend
The bbolt backend stores state in a local file and restores it when Anubis starts again. It suits a single instance with a stable, writable data path.
The file is local to the host. Multiple Anubis instances must not use it as a shared store. Expired values are removed during normal reads and periodic cleanup.
References: lib/…/factory.go• L24-54 lib/…/factory.go• L72-96 lib/…/bbolt.go• L19-35 lib/…/bbolt.go• L179-197
Valkey backend
The Valkey backend puts state in a network service that supports key expiry. It is the main choice when several Anubis instances must use the same state or when storage should run outside the application host.
The configuration supports a direct service, a cluster, or Sentinel-managed failover. The factory checks the connection before it returns the backend, so an unreachable service prevents a valid store from being built.
References: lib/…/factory.go• L30-71 lib/…/factory.go• L121-177 lib/…/valkey.go• L18-47
S3-compatible backend
The s3api backend stores each value as an object in a configured bucket. It supports AWS S3 and compatible object stores, including services that need path-style addressing.
Object storage has no native per-value expiry in this contract. The backend records the expiry with the object and checks it when the value is read. This makes it persistent and shareable, but its request and consistency behavior should match the state workload before it is used as the default store.
References: lib/…/factory.go• L21-23 lib/…/factory.go• L39-74 lib/…/s3api.go• L21-78
Aggregate storage
The current store registry does not provide an aggregate backend. An Anubis process selects one registered backend rather than combining memory, disk, Valkey, and S3-compatible storage into a built-in primary and fallback system.
The shared JSON wrapper can add typed values and key prefixes without changing the selected backend. This is a wrapper around one store, not a second persistence tier. See Storage contracts for the contract that such wrappers must preserve.
References: lib/…/registry.go• L10-42 lib/…/interface.go• L49-99 lib/…/all.go• L1-11
Configuration integration
The policy stores a backend name and backend-specific parameters. Validation uses the registered factory, so an unknown name or invalid parameters fail before the policy can use the store.
When configuring a backend, follow this sequence:
- Choose a backend that matches the instance layout.
- Set its name in the policy
store.backendfield. - Put only that backend's settings in
store.parameters. - Make the required local path, service, bucket, and credentials available to the process.
- Configure a stable signing key when the backend is persistent.
The factory owns connection and path checks. The policy loader then passes the resulting store to the DNS cache and other stateful systems, so a storage configuration error can prevent the full policy from becoming active.
References: lib/…/store.go• L17-43 lib/…/policy.go• L134-148 cmd/…/main.go• L337-345
Change checklist
When these files or sections are changed, remember to consider these:
- Keep each registered backend name aligned with its policy configuration name.
- Keep backend expiry behavior aligned with the shared
GetandSetcontract, especially for object storage. - Recheck the persistent-store warning when changing
IsPersistentor adding a new backend. - Recheck the deployment guidance when changing whether a backend can be shared by more than one instance.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Memory storage is used across several instances | A challenge or cached value written by one instance is missing from another | Use Valkey or another shared persistent backend |
| bbolt uses a missing or unwritable path | Backend creation fails and the policy cannot use storage | Validate the data path and its write access before startup |
| Valkey URL or Sentinel settings are invalid | Backend creation fails before requests start | Use the backend validator and its startup ping |
| S3 expiry metadata is missing or stale | An object can remain available after its intended lifetime | Preserve the backend's expiry metadata contract |
| Persistent storage has no stable signing key | Stored challenges become invalid after a restart | Configure one of the supported stable signing keys |
Key files
| File | Why to read it |
|---|---|
| lib/…/interface.go | Defines the common storage behavior and persistence signal |
| lib/…/store.go | Shows how policy names and validates a backend |
| lib/…/policy.go | Shows where the selected backend enters the running system |
| lib/…/memory.go | Describes the local, volatile deployment role |
| lib/…/bbolt.go and lib/…/factory.go | Describes the local persistent deployment role and path checks |
| lib/…/valkey.go and lib/…/factory.go | Describes shared service modes and connection checks |
| lib/…/s3api.go and lib/…/factory.go | Describes object storage and expiry handling |
| lib/…/registry.go | Shows backend registration and lookup |