Skip to content

Add discover: a breadth-first walk of the Facebook graph - #5

Merged
tamnd merged 2 commits into
mainfrom
discover-graph-bfs
Jun 15, 2026
Merged

tamnd merged 2 commits into
mainfrom
discover-graph-bfs

Conversation

@tamnd

@tamnd tamnd commented Jun 15, 2026

Copy link
Copy Markdown
Owner

feed answers one question about one actor. discover chains the commands: from a seed (page, profile, group, or post) it follows the object's edges, and from each neighbor it follows theirs, breadth first, streaming one record per node.

The graph

The anonymous surface is a shallow star, so the graph is small and deliberate. Five node kinds (page, profile, group, post, comment) and three edges:

Edge From to What it follows
posts actor to post an actor's recent feed
author post to actor the actor that posted a story
comments post to comment a post's preview comments (a leaf)

--follow takes a preset (content = posts+author, the default; threads = posts+comments; all) or a comma-separated edge list.

Why the edges are shaped this way

Two things fall out of reading the pages Facebook serves to crawlers:

  • Preview comments expose a commenter's name but no id to hop to, so a comment is a leaf, and threads needs --depth 2 from an actor seed (actor to post to comment).
  • A feed post is tagged with the actor it came from, so author from a feed post dedups back to the container. author is a real hop only from a post seed, where the URL encodes the owner; one hop further, posts reaches the rest of that author's feed.

Bounds and errors

--depth (default 1), --fanout (default 25), and -n (default 500) keep every walk finite. A seed that will not fetch fails the walk; a failure deeper in the walk becomes a one-line note on stderr (silenced by -q) and the walk carries on.

Testing

The walker sits behind a narrow grapher interface that *Client satisfies, so the whole BFS is tested over an in-memory fake with no network: edge parsing and the unknown-token error, the follows matrix, posts-from-actor, the author hop from a post seed, threads depth, the dedup cycle, the budget and fanout caps, depth-0 seeds-only, seed-fatal and unsupported-kind seeds, deeper feed/comment errors degrading to notes, multiple seeds, and comments as leaves.

Also

  • discover command (aliases walk, graph) streaming a typed Node (payload + depth/via/parent), reusing each object's own row renderer.
  • New discovering guide, a discover entry in the CLI reference, and cross-links from search and datasets.
  • Two discover smoke cases.

Build, vet, and tests are green; gofmt clean; go mod tidy is a no-op.

tamnd added 2 commits June 15, 2026 18:52
feed answers one question about one actor. discover chains the
commands: from a seed page, profile, group, or post it follows the
object's edges, and from each neighbor it follows theirs, hop by hop,
streaming one record per node.

The anonymous surface is a shallow star, so the graph is small and
deliberate. There are five node kinds (page, profile, group, post,
comment) and three edges: posts (actor to post), author (post to
actor), and comments (post to leaf comment). --follow takes a preset
(content, threads, all) or a comma-separated edge list.

Two things fall out of reading the pages Facebook serves to crawlers.
Preview comments expose a name but no id, so a comment is a leaf and
threads needs depth 2 from an actor seed. A feed post is tagged with
the actor it came from, so author from a feed post dedups back to the
container; author is a real hop only from a post seed, where the URL
encodes the owner.

The walker sits behind a narrow grapher interface that *Client
satisfies, so the whole BFS is tested over an in-memory fake with no
network: edge parsing, the follows matrix, the author hop, threads
depth, the dedup cycle, the budget and fanout caps, seed-fatal vs
deeper-note errors, and comments as leaves.

A seed that will not fetch fails the walk; a failure deeper in the
walk becomes a one-line note on stderr and the walk carries on. depth,
fanout, and -n keep every walk finite.

Adds the discovering guide, a discover entry in the CLI reference, and
two smoke cases.
@tamnd
tamnd merged commit e5d344b into main Jun 15, 2026
7 checks passed
@tamnd
tamnd deleted the discover-graph-bfs branch June 15, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant