Introducing a new way to review your PRs.

Read the announcement

techarohq / anubis

Weighs the soul of incoming HTTP requests to stop AI crawlers

View on GitHub

19 documents · Updated Nov 23, 2026

docs / storage-backends

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.

BackendState locationPersistenceDeployment role
memoryAnubis process memoryNoLocal development or a single instance where state loss is acceptable
bboltA local writable fileYesA single Anubis instance with local disk
valkeyA Valkey or Redis-compatible serviceYesSeveral Anubis instances or a separate state service
s3apiAn S3-compatible object bucketYesShared object storage where request volume and object latency fit the workload
Aggregate storeNot provided as a registered backendNot applicableNo 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:

  1. Choose a backend that matches the instance layout.
  2. Set its name in the policy store.backend field.
  3. Put only that backend's settings in store.parameters.
  4. Make the required local path, service, bucket, and credentials available to the process.
  5. 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 Get and Set contract, especially for object storage.
  • Recheck the persistent-store warning when changing IsPersistent or adding a new backend.
  • Recheck the deployment guidance when changing whether a backend can be shared by more than one instance.

Important failure modes

TriggerConsequenceGuard
Memory storage is used across several instancesA challenge or cached value written by one instance is missing from anotherUse Valkey or another shared persistent backend
bbolt uses a missing or unwritable pathBackend creation fails and the policy cannot use storageValidate the data path and its write access before startup
Valkey URL or Sentinel settings are invalidBackend creation fails before requests startUse the backend validator and its startup ping
S3 expiry metadata is missing or staleAn object can remain available after its intended lifetimePreserve the backend's expiry metadata contract
Persistent storage has no stable signing keyStored challenges become invalid after a restartConfigure one of the supported stable signing keys

Key files

FileWhy to read it
lib/…/interface.goDefines the common storage behavior and persistence signal
lib/…/store.goShows how policy names and validates a backend
lib/…/policy.goShows where the selected backend enters the running system
lib/…/memory.goDescribes the local, volatile deployment role
lib/…/bbolt.go and lib/…/factory.goDescribes the local persistent deployment role and path checks
lib/…/valkey.go and lib/…/factory.goDescribes shared service modes and connection checks
lib/…/s3api.go and lib/…/factory.goDescribes object storage and expiry handling
lib/…/registry.goShows backend registration and lookup