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.
Internal structure
Section titled “Internal structure”_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
_entriesas aset, keyed by(org_id, namespace)—add_to_namespaceis idempotent by nature. - Spans are capped at 10 000 entries; oldest are discarded automatically.
_report_linkshas no TTL sweep (unlike MongoDB’sexpireAfterSeconds=0index) — expired docs just sit there until the process restarts. Harmless:get_report_link_by_token_hashstill returns them, but the router’s ownexpires_at < nowcheck rejects them regardless, same as the Mongo backend.
Limitations
Section titled “Limitations”| Limitation | Detail |
|---|---|
| No persistence | All data is lost when the process exits |
| No concurrency | Not safe for multi-process deployments |
| Memory bound | Large plans / long-running orgs will consume process memory |
| Span capped | Only the most recent 10 000 spans are retained |
When to use
Section titled “When to use”| Scenario | Use in-memory? |
|---|---|
| Unit tests | Yes — fast, no external dependency |
| Integration tests | Yes — opentremor-core-tests.yaml sets backend: memory |
| Local development (quick) | Yes |
| Production | No — use MongoDB |
Configuration
Section titled “Configuration”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.