Load a big graph, and load it again
Tens of thousands of edges should go in fast, and sending them again after a failure should be safe.
The situation
For a team that loads connected data from another system, often on a schedule. Plain Apache AGE writes with Cypher, row by row: about 31 edges a second, and every service solving loading and indexing on its own.
Step by step
-
Problem 1. Row by row through Cypher
Each edge is a Cypher MERGE of its own, sent straight to the database. In graphos's own benchmark, an earlier graphos that still wrote this way managed 31 edges a second.
Edges written a second: 31 · Sending it again: — · An edge whose end is missing: —
-
With graphos 2. A stream into the API
The loader sends nodes and edges to graphos-api as an NDJSON stream (
…/graph/nodes:bulk,…/graph/edges:bulk), or as JSON batches of up to 1,000 rows.A stream commits every 500 rows, each batch in its own transaction. A bad line is counted in
rows_invalid, and the first 50 are listed. -
How it works 3. COPY, then upsert
graphos writes each batch with a binary COPY into a staging table, then
INSERT … ON CONFLICT DO UPDATE. It is the only write path.Measured on 13,000 nodes and 44,000 edges, with 4 GB of shared_buffers on one host: 1,153–4,840 edges a second.
Edges written a second: 1,153–4,840
-
How it works 4. A missing end: skipped and counted
An edge whose source or target node doesn't exist isn't written; it is counted in
edges_skipped. Duplicates within a batch collapse, and the last one wins.An edge whose end is missing: skipped and counted
-
With graphos 5. Sent again: the data as it was
If the load fails halfway, sending the whole stream again is safe: the data ends up as it was meant to be.
Each repeated row still records a new revision and a change in the change feed, so a repeat isn't free.
Sending it again: safe: the data unchanged
-
How it works 6. A whole graph at once
A snapshot import takes nodes and edges in one NDJSON stream, up to 50 million rows, committing every 5,000. Like a stream, it isn't one transaction.
Measured on a single machine: an export of 1.19 million rows imported into an empty tenant in 447 s, about 2,500 rows a second.
What graphos does here
- Writes through the API
- COPY-staged upserts: the one write path.
- graphos-api
- Takes batches, NDJSON streams and snapshots.
- Change feed
- Records every write, a repeat included.
- Plain AGE underneath
- The rows land in ordinary AGE tables.
What shows it: Measured
Measured, on the graphos page and in its Apache AGE notes: 1,153–4,840 edges a second on 13,000 nodes and 44,000 edges with 4 GB of shared_buffers, against 31 for per-row Cypher MERGE (from an earlier graphos, which can no longer be rerun); and a 1.19-million-row import in 447 s on a single machine. Tests check that an upsert is idempotent and that an edge with a missing end is skipped.
In graphos's latest release, with a result measured in graphos's own docs; each says on what.
Try it
The example 02_bulk_load.py loads a graph in bulk, then as a snapshot, and prints what was written and skipped.
Related use cases
- Keep the edges equal to the source · The graph should match the source system's current edges, without a gap while it catches up.
- A spreadsheet in, checked first · A CSV file from a spreadsheet or another system should become nodes, with every row checked before anything is written.
- Follow every change · A search index, a cache or another service should learn what changed in the graph, and never miss a write.