Or just stay in PostgreSQL and add some recursive CTEs for the graph traversals. Are you seeing more usage moving from PostgreSQL to Neo4J or the other way around?
Great point, and honestly for a lot of teams that’s the right call. If your traversals are shallow and predictable, recursive CTEs in Postgres work well, and you keep one database.
Where I’ve seen Neo4j pay off is deep or open-ended traversals: friend-of-friend, fraud rings, recommendations, dependency graphs. Those queries get painful to write and slow to run as recursive SQL.
It’s still early days for RtoGtoR, so I don’t have real usage numbers yet. But the reason I built it both ways is that the answer often changes. Teams try a graph, decide it isn’t worth it, and move back. Or they keep Postgres as the system of record and copy data into Neo4j just for graph-heavy analysis. I wanted that move to be safe in either direction, not a one-way bet.
Curious what you’ve seen. Have recursive CTEs held up for you at scale?
It depends on how you write the traversal more than on CTEs vs. a graph database.
I maintain TypeGraph, a TypeScript graph layer over Postgres and SQLite. We ran LDBC SNB at SF10 (~65k persons, 3.9M knows edges, ~29M posts and comments) against Neo4j Community (2026.05, memory-tuned), plain Postgres, SQLite, and pgGraph, a Postgres extension that keeps an in-memory adjacency index (CSR). p50 results, in the order Neo4j / TypeGraph on Postgres / TypeGraph on SQLite / pgGraph:
Point lookups (IS1-7): 3-133ms / 1-77ms / 0.03-2ms / 1-23ms
What we learned:
The naive recursive CTE is the trap. UNION ALL plus a path array for cycle detection enumerates paths, not nodes, so the cost grows exponentially with depth. Our first version took 44s to find a shortest path for one pair at 8 hops on a 31-node test graph. Switching to set-based frontier expansion (keep a visited set, only expand newly reached nodes, search from both ends for shortest path) brought that to under a millisecond. That's iterative SQL with a temp table, not one recursive CTE. A lot of "recursive SQL is slow" is really "recursive SQL written as path enumeration."
Whole-graph algorithms are where SQL really loses. Connected components at SF10 took 69ms in pgGraph, ~2 min on SQLite, and ~8.5 min on Postgres, and the gap grew with scale (round after round of full SQL passes vs. an in-memory adjacency structure). Neo4j Community can't run it without the GDS plugin either.
For traversal, Postgres was 2-4x slower than Neo4j for us. That's real, but it's a constant factor rather than a cliff, and in exchange you keep one system of record and real transactions.
So my rule of thumb: for transactional workloads with traversals, stay relational and write the traversal set-based. For analytics over the whole graph, use a specialized engine, and that can live inside Postgres as an extension. Caveat: single box (r7i.4xlarge), shared vCPU, so treat sub-ms differences as noise.
This is a fantastic breakdown. Thank you for sharing real numbers instead of opinions.
The path-enumeration point is the big one for me. “Recursive SQL is slow” often really means “recursive SQL that lists every path instead of every node.” The jump from 44s to under 1ms just from switching to frontier expansion says it all.
The SQLite results surprised me too. Beating Neo4j on shortest path and 3-hop is not what most people would expect.
Your rule of thumb matches why I built RtoGtoR to work both ways. It isn’t trying to argue that graph databases are better. It’s for the cases where teams do want a separate engine, such as whole-graph analytics or trying Neo4j out, and need to move data there and back safely while Postgres stays the system of record.
Curious: with pgGraph keeping the adjacency index in memory, how do you keep it in sync with writes? Is it updated on every transaction, or rebuilt in batches?
Small correction on my own numbers first: SQLite beat Neo4j on 3-hop at both scales, but on shortest path it was basically a tie at SF1 (3.9 vs 3.2 ms, Neo4j slightly ahead) and only pulled ahead at SF10 (35 vs 82 ms). pgGraph was fastest on shortest path at both.
On sync: pgGraph isn't mine. It's a separate Postgres extension I benchmarked against. For the benchmark I deliberately turned its sync off (sync_mode = 'manual', one graph.build() after a static load), so my numbers say nothing about its write path.
From their docs, though: the default is trigger-based. Every write to a registered table appends a row to a durable sync log, and the next traversal replays pending rows into an in-memory overlay before it runs, so writes are visible without a rebuild. Full rebuilds are still needed for things like TRUNCATE, schema changes, or overflowing the edge buffer. There's also an opt-in mode that writes changes to shared durable segments with compaction. The tradeoff is that the read after a write burst pays to catch up, which is the usual price of a derived in-memory index.
TypeGraph sidesteps the question by not having a derived index. Traversal runs as SQL over the same tables you write to, so it's always current, and you pay for that in raw traversal speed compared with a CSR engine.
Thanks for the correction, and sorry for mixing up pgGraph with your project. Appreciate you clearing up both.
That tradeoff is a really useful way to frame it: a derived index gives fast reads but has to catch up after writes, while TypeGraph’s “traverse the tables you write to” approach is always current but slower.
The same tension applies to what I’m building. Copying data from Postgres into Neo4j is also a derived copy, just a much heavier one. Right now RtoGtoR runs in batches rather than syncing live, so the graph is only as fresh as the last run. That’s why I put so much weight on verify (checking that both sides match) and on safe re-runs. Live sync, including passing deletes through, is something I’m still thinking about.
Going to dig into TypeGraph properly. Thanks for one of the best comment threads I’ve had on a post.
2
u/pdlug 8d ago
Or just stay in PostgreSQL and add some recursive CTEs for the graph traversals. Are you seeing more usage moving from PostgreSQL to Neo4J or the other way around?