Labs › storage

Build Your Own Property Graph Database

Build a property graph database from in-memory adjacency lists to Cypher-lite pattern matching to label indexes and Dijkstra shortest path — understanding why Neo4j's index-free adjacency is a fundamental architectural difference.

rust 1.83 advanced ~12h build · ~3h read ~870 LoC (v3)
v0: In-Memory Property Graphv1: Cypher-lite Query Languagev2: Label Index + Shortest Path + PageRank
☕ Java/Spring integration included service client

Why this lab exists

Every recommendation engine, fraud detection system, and social network runs on graphs. When LinkedIn answers “people you may know,” it is traversing a graph where nodes are people and edges are connections. When a bank detects fraud, it is looking for suspicious transaction paths in a graph of accounts and transfers. The query “find all accounts within 3 hops of this flagged account” is trivial in a graph database and painful in a relational one — it requires 3 self-joins, each exponentially larger than the last.

This lab makes you build the data structure that powers those systems. You will go from a bare-bones in-memory adjacency list, to a mini Cypher query engine that parses and executes graph pattern matching, to a label-indexed, Dijkstra-capable, PageRank-equipped graph database. By the end, you will understand exactly why Neo4j’s “index-free adjacency” is not marketing — it is a fundamental architectural choice that makes multi-hop traversal O(1) per hop regardless of graph size.

The reference for comparison throughout this lab is Neo4j — the dominant property graph database, written in Java, with a 15-year head start. Every design decision in our Rust toy is illuminated by asking: what does Neo4j do instead, and why?

What we are building

A property graph database where:

  • Nodes have a unique NodeId, one or more string labels, and a property map (HashMap<String, Value>)
  • Edges are directed, have a string label, a from NodeId, a to NodeId, and properties
  • Value is a tagged enum: String, Int, Float, Bool
  • Queries are expressed in a subset of the Cypher query language
  • v2 adds a label index, a property index, Dijkstra shortest path, and iterative PageRank

Explicit scope exclusions: no disk persistence, no ACID transactions, no MVCC, no concurrent access, no Cypher aggregations (COUNT, COLLECT), no schema enforcement, no relationship directions in index lookups.

Mental model

The property graph model

A property graph has two kinds of entities, both carrying arbitrary key-value properties:

Node: {id: 1, labels: ["Person"], properties: {name: "Alice", age: 30}}
Edge: {id: 1, from: 1, to: 2, label: "KNOWS", properties: {since: 2020}}

This is different from an RDF triple store (no literals as nodes, schema-free) and different from a relational database (no foreign-key joins — edges are first-class citizens).

The defining query is multi-hop traversal:

MATCH (alice:Person {name: "Alice"})-[:KNOWS*1..3]->(friend:Person)
RETURN friend.name

In SQL this is a recursive CTE or 3 self-joins. In our graph engine it is DFS with a depth limit. In Neo4j it follows physical relationship pointers — one pointer dereference per hop.

Adjacency list: the backbone

Our graph is stored as three hash maps:

nodes:     HashMap<NodeId, Node>
edges:     HashMap<EdgeId, Edge>
adjacency: HashMap<NodeId, Vec<EdgeId>>

To find Alice’s friends: look up adjacency[alice_id], get a list of edge IDs, fetch each edge to find the to NodeId. Two HashMap lookups per hop. This is fast in practice (HashMap is O(1) amortized), but it is not the same as Neo4j’s approach.

What index-free adjacency actually means

Neo4j stores each node as a 15-byte record on disk:

Node record (15 bytes):
  in_use:        1 byte
  next_rel_id:   4 bytes  -- pointer to first relationship record
  next_prop_id:  4 bytes  -- pointer to first property record
  label_id:      2 bytes
  extra:         4 bytes

Each relationship record (34 bytes) stores pointers to the next relationship for BOTH the source and target node:

Relationship record (34 bytes):
  in_use:              1 byte
  first_node:          4 bytes
  second_node:         4 bytes
  relationship_type:   2 bytes
  first_node_prev_rel: 4 bytes  -- doubly-linked list for first_node
  first_node_next_rel: 4 bytes
  second_node_prev_rel:4 bytes  -- doubly-linked list for second_node
  second_node_next_rel:4 bytes
  next_prop_id:        4 bytes
  extra:               3 bytes

To find Alice’s friends: read Alice’s node record (1 disk read, 15 bytes), follow next_rel_id to her first relationship record (1 disk read, 34 bytes), follow first_node_next_rel for the next relationship. No index lookup required — you are following physical pointers on disk.

Our HashMap approach: adjacency[alice_id] is a hash lookup that may cause a cache miss. For a hot in-memory graph with 10,000 nodes, this is fast. For a cold on-disk graph with 1 billion nodes, following physical record pointers beats hash lookups decisively.

The Cypher-lite query plan

Our mini Cypher parser produces a QueryPlan tree:

MATCH (n:Person {name: "Alice"})-[:KNOWS*1..3]->(m:Person) RETURN m

QueryPlan::PathMatch {
  from_label: Some("Person"),
  from_props: {"name": String("Alice")},
  rel_type: Some("KNOWS"),
  min_hops: 1, max_hops: 3,
  to_label: Some("Person"),
  where_pred: None,
  return_aliases: ["m"],
}

The executor converts this to: scan Person nodes, filter by name = "Alice", DFS from each match up to 3 hops along KNOWS edges, filter targets by Person label, project the “m” alias.

Prerequisites

No specific prior labs are required, but the WAL lab and B+Tree lab are useful context for understanding why disk-based graph storage is hard. Familiarity with BFS and DFS at the level of a coding interview is sufficient for v2.

Stage-by-stage build

Stage 0 In-Memory Property Graph ~220 LoC ›
  • Define NodeId = u64, EdgeId = u64, Value enum (String/Int/Float/Bool)
  • Define Node: {id, labels: Vec<String>, properties: HashMap<String, Value>}
  • Define Edge: {id, from, to, label, properties}
  • Implement Graph: {nodes, edges, adjacency: HashMap<NodeId, Vec<EdgeId>>}
  • Implement add_node(labels, properties) -> NodeId
  • Implement add_edge(from, to, label, properties) -> EdgeId
  • Implement neighbors(node_id) -> Vec<NodeId> (outgoing only)
  • Implement find_nodes(label) -> Vec<&Node> (linear scan)
  • Write 8 tests: add node, add edge, neighbors, find by label, multi-label, edge properties, bidirectional traversal, disconnected graph

The in-memory graph is three hash maps and two monotonic ID counters. The adjacency list maps each node to its outgoing edge IDs — not directly to neighbor NodeIds. This indirection lets edges carry properties (which you cannot store in a direct NodeId adjacency list).

pub struct Graph {
    pub nodes:     HashMap<NodeId, Node>,
    pub edges:     HashMap<EdgeId, Edge>,
    pub adjacency: HashMap<NodeId, Vec<EdgeId>>,
    next_node_id:  NodeId,
    next_edge_id:  EdgeId,
}

Why Vec<EdgeId> instead of Vec<NodeId>? If you store Vec<NodeId> directly, you lose the edge properties. When you ask “what is the weight of the KNOWS edge between Alice and Bob?”, you need to look up the edge record. Storing Vec<EdgeId> in the adjacency list gives you O(1) access to both the neighbor and the edge properties.

The neighbors() method traverses the adjacency list:

pub fn neighbors(&self, node_id: NodeId) -> Vec<NodeId> {
    self.adjacency
        .get(&node_id)
        .map(|edge_ids| {
            edge_ids.iter()
                .filter_map(|eid| self.edges.get(eid).map(|e| e.to))
                .collect()
        })
        .unwrap_or_default()
}

Two HashMap lookups per hop: adjacency[node_id] to get edge IDs, then edges[eid] to get the target NodeId. Compare to Neo4j’s one pointer dereference per hop.

Multi-label nodes: a node can have multiple labels. add_node accepts Vec<String> for labels. find_nodes("Person") returns nodes where labels.contains("Person") — a linear scan across all nodes. The label index (v2) makes this O(1).

Value as a hashable enum: Value needs to implement Hash and Eq so it can be used as a key in the property index (v2). Float hashes via f64::to_bits() — not IEEE-correct (NaN != NaN by default), but acceptable for a toy.

Stage 1 Cypher-lite Query Language ~570 LoC ›
  • Write a tokenizer: handle identifiers, string literals, -, -[, ]->, .., *, {, }
  • Write a recursive-descent parser for: MATCH (n:Label) RETURN n
  • Extend parser for: MATCH (n:Label {prop: value}) RETURN n
  • Extend parser for: MATCH (n:Label)-[r:TYPE]->(m:Label) RETURN n, m
  • Extend parser for: MATCH (n:Label)-[:TYPE*min..max]->(m) WHERE n.prop = value RETURN m
  • Define QueryPlan: ScanNodes, Filter, Traverse, PathMatch, Project
  • Implement executor::execute(plan, graph) -> Vec<ResultRow>
  • Implement dfs_traverse(graph, start, rel_type, min_hops, max_hops) -> Vec<NodeId>
  • Write 6 tests: all nodes of label, property filter, simple relationship, 3-hop path, WHERE clause, RETURN projection

The parser handles the 4 query patterns in a single pass. The key design decision is to represent the full path pattern as a single QueryPlan::PathMatch variant rather than composing ScanNodes + Filter + Traverse. This avoids the complexity of building a join operator.

The tokenizer handles the awkward graph syntax. The tricky tokens are -[ (start of relationship pattern) and ]-> (end of relationship pattern). A naive character-by-character tokenizer will produce -, [ and ], -, > separately. The tokenizer must look ahead to compose these:

'-' => {
    chars.next();
    if chars.peek() == Some(&'[') {
        chars.next();
        tokens.push("-[".to_string());
    } else {
        tokens.push("-".to_string());
    }
}
']' => {
    chars.next();
    if chars.peek() == Some(&'-') {
        chars.next();
        if chars.peek() == Some(&'>') {
            chars.next();
            tokens.push("]->".to_string());
        }
    }
}

The .. range separator in *1..3 is also ambiguous: it could be two . tokens (from property access like n.name). The tokenizer peeks ahead to distinguish . (property access) from .. (range).

The QueryPlan tree is the intermediate representation between parsing and execution:

pub enum QueryPlan {
    ScanNodes(String),                          // scan all nodes with label
    Filter(Box<QueryPlan>, Predicate),          // filter sub-plan by predicate
    Traverse { source, rel_type, min_hops, max_hops },
    PathMatch { from_label, from_props, rel_type, min_hops, max_hops,
                to_label, where_pred, return_aliases, from_alias, to_alias },
    Project(Box<QueryPlan>, Vec<String>),       // keep only listed aliases
}

DFS with a depth limit for variable-length paths:

pub fn dfs_traverse(graph, start, rel_type, min_hops, max_hops) -> Vec<NodeId> {
    let mut results = Vec::new();
    let mut stack: Vec<(NodeId, usize)> = vec![(start, 0)];

    while let Some((current, depth)) = stack.pop() {
        if depth > max_hops { continue; }
        if depth >= min_hops && current != start {
            results.push(current);
        }
        if depth < max_hops {
            for edge in graph.outgoing_edges(current) {
                if rel_type.map_or(true, |t| edge.label == t) {
                    stack.push((edge.to, depth + 1));
                }
            }
        }
    }
    results
}

Note that the stack can revisit nodes at different depths. For a cyclic graph this causes infinite recursion — the production solution is a visited set per path (not per node, since the same node can appear on multiple paths). Our simple implementation uses a (NodeId, depth) visited pair to break cycles.

ResultRow is HashMap<String, Node>: maps alias names (“n”, “m”) to cloned node values. Cloning is expensive for large result sets — production query engines use row references, not copies. For a toy this is acceptable.

Stage 2 Label Index + Shortest Path + PageRank ~870 LoC ›
  • Implement LabelIndex: HashMap<String, HashSet<NodeId>>, maintained on add_node
  • Implement PropertyIndex: HashMap<(String, String), HashMap<Value, HashSet<NodeId>>>
  • Add create_index(label, prop) to build a property index over existing nodes
  • Implement bfs_shortest_path(from, to) -> Option<Vec<NodeId>>
  • Implement shortest_path(from, to, weight_property) -> Option<Vec<NodeId>>
  • Implement page_rank(iterations, damping) -> HashMap<NodeId, f64>
  • Write 5 tests: label index speedup, property index lookup, BFS 3 hops, Dijkstra weighted path, PageRank sums to 1.0

The label index is a HashMap<String, HashSet<NodeId>> maintained alongside the graph. Every add_node call updates the index in O(labels.len()) time:

pub fn insert(&mut self, node: &Node) {
    for label in &node.labels {
        self.inner.entry(label.clone()).or_default().insert(node.id);
    }
}

Lookup is O(1): index.get("Person") returns a HashSet<NodeId>. Before the index, find_nodes("Person") scanned all n nodes. After the index, it is a single HashMap lookup.

The property index handles (label, property_name) -> value -> NodeIds. This is how MATCH (n:Person {name: "Alice"}) becomes O(1) instead of O(n):

pub fn lookup(&self, label: &str, prop: &str, value: &Value) -> HashSet<NodeId> {
    let key = (label.to_string(), prop.to_string());
    self.inner.get(&key).and_then(|m| m.get(value)).cloned().unwrap_or_default()
}

The property index is opt-in (you must call create_index(label, prop) explicitly). This mirrors Neo4j’s CREATE INDEX ON :Person(name) command. Without the explicit declaration, the executor falls back to a linear scan with filter.

Dijkstra with a binary heap uses std::collections::BinaryHeap. Rust’s BinaryHeap is a max-heap, so we reverse the ordering (min cost = max priority):

impl Ord for DijkstraState {
    fn cmp(&self, other: &Self) -> Ordering {
        other.cost.partial_cmp(&self.cost).unwrap_or(Ordering::Equal)
            .then_with(|| self.node.cmp(&other.node))
    }
}

Edge weights come from a named property: shortest_path(from, to, Some("cost")) reads edge.properties["cost"] as an f64. Missing weight property defaults to 1.0, making unweighted BFS and weighted Dijkstra share the same code path.

PageRank power iteration runs for a fixed number of iterations. The standard formula:

rank(v) = (1 - d) / N + d * sum(rank(u) / out_degree(u)) for all u -> v

Where d is the damping factor (0.85) and N is the total number of nodes. Dangling nodes (out-degree 0) distribute their rank equally to all nodes — otherwise rank leaks out of the graph and scores no longer sum to 1.0.

The sum-to-1 property (within floating-point tolerance) is a correctness invariant: if PageRank values do not sum to approximately 1.0 after convergence, there is a bug in the dangling-node handling.

Run it yourself

Prereqs: Rust 1.75+cargo
  1. 1
    Clone and build
    git clone https://github.com/pushkarkumar-dev/system-design-labs
    cd system-design-labs/labs/property-graph-db
    cargo build
  2. 2
    Run all tests (v0 + v1 + v2)
    cargo test
  3. 3
    Run the demo (social network graph + all query types)
    cargo run --bin graph-demo
  4. 4
    Run benchmarks
    cargo bench
Expected output
=== Property Graph Database Demo ===

Graph: 6 nodes, 6 edges

--- v0: adjacency list ---
Alice's neighbors: [2, 3]
Linear scan for :Person nodes: 5

--- v1: Cypher-lite queries ---
MATCH (n:Person) RETURN n => 5 rows
MATCH (n:Person {name: "Alice"}) RETURN n => 1 row
MATCH (n:Person)-[r:KNOWS]->(m:Person) RETURN n, m => 5 rows
MATCH (n:Person)-[:KNOWS*1..3]->(m) WHERE n.name = Alice => 3 rows
found: Some(String("Bob"))
found: Some(String("Carol"))
found: Some(String("Dave"))

--- v2: index lookups ---
LabelIndex lookup :Person => 5 nodes (O(1))
PropertyIndex :Person(name='Carol') => {3}
BFS Alice -> Eve: Some(4)
PageRank total = 1.0000 (should be ~1.0)
Top-ranked nodes (by PageRank):
Carol => 0.1842
Bob => 0.1756
Dave => 0.1621

Benchmarks

Benchmark results on M2 MacBook Pro, 16GB RAM
Metric Result Notes
add_node throughput ~4,200,000 nodes/sec estimated — HashMap insert + ID increment
find_nodes by label (linear scan, 100k nodes) ~850,000 queries/sec estimated — full scan before label index
find_nodes by label (label index) ~28,000,000 queries/sec estimated — HashMap lookup O(1)
BFS shortest path (100 hops, 10k nodes) ~12,000 queries/sec estimated — BFS traversal
PageRank (100 iterations, 10k nodes) ~8 iterations/sec estimated — O(V+E) per iteration

Run cargo bench on your machine for real numbers. The label index speedup (33x) is the most striking result: the same logical operation changes from O(n) to O(1) with one HashMap added per label. The PageRank number is low because O(V+E) per iteration dominates at 10k nodes — Neo4j uses native graph storage to amortize the cost across disk reads.

Stress tests

To verify correctness under load, the test suite includes:

Label index consistency: insert 1,000 Person nodes, verify the label index contains exactly 1,000 entries. Then verify the linear scan and the index agree on every NodeId.

Cycle detection in DFS: build a cyclic graph (A->B->C->A), run a variable-length path query, verify termination and no duplicate results in the output.

Dijkstra optimality: build a graph with two paths of different total weights, verify Dijkstra returns the lower-cost path (not just the fewer-hop path).

PageRank sum invariant: run PageRank on graphs of sizes 10, 100, 1000 with random topologies, verify the sum of all scores is always within 0.001 of 1.0.

Property filter with index: run the same query (MATCH (n:Person {name: "Alice"}) RETURN n) against graphs with and without a property index, verify both paths return identical results.

What the toy misses

What the toy misses Honest gaps vs. production
  • Disk-based adjacency storage Neo4j stores nodes in fixed-size 15-byte records and relationships in 34-byte records, with direct pointer chaining (no indirection). Graph traversal is O(1) per hop by following record offsets. Our HashMap indirection adds a cache miss per lookup.
  • Index-free adjacency Neo4j's defining feature: each node record contains a pointer to its first relationship, and each relationship points to the next relationship for both source and target. No index needed — traversal follows physical pointers. Hash maps defeat this.
  • Full Cypher language The Cypher query language has CREATE, MERGE, DELETE, aggregations (COUNT, COLLECT, AVG), OPTIONAL MATCH, UNION, and CALL procedures. Our tiny subset covers maybe 10% of real queries.
  • ACID transactions Neo4j uses MVCC for concurrent transactions. Graph mutations during a traversal can see inconsistent state without isolation. Our single-threaded in-memory graph has no isolation.
  • Graph partitioning for scale Distributing a graph database across machines is exceptionally hard — a social network's friendship graph has a diameter of ~6, meaning any query can cross any partition. Most graph DBs prefer replication over sharding.
  • Native graph storage format SQLite and PostgreSQL can store graphs, but traversal requires a self-join per hop. Neo4j's native storage traverses relationships in O(1) per hop regardless of graph size — a fundamental advantage for multi-hop queries.

Wiring it into a Java/Spring service

☕

Wiring it into a Java/Spring service

service client spring-data-neo4j
Maven dependencies
org.neo4j.driver:neo4j-java-driver:5.21.0
org.springframework.boot:spring-boot-starter-data-neo4j:3.3.0
org.springframework.boot:spring-boot-starter-actuator:3.3.0

Part A — GraphClient: raw Cypher via the Neo4j Java Driver

GraphClient.java runs the same four query patterns our Rust Cypher-lite engine supports, but against a real Neo4j instance using the official Java driver. The comparison is intentional: same query, two engines.

@Component
public class GraphClient {
    private final Driver driver;

    // MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = $name RETURN m
    // Rust equiv: executor.execute(PathMatch{rel_type: KNOWS}, graph)
    public List<Map<String, Object>> findFriends(String name) {
        try (Session session = driver.session()) {
            Result result = session.run(
                "MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = $name RETURN m.name AS name",
                Values.parameters("name", name)
            );
            return result.list(Record::asMap);
        }
    }

    // MATCH (n:Person)-[:KNOWS*1..3]->(m:Person) WHERE n.name = $name RETURN m
    // Rust equiv: dfs_traverse(graph, alice_id, "KNOWS", 1, 3)
    public List<Map<String, Object>> findFriendsUpTo3Hops(String name) {
        try (Session session = driver.session()) {
            Result result = session.run(
                "MATCH (n:Person)-[:KNOWS*1..3]->(m:Person) WHERE n.name = $name RETURN DISTINCT m.name AS name",
                Values.parameters("name", name)
            );
            return result.list(Record::asMap);
        }
    }
}

The architectural difference in one sentence: when Neo4j executes MATCH (n)-[:KNOWS]->(m), it follows a physical pointer chain stored in each relationship record. When our Rust executor runs the same query, it does adjacency[node_id] (HashMap lookup) + edges[edge_id] (another HashMap lookup) per hop. On a cold in-memory graph the difference is negligible. On a 50 billion-edge graph stored on NVMe, Neo4j’s pointer chain beats hash map lookups by an order of magnitude.

Part B — Spring Data Neo4j: the ORM path

Spring Data Neo4j (SDN) provides a higher-level API using @Node and @Relationship annotations — the Spring Data pattern familiar from Spring Data JPA:

// Spring Data Neo4j entity — comparable to a JPA @Entity
@Node("Person")
public class PersonNode {
    @Id @GeneratedValue
    private Long id;

    private String name;
    private int age;

    @Relationship(type = "KNOWS", direction = OUTGOING)
    private List<PersonNode> friends;
}

// Repository — same pattern as JpaRepository
public interface PersonRepository extends Neo4jRepository<PersonNode, Long> {
    List<PersonNode> findByName(String name);

    @Query("MATCH (n:Person)-[:KNOWS*1..3]->(m:Person) WHERE n.name = $name RETURN m")
    List<PersonNode> findFriendsWithin3Hops(String name);
}

SDN translates findByName("Alice") into MATCH (n:Person) WHERE n.name = "Alice" RETURN n — the same query our Cypher-lite parser handles. The custom @Query for variable-length paths shows the limit of derived query names: some graph patterns cannot be expressed without explicit Cypher.

Part C — application.yml

spring:
  neo4j:
    uri: bolt://localhost:7687
    authentication:
      username: neo4j
      password: secret

management:
  endpoint:
    health:
      show-details: always

Run it

# Start Neo4j (Docker)
docker run --rm -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/secret neo4j:5

# Seed the graph in Neo4j Browser (localhost:7474):
# CREATE (a:Person {name: "Alice", age: 30})
# CREATE (b:Person {name: "Bob", age: 25})
# CREATE (c:Person {name: "Carol", age: 28})
# CREATE (a)-[:KNOWS]->(b)
# CREATE (b)-[:KNOWS]->(c)

# Run the Spring Boot demo
cd labs/property-graph-db/java-integration
mvn spring-boot:run

Expected output (with Neo4j running):

=== Property Graph Database — Java/Neo4j Demo ===

1. MATCH (n:Person) RETURN n
   [Rust equiv: graph.find_nodes("Person") with label index]
   {name=Alice, age=30}
   {name=Bob, age=25}
   {name=Carol, age=28}

2. MATCH (n:Person {name: "Alice"}) RETURN n
   [Rust equiv: PropertyIndex.lookup("Person", "name", "Alice")]
   {name=Alice, age=30}

3. MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = "Alice" RETURN m
   [Rust equiv: executor.execute(PathMatch{rel_type: KNOWS}, graph)]
   Neo4j uses index-free adjacency: O(1) per hop via relationship record chain.
   {name=Bob}

4. MATCH (n:Person)-[:KNOWS*1..3]->(m:Person) WHERE n.name = "Alice" RETURN m
   [Rust equiv: dfs_traverse(graph, alice_id, "KNOWS", 1, 3)]
   Found 2 friends within 3 hops:
   Bob
   Carol

Key difference: Neo4j's variable-length path uses relationship pointer
chains (index-free adjacency). Our DFS uses a HashMap<NodeId, Vec<EdgeId>>
which adds one HashMap lookup per hop instead of one pointer dereference.

What surprised me

Where to go deeper

  • Previous in storage: B+Tree KV Store — the data structure inside Neo4j’s label indexes. Neo4j uses a B-Tree per label; our LabelIndex is a flat HashMap with no range query support.
  • Related in storage: LSM-Tree KV Store — RocksDB is sometimes used as the storage layer for graph databases. Understanding LSM-Tree write amplification explains why graph databases often prefer custom B-Tree storage instead.
  • Design question: if you needed to support MATCH (n:Person)-[:KNOWS*1..6]->(m:Person) (6-hop “six degrees of separation” query) on a graph with 1 billion nodes, what data structure would you use? How does Neo4j’s disk layout change the I/O cost compared to a HashMap-based graph?
  • Design question: the PageRank algorithm requires knowing the out-degree of every node before each iteration. How does this interact with the adjacency list storage? What happens to PageRank if 10% of nodes are dangling (no outgoing edges)?