State and storage backends
Anubis uses a small storage abstraction to keep protection state and short-lived cache data. The same contract lets one service use local memory or disk and lets several service instances share a remote store. Backend choice affects whether state survives a restart and whether it can be shared across instances.
Storage model
The storage model treats state as byte values addressed by string keys. Every value can have an expiry, so protection data can disappear when it is no longer useful; callers also receive a common not-found result instead of a backend-specific result. The store.Interface contract is the boundary between Anubis features and the selected backend. lib/…/interface.go• L11-44
The model has two useful layers:
- Raw store: Reads, writes, and deletes byte values.
- Typed view:
store.JSON[T]adds JSON conversion and an optional key prefix for a feature that wants typed records without a new backend. lib/…/interface.go• L49-99
The IsPersistent result tells the wider service whether data remains after a restart. The service uses this signal to warn when persistent state is configured without a signing key that can keep challenges valid across restarts. cmd/…/main.go• L337-345
Backend selection
The policy selects a backend by name and passes backend-specific parameters to its factory. Validation happens before the policy creates the running service, which makes an unknown backend or invalid backend settings a configuration error rather than a runtime choice. lib/…/store.go• L17-43, lib/…/policy.go• L134-145
Factories register names with the store registry. This keeps the policy format stable while allowing local, remote, and future backends to share the same selection path. lib/…/registry.go• L15-42
flowchart LR
Policy[Policy store choice] --> Validate[Validate backend settings]
Validate --> Factory[Build selected backend]
Factory --> Contract[Storage contract]
Contract --> State[Protection state and caches]
Backend categories
The supported backends cover single-process use, local persistence, and shared remote persistence. The choice should match the service topology and the value of state after a restart.
| Category | Backend | Main use | Restart and sharing behavior |
|---|---|---|---|
| Volatile local | memory | Simple single-instance operation and temporary state | Lost on restart and not shared across Anubis instances. lib/…/memory.go• L73-100 |
| Persistent local | bbolt | A service that needs state on its local filesystem | Survives restarts but is not for several Anubis instances sharing one store. lib/…/bbolt.go• L19-35 |
| Shared remote | valkey | Several Anubis instances using one shared key-value service | Persistent and suitable for shared service use. lib/…/valkey.go• L11-16 |
| Shared object storage | s3api | Durable state in an S3-compatible bucket | Persistent and remote; expiry is managed as part of the stored object because object storage has no native TTL. lib/…/s3api.go• L33-78 |
Memory backend
The memory backend is a volatile store for one running Anubis instance. It supports expiry and limits its retained entries, but it does not provide a shared view to other instances or a durable copy after shutdown. lib/…/memory.go• L26-34, lib/…/memory.go• L56-75
References: lib/…/memory.go• L26-34 lib/…/memory.go• L56-75
Local database backend
The bbolt backend provides a persistent local store. It is a good fit when one Anubis instance owns the data file; it is not a shared coordination store for multiple instances. lib/…/factory.go• L28-54, lib/…/bbolt.go• L179-181
References: lib/…/factory.go• L28-54 lib/…/bbolt.go• L179-181
Valkey backend
The Valkey backend provides a shared remote key-value store with native expiry. Its connection mode can target a single service, a cluster, or a Sentinel-managed service, so it fits deployments where several Anubis instances must observe the same protection state. lib/…/factory.go• L30-71, lib/…/factory.go• L130-177
References: lib/…/factory.go• L30-71 lib/…/factory.go• L130-177
S3-compatible backend
The S3-compatible backend stores each value as an object in a configured bucket. It records the expiry with the object and treats an expired object as absent when it is read, which gives object storage the same short-lived state behavior as the other backends. lib/…/factory.go• L90-106, lib/…/s3api.go• L33-55
References: lib/…/factory.go• L90-106 lib/…/s3api.go• L33-55
Backend decoration
The storage layer can wrap a backend without changing the backend choice. ActorifiedStore serializes operations through actors while preserving the same storage contract, and JSON[T] adds typed records and key namespaces. These wrappers let a feature add access or data-shape rules without coupling itself to memory, disk, or a remote service. lib/…/actorifiedstore.go• L12-42, lib/…/interface.go• L49-99
Child pages
Read Storage contracts for the shared operations, error meanings, expiry rules, and typed wrapper. Read Storage backends for backend-specific configuration and operational limits.
Change checklist
When these files or sections are changed, remember to consider these:
- A new backend name must be registered and loaded by the package set used during policy validation.
- A change to expiry or not-found behavior must remain consistent across every backend and the typed JSON wrapper.
- A change to persistence semantics must keep the restart warning aligned with
IsPersistent. - A change to shared-instance support must update deployment guidance for the selected backend.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Memory storage is used by several Anubis instances | Each instance sees different protection state | Use a shared remote backend for multi-instance service use |
| A persistent backend is used without a signing key | Challenges are invalidated after a restart | Configure a supported private signing key |
| A backend configuration names an unknown backend or invalid parameters | Policy validation fails before the service starts | Validate the policy and backend settings together |
| S3 object expiry metadata is missing or stale | Expired protection state can remain readable or be treated inconsistently | Preserve the backend expiry contract when writing and reading objects |
Key files
| File | Why to read it |
|---|---|
| lib/…/interface.go | Defines the common state contract and typed JSON view |
| lib/…/registry.go | Shows how backend names map to factories |
| lib/…/store.go | Shows how policy configuration selects and validates a backend |
| lib/…/memory.go | Shows the volatile local backend |
| lib/…/bbolt.go | Shows the persistent local backend boundary |
| lib/…/valkey.go | Shows the shared remote key-value backend |
| lib/…/s3api.go | Shows the shared object-storage backend and expiry behavior |
| cmd/…/main.go | Shows how persistence affects restart and signing-key warnings |