Skip to content

In-Memory Backend

InMemoryStorage is a zero-dependency backend backed by Python dicts and a bounded deque. It is the default fallback when MongoDB is unavailable and the backend used by the test suite.


_orgs: dict[str, dict] # org_id → organization doc
_users: dict[str, dict] # user_id → user doc
_memberships: dict[tuple[str, str], dict] # (org_id, user_id) → membership doc
_resources: dict[str, dict] # "org_id:hash" → {hash, value, analysis, org_id}
_entries: dict[tuple[str, str], set] # (org_id, namespace) → {hash1, hash2, …}
_namespace_created_at: dict[tuple[str, str], datetime] # (org_id, namespace) → first-seen, set once on first add_to_namespace
_api_keys: dict[str, dict] # key_id → key document (carries org_id)
_installed_analyzers: dict[tuple[str, str], dict] # (org_id, analyzer) → {enabled}
_custom_rules: dict[str, dict] # "org_id:rule_id" → rule doc, filtered by org_id (+ analyzer/category/enabled)
_rule_categories: dict[str, dict] # "org_id:category_id" → category doc (org-owned, category is a str reference to this — not a fixed enum)
_llm_credentials: dict[tuple[str, str], dict] # (org_id, provider) → doc
_jobs: dict[str, dict] # job_id → doc (carries org_id)
_usage_events: list[dict] # every billing event, filtered by org_id
_findings: dict[tuple[str, str, str], dict] # (org_id, resource_hash, rule_id) → record
_integrations: dict[tuple[str, str], dict] # (org_id, provider) → doc
_report_links: dict[str, dict] # link_id → doc, looked up by scanning for token_hash
_allowed_models: dict[str, dict] # "llm_backend:model" → doc — no org_id, platform-wide
_spans: deque(maxlen=10_000) # telemetry spans (capped)
  • Resources are stored by composite key "{org_id}:{hash}" in _resources — dedup is per-org, not global.
  • Namespace membership is tracked in _entries as a set, keyed by (org_id, namespace)add_to_namespace is idempotent by nature.
  • Spans are capped at 10 000 entries; oldest are discarded automatically.
  • _report_links has no TTL sweep (unlike MongoDB’s expireAfterSeconds=0 index) — expired docs just sit there until the process restarts. Harmless: get_report_link_by_token_hash still returns them, but the router’s own expires_at < now check rejects them regardless, same as the Mongo backend.

LimitationDetail
No persistenceAll data is lost when the process exits
No concurrencyNot safe for multi-process deployments
Memory boundLarge plans / long-running orgs will consume process memory
Span cappedOnly the most recent 10 000 spans are retained

ScenarioUse in-memory?
Unit testsYes — fast, no external dependency
Integration testsYes — opentremor-core-tests.yaml sets backend: memory
Local development (quick)Yes
ProductionNo — use MongoDB

storage:
backend: "memory"

No other fields are required. Auth also defaults to disabled (auth.api_key: null) in the bundled test/local configs, so every request resolves to the anonymous owner of a synthetic default org — see Authentication.