Every learner who enrolls in a GraphAcademy course that needs a database gets one. We provision a real Aura instance in the background, track it, and resume it when you come back. It works well, but for Neo4j Fundamentals, it's too much.
Neo4j Fundamentals teaches you the principles of graph databases (nodes, relationships, properties and labels) and introduces Cypher with a few MATCH queries on a small movie graph. Until recently, we were provisioning thousands of databases a month for it, and a learner might run a single write query against theirs.
What a provisioned instance costs
A real instance is a real resource that needs to be created, managed and terminated. The learner waits while it comes up, and credentials have to reach the browser and be trusted when they arrive. Each step is a place for a beginner's first few minutes to go wrong.
At thousands of instances a month, that has a considerable cost. The commit that made the change gave its reason in one line, "save real database provisions for this course".
The alternative
Relate is an open-source embedded graph database. It runs inside your application with no server to deploy, and it compiles to WebAssembly. It speaks Cypher and is tested against the openCypher TCK (technology compatibility kit).
Query execution was already client-side for us, because the query app connects to Aura straight from the browser. Swapping that connection for an in-memory engine left the rest of the app almost unchanged. We also got to remove the server-side process, the Bolt authentication, and the create, pause, resume and stop machinery.
Learners can still create nodes, change them and break things, because the engine accepts writes like any other Cypher database. This write runs in your tab right now:
CREATE (p:Person {name: 'Ada Lovelace'})
RETURN p.name AS nameRunning Relate in your own page
To do the same in a web page, install the WebAssembly package from npm:
npm install @relate/relate-wasmInitialize the module, create an instance and call execute with a query and a JSON string of parameters (or null). It returns the result as a JSON string, which includes the columns, the rows and an error field for engine errors:
import init, { RelateDb } from "@relate/relate-wasm";
await init();
const db = new RelateDb();
db.execute("CREATE (:Person {name: 'Ada Lovelace'})", null);
const result = JSON.parse(
db.execute("MATCH (p:Person) RETURN p.name AS name", null)
);
console.log(result.rows); // [{ name: "Ada Lovelace" }]The instance is in memory, so it forgets everything when the page reloads. The glue code loads the .wasm file from beside itself, so a bundler that renames or inlines it breaks the load. The Relate browser guide covers serving it as a static file and running the engine in a worker.
Where to go next
- Relate documentation
- Run Relate in the browser, a first web page on the WebAssembly package
- Use Relate from a web page, for bundlers, workers and persistent storage in the browser
- Relate agent skill, which teaches an AI assistant to drive Relate
To have your coding agent do the setup, give it this prompt:
Set up relate for me. Read https://relatedb.ai/skill.md, install the relate agent skill, create a database, add my data, and answer my questions by writing Cypher queries.Try it yourself
Enroll in Neo4j Fundamentals and run your first Cypher query in the same in-browser engine.
Comments (0)
Loading comments...