Skip to content

Core Concepts & Architecture Primer

Getting started with the Impulse Graph Engine does not require a background in sparse linear algebra or compiler design. Understanding four structural choices—CSR/CSC adjacency arrays, per-domain dense IDs, set-reduced traversals, and Structure-of-Arrays (SoA) columns—explains how every runtime executes queries directly over .imps files.

Whether you are using the Pure JVM runtime (Java, Kotlin, Scala, Clojure) or the Native C-ABI runtime (C++, Rust, Python, Go, .NET, Node.js), the exact same data layout and execution model apply.


1. Why Graph Analytics Needs a Different Approach

In traditional application development, graphs are usually modeled in one of two ways:

  1. Object Pointers: In-memory objects where a Node has a list of references to other nodes (List<Node> neighbors).
  2. Relational Database Tables: A nodes table and an edges join table containing (source_id, target_id).

Both approaches hit severe bottlenecks when analytics scale to millions or billions of edges:

  • Object pointer-chasing causes constant CPU cache misses. In languages with managed memory (like Java), millions of edge objects cause heavy garbage collection (GC) thrashing and high heap overhead.
  • Relational JOIN queries require expensive disk I/O, hash-join tables, and index lookups for every traversal hop.

Impulse Graph solves this by treating the graph as a Sparse Matrix stored in a contiguous, zero-copy, memory-mapped binary format (.imps).


2. Sparse Matrices for Graph Topology

Imagine a graph where rows represent Source Nodes and columns represent Target Nodes. An edge between Node \(A\) and Node \(B\) is represented by a 1 at coordinate \((A, B)\). This is an Adjacency Matrix.

          Target User
          0   1   2   3
Src   0 ┌ 0   1   1   0 ┐  --> User 0 follows User 1 and User 2
User  1 │ 0   0   1   0 │  --> User 1 follows User 2
      2 │ 0   0   0   0 │  --> User 2 follows nobody
      3 └ 1   1   1   0 ┘  --> User 3 follows User 0, 1, and 2

The Problem with Dense 2D Matrices

If you have 1,000,000 users and each user has 50 friends:

  • A standard 2D matrix would require \(1,000,000 \times 1,000,000 = 1,000,000,000,000\) (1 Trillion) cells!
  • That would consume ~1 Terabyte of RAM, where 99.995% of the cells are empty zeros.

Graphs in the real world are almost always sparse—most possible connections do not exist. Therefore, we store only the actual connections using Compressed Sparse Row (CSR) and Compressed Sparse Column (CSC).


3. Compressed Sparse Row (CSR): The Forward Topology

CSR (Compressed Sparse Row) is the industry standard format for representing sparse matrices and graph adjacencies. It compresses the 2D grid into two flat, contiguous integer arrays:

  1. row_offsets: Points to where each source node's target list begins and ends.
  2. column_targets: Contains the actual target node IDs packed contiguously.

Concrete Example

Let's look at the 4-node graph from above:

  • Node 0 links to: 1, 2 (2 edges)
  • Node 1 links to: 2 (1 edge)
  • Node 2 links to: (none) (0 edges)
  • Node 3 links to: 0, 1, 2 (3 edges)

Total edges: \(2 + 1 + 0 + 3 = 6\).

In CSR format, this entire graph is stored in two compact arrays:

row_offsets:    [ 0,    2,    3,    3,    6 ]
                  │     │     │     │     │
Node Index:       0     1     2     3 (end)

column_targets: [ 1, 2, │ 2, │ (none), │ 0, 1, 2 ]
                  ──────  ───          ───────────
                  Node 0 Node 1 Node 3

How an Edge Lookup Works in \(O(1)\)

To find the outgoing edges for Node 0:

  1. Read offset range: start = row_offsets[0] (\(0\)), end = row_offsets[1] (\(2\)).
  2. Slice column_targets[0..2]: [1, 2].

To find the outgoing edges for Node 2:

  1. Read offset range: start = row_offsets[2] (\(3\)), end = row_offsets[3] (\(3\)).
  2. Because start == end, Node 2 has 0 outgoing edges.

CSR Memory Locality and Hardware Prefetch Mechanics

  • Instant Degree Calculation: The degree (edge count) of Node \(u\) is simply row_offsets[u + 1] - row_offsets[u]—an instant scalar subtraction requiring zero edge traversals.
  • CPU Cache Perfection: All neighbors of a node sit side-by-side in contiguous memory. The CPU prefetcher loads them into L1 cache in a single memory cycle.
  • Vector SIMD Friendly: CPU vector registers (AVX-512, ARM Neon) can process 8 to 16 neighbor IDs simultaneously.
  • Primary Use: Forward traversals (.out("FOLLOWS"), BFS, PageRank push).

4. Compressed Sparse Column (CSC): The Reverse Topology

While CSR makes asking "Who does User 0 follow?" instant, asking the reverse—"Who follows User 2?"—would require scanning every row in the CSR matrix.

To make incoming traversals just as fast, Impulse Graph supports CSC (Compressed Sparse Column).

  • CSC is the exact transpose of CSR.
  • In CSC, the offsets array points to Target Nodes, and the targets array stores the Source Nodes that point to them.
  • In our example above, looking up the incoming edges for Node 2 in CSC yields: [0, 1, 3] in \(O(1)\) time.
  • Primary Use: Incoming traversals (.in("FOLLOWS"), reverse reachability, PageRank pull).

Tip

When building general-purpose relations with SnapshotBuilder, CSR is the standard forward topology required for .out(...) walks, and you can optionally include CSC with a single method call (.addTopology(Topology.CSC, CompressionScheme.RAW)). If your edge stream is sorted by source ID, the Impulse builder automatically stages and inverts the stream into CSC using external sort. (At the .imps binary specification level, all topology sections—CSR, CSC, and COO—are independently optional to support specialized M:1 / 1:1 direct-lookup arrays, CSC-only relations, or virtual relations, probed at runtime via OP_HAS_CSR / OP_HAS_CSC.)


5. Universal Node Architecture: Domains & Dense IDs

One of the most important architectural rules in Impulse Graph is Per-Domain Dense ID Independence:

There is NO Global Flattened ID Space

In many graph databases, every node in the entire database is assigned a synthetic global 64-bit ID (e.g., node 1000 is a User, node 1001 is a Product, node 1002 is a Store).

Impulse Graph does not use global IDs. Instead, each Node Domain possesses its own independent, zero-indexed dense integer space (\(0 \dots N_d - 1\)):

┌─────────────────────────┐         ┌─────────────────────────┐
│ User Domain       │         │ Account Domain      │
│ Cardinality: 10,000    │         │ Cardinality: 50,000   │
├─────────────────────────┤         ├─────────────────────────┤
│ Dense IDs: 0 .. 9,999   │         │ Dense IDs: 0 .. 49,999  │
│ User 0 ≠ Account 0      │         │ Account 0 ≠ User 0      │
└─────────────────────────┘         └─────────────────────────┘

Why Independent Dense IDs?

  1. Direct Array Indexing: If the User domain has 10,000 nodes, its row_offsets array has exactly 10,001 entries. Looking up User ID 42 is a direct array access (offsets[42]), requiring zero hash tables or ID translation.
  2. Compact Integer Widths:
  3. Small domains (e.g., categories, states, roles) with \(< 65,536\) entities can use 16-bit integers (PrimitiveWidth.UINT16), cutting memory usage in half.
  4. Standard domains use 32-bit integers (PrimitiveWidth.UINT32), supporting up to 4.29 billion nodes.
  5. Hyperscale domains use 64-bit integers (PrimitiveWidth.UINT64).
  6. Domain-Bound Traversals: Every traversal begins by binding an explicit domain context:
    snap.domain("User").from(42).out("OWNS").toList();
    

6. How Traversals Execute: Domain Pipelines & Collapsing Intermediate Results

Understanding how Impulse Graph evaluates a multi-hop query requires knowing two core execution rules that set it apart from SQL JOINs and traditional Cypher/Gremlin engines:

Rule 1: Start in One Domain, Walk 0..N Edges, Finish in One Target Domain

Every traversal in Impulse Graph is a pipeline that steps from one Node Domain to the next:

  1. Anchor to a Single Starting Domain: You start in one domain (e.g., User) with an initial frontier of nodes (one node, a list of nodes, a bitset, or the entire domain).
  2. Step Across 0 or More Directed Relations:
  3. If you walk 0 edges (e.g., snap.domain("User").all().filter("node.age >= 21").toList()), you stay in User and return matching User nodes.
  4. Each edge walk transitions the active frontier from the relation's Source Domain to its Target Domain: $\(\text{User} \xrightarrow{\text{PLACED}} \text{Order} \xrightarrow{\text{CONTAINS}} \text{Product}\)$
  5. Any .filter(...) or .project(...) step along the way operates on the attributes of whichever domain (or edge relation) is currently active at that step.
  6. Materialize from the Single Final Target Domain: The query finishes in a single target domain (above, Product) and returns results from that domain's surviving frontier:
  7. Target Node IDs or Business Keys (toList(), toKeyList(), toBitSet())
  8. Target Domain Attributes (e.g., product.price, product.category)
  9. Projected State carried forward along the walk, or a scalar aggregate (count(), sum(), max()).

Rule 2: Set Semantics (Not Multi-Sets) & Monoidic Reduction (Collapsing Paths)

Most query engines (relational SQL JOINs, Neo4j Cypher, Gremlin) use multi-set (bag-of-paths) semantics. If User 0 and User 1 both follow User 2, and User 2 follows 1,000 people, a multi-set engine produces two duplicate rows for User 2 at hop 1, and walks all 1,000 of User 2's outgoing edges twice at hop 2. Over 4 or 5 hops, duplicate paths multiply into millions of redundant intermediate rows.

Impulse Graph uses Set semantics at every step, collapsing converging paths into a single entry per node immediately:

Multi-Set Engine (SQL JOIN / Standard Cypher) — Duplicate Paths Multiply:
  User 0 ──┐                 ┌──► User 2 (Row 1) ──► walks User 2's 1,000 edges
           ├──► User 2  ───► │
  User 1 ──┘                 └──► User 2 (Row 2) ──► walks User 2's 1,000 edges AGAIN!

Impulse Graph (Set Semantics / Monoidic Reduction) — Collapsed at Every Step:
  User 0 ──┐
           ├──► BitSet[User 2] = 1  ───► walks User 2's 1,000 edges ONCE!
  User 1 ──┘
  • When Walking Without State (Bitset Union): The intermediate frontier is an off-heap BitSet with one bit per node in the current domain. Whether 1 edge or 10,000 edges land on User 2, bit 2 is simply set to 1 (OR). Duplicates are eliminated automatically in \(O(1)\) time with zero hash-table overhead.
  • When Carrying Calculated State Across Hops (Monoidic Reduction): What if each path carries a calculated value (such as transaction amount, path distance, or score) and multiple incoming edges converge on the same target node? Impulse collapses (reduces) the converging values into a single value for that target node using an associative reduction operator (a monoid):
Reduction Rule (Monoid) How Converging Values \((v_1, v_2, \dots)\) Are Collapsed Typical Graph Use Case
Bitwise OR (Default) \(\text{true} \lor \text{true} = \text{true}\) (Set Union) Multi-hop reachability, ReBAC authorization, filtering
SUM (+) \(v_1 + v_2 + \dots\) Total cash flow, path counting, PageRank / Markov walks
MIN \(\min(v_1, v_2, \dots)\) Shortest paths, earliest transaction timestamp
MAX \(\max(v_1, v_2, \dots)\) Maximum bottleneck capacity, highest risk/confidence score

Because every step collapses its output into at most \(N_d\) unique entries (one bit—and optionally one state value—per node in the target domain), intermediate memory never explodes, even on dense or cyclic graphs.


7. Business Keys vs. Dense IDs (Primary Key Index)

In production databases, entities rarely have continuous 0-indexed integer IDs. You usually have:

  • UUIDs: "550e8400-e29b-41d4-a716-446655440000"
  • String Business Keys: "USR-98421", "alice@example.com"
  • Sparse Relational IDs: 102, 594, 100024, 8847192

How Key Mapping Works

When compiling snapshots from CSV/Parquet manifests with the standalone impulse-graph build CLI, the compiler builds a compact Section 4 hash index mapping external string/UUID keys to dense IDs (\(0 \dots N_d-1\)).

In Java ingestion pipelines, external database keys are translated during stream generation using an IdMapper<K>:

// Map external database keys (e.g. Long, String, UUID) to continuous 0..N-1 dense IDs:
IdMapper<String> userMapper = new StringIdMapper("User");
long aliceDenseId = userMapper.getOrAssignId("alice@example.com"); // 0
  • At Ingestion Time: External keys are mapped to continuous \(0 \dots N_d-1\) integers.
  • During Traversal: All multi-hop vector traversals execute entirely on fast primitive integers.
  • At Result Materialization: You map target Dense IDs back to external business keys when returning results to your API callers.

8. Columnar Attributes: Structure of Arrays (SoA)

Traditional graph databases store node and edge properties as key-value property maps inside the node object.

Impulse Graph stores attributes using a Structure of Arrays (SoA) columnar layout:

Row-Oriented (Traditional):
[ { id: 0, age: 30, score: 9.5 }, { id: 1, age: 24, score: 7.2 }, ... ]

Columnar SoA (Impulse Graph):
age[]:   [ 30,   24,   45,   19,   62, ... ]  <-- Contiguous 32-bit integers
score[]: [ 9.5,  7.2,  8.8,  6.1,  9.0, ... ]  <-- Contiguous 32-bit floats

Why SoA Matters for Filtering

When evaluating a traversal filter like .filter("node.age >= 21"):

  • The CPU loads only the age vector directly into AVX-512 SIMD registers.
  • The CPU never reads score, names, or edge pointers from disk/RAM.
  • A single vector instruction evaluates 16 node filters simultaneously, producing a bitmask in nanoseconds.

9. The Impulse Binary Snapshot (.imps)

All of the above primitives—CSR matrices, CSC matrices, domain catalogs, string pools, and columnar attributes—are serialized into a single immutable file ending with .imps (Binary Snapshot Specification).

  • Page 0 (4KB): Fixed header with magic bytes 0x494D5053 (IMPS), version 0x000A, and hardware flags.
  • 128-Byte Hardware Alignment: All sections, matrices, and attribute arrays are strictly aligned to 128-byte boundaries. This matches AVX-512 cache lines and GPU warp memory coalescing (NVIDIA GPUDirect Storage cuFile).
  • Memory-Mapped (mmap): When your application starts, the operating system maps the .imps file into virtual memory in \(O(1)\) time without copying data onto the JVM heap or user-space object graphs.

10. Conceptual Glossary Summary

Term Canonical Definition Role in Impulse Graph
.imps Impulse Binary Snapshot File. Immutable, 128-byte-aligned binary file format.
Node Domain A distinct entity namespace (e.g., User, Account). Defines an independent dense ID space \(0 \dots N_d - 1\).
Dense ID A zero-indexed primitive integer (\(0 \dots N-1\)). Direct index into CSR offsets and columnar attribute arrays.
Relation A directed edge type connecting a source domain to a target domain. Encodes graph connections (e.g., User -[:OWNS]-> Account).
CSR Compressed Sparse Row matrix format. Contiguous row_offsets + column_targets for fast forward walks (out).
CSC Compressed Sparse Column matrix format. Transpose of CSR for fast reverse/incoming walks (in).
COO Coordinate format (src, tgt pairs). Stream ingestion format used before CSR/CSC compaction.
Primary Key Index Reverse index mapping external keys (UUID, String) to Dense IDs. Translates external business identifiers to dense integer coordinates.
SoA Attributes Structure of Arrays columnar property storage. Contiguous primitive vectors enabling SIMD filtering.
SnapshotBuilder Fluent Java builder (org.impulsegraph:impulse-builder). Single-pass streaming generator that builds .imps files direct to disk or S3.

Next Steps

Now that you understand the foundational architecture, dive into the hands-on walkthroughs: