Loom Data and Storage

Part of Loom. Choice status: proposed, subject to a small implementation benchmark.

Database alternatives

OptionFitTradeoff
Neo4jPages and typed links map directly to a graph; suitable for neighborhood and path queriesRequires Cypher knowledge, operational planning, and bounded traversals
MongoDBFlexible crawl/job documents and separate page/edge collectionsRecursive traversal is available, but graph exploration and indexing need careful design
PostgreSQLStrong fit for job ledgers and relational edge tablesA viable alternative, though it is outside the user’s preferred graph/NoSQL direction

Proposed starting choice: Neo4j as the durable source of truth, with Redis for queue and limiter state. Avoid maintaining both MongoDB and Neo4j in the first release.

Neo4j provides an official Go driver. MongoDB documents recursive traversal through $graphLookup. The choice above is an architectural recommendation, not a comparative performance claim.

Snapshot graph

flowchart LR
    User[Account] -->|OWNS| Job[Crawl job]
    Job -->|CONTAINS| Page[Page observation]
    Page -->|LINKS_TO| Other[Target observation or stub]
    Page -->|REDIRECTS_TO| Redirect[Redirect destination]
    Page -->|DECLARES_CANONICAL| Canonical[Canonical target]
    Job -->|HAS_WORK| Frontier[Frontier entry]
    Job -->|HAS_EVENT| Event[Outbox / status event]
EntityImportant fields
AccountStable owner ID from authentication provider
Crawl jobOwner, seed, settings snapshot, state, termination reason, counters, revision, timestamps
Page observationJob ID, URL identity, requested/final URL, title, HTTP status, fetch outcome, content type, depth, timing, bytes
LinkJob ID, source/target IDs, type, bounded anchor samples, occurrence count
Frontier entryJob and URL key, state, next eligibility, lease token/expiry, attempts, result reference
Outbox eventUnique event ID, job ID, work ID, dispatch state and timestamps
FindingJob ID, type, page/edge references, evidence and severity

A page observation belongs to a crawl snapshot. Do not overwrite yesterday’s status with today’s result. Canonical URL identity can be shared as metadata later; observations remain versioned by job.

Consistency

Use deterministic unique keys such as job_id + normalized_url for pages/frontier and job_id + source + target + type for aggregated edges. Create appropriate uniqueness constraints and indexes before processing jobs; confirm support in the selected Neo4j version/edition.

Use a short transaction to settle a page and create its edges, frontier additions, and outbox records. Guard mutations with job state and attempt tokens. Where Neo4j lacks a desired compound constraint in the chosen edition, use a deterministic single key. Benchmark job counters and lease claims for contention before adopting multiple replicas.

Store status history or revisions durably enough for reliable browser reconnects. Return authorized graph data through the Go API; browsers never receive database credentials or arbitrary Cypher execution.

Graph queries and retention

All queries are scoped to an owned job and carry explicit node, edge, depth, and time limits. Provide summary/path-group queries, capped neighborhoods, search, paginated pages, and bounded export jobs. Never load every node into the browser by default or run unbounded variable-length traversals.

Persist page metadata and link observations by default, not full HTML. Put large exports or later snapshots in private object storage with lifecycle rules. URL queries can contain sensitive values; redact logs and keep maps private by default. Deleting a job removes its frontier, observations, edges, exports, and queue references through a recoverable cleanup process.