The model has four elements and no schema requirement.
A node is an entity. It has zero or more labels - :Person, :Account, :Device - which group nodes and are the basis of indexing. It has properties, a flat map of primitive values and arrays. There is no nesting: a property cannot be a map or a node.
A relationship connects exactly two nodes, has exactly one type - :OWNS, :TRANSFERRED_TO - is always directed, and may have properties of its own. That last point is what distinguishes a property graph from a simple network: the relationship is a place to put data, and (a)-[:TRANSFERRED {amount: 500, at: datetime()}]->(b) puts the transaction on the edge where it belongs.
Direction is stored but can be ignored at query time. A relationship always has a direction, and a MATCH may specify it (-->), reverse it (<--), or ignore it (--). The practical rule: store the direction that makes semantic sense and query in whichever direction you need. Creating both directions of a symmetric relationship is a common beginner mistake that doubles your relationship count and your write cost for nothing.
Index-free adjacency is the architectural claim. Each node stores pointers to its relationships, so finding a node's neighbours does not consult an index - it follows pointers. The cost of a hop is therefore proportional to the degree of the node you are standing on, not to the size of the database. That is why deep traversals are fast here and slow in a relational database, and it is also why a supernode - a node with millions of relationships - is the characteristic graph performance problem, since the hop that was supposed to be cheap now reads millions of pointers.
Cypher's core shape is MATCH a pattern, WHERE a predicate, RETURN a projection, with CREATE, MERGE, SET, REMOVE and DELETE for writes, and WITH to chain stages like a pipeline. The pattern syntax is the point: it is an ASCII drawing of the thing you are looking for.
Two Cypher facts to learn in Module 1. First, MATCH with no anchor scans every node with that label, and MATCH (n) with no label scans the entire graph - so every query needs a starting point that an index can serve. Second, DELETE on a node with relationships fails; you must DETACH DELETE, which deletes the relationships too, and that is a safety feature rather than an inconvenience.
Laboratory exercise 1 - provision and verify.
Stand up Neo4j 5 and open Browser. Record the version, the edition, and the configured heap and page cache sizes - both matter in Module 4.
Load at least 500,000 nodes and 2,000,000 relationships modelling the capstone's fraud graph: people, accounts, devices, addresses and transfers, with properties on both nodes and relationships.
Then demonstrate the model, each with evidence: put a property on a relationship and query by it; show a node with two labels matching both; attempt to store a nested map as a property and capture the error; and create a symmetric relationship in one direction and query it in both.
Then demonstrate index-free adjacency: measure a one-hop traversal from a node with degree 10 and from a node with degree 100,000, and record the difference. That is the supernode problem, seen early.
Finally, demonstrate the scan: run MATCH (n:Person) WHERE n.email = '...' RETURN n without an index and with one, and record the database hits for each from PROFILE.
Deliverable: an idempotent load script, a README with the version, edition, heap and page cache, the four model demonstrations, the degree comparison, and the indexed-against-unindexed profile comparison.
// ------------------------------------------------------------------
// Neo4j Browser at :7474 - keep it open. It draws results AS A
// GRAPH, which makes a wrong model obvious in a way a table of rows
// never does.
// ------------------------------------------------------------------
// docker run -d -p 7474:7474 -p 7687:7687 \
// -e NEO4J_AUTH=neo4j/password neo4j:5
CALL dbms.components(); // version and EDITION
CALL dbms.listConfig() YIELD name, value
WHERE name IN ['server.memory.heap.max_size',
'server.memory.pagecache.size']
RETURN name, value;
// Both matter in Module 4, and the defaults are rarely right.
// ------------------------------------------------------------------
// NODES: labels (plural, optional) + properties (FLAT).
// ------------------------------------------------------------------
CREATE (p:Person:Customer {
id: 'p-0001',
name: 'Ada Lovelace',
email: 'ada@example.test',
created_at: datetime('2026-11-30T14:04:00Z'),
risk_flags: ['new_device'] // ARRAYS are fine
});
// ^^^^^^^^^^ TWO labels. Both match:
MATCH (p:Person) RETURN count(p);
MATCH (p:Customer) RETURN count(p);
// PROPERTIES ARE FLAT. There is no nesting:
// CREATE (p:Person {address: {city: 'London'}});
// -> Property values can only be of primitive types or arrays
//
// THE MODELLING CONSEQUENCE, and it is the right one: a nested thing
// becomes A NODE, connected by a relationship. That is not a
// workaround - it is the graph telling you the address is an entity
// other people might also live at, which is exactly the fact a fraud
// graph cares about.
CREATE (a:Address {line1: '1 High St', city: 'London', postcode: 'E1 1AA'});
MATCH (p:Person {id:'p-0001'}), (a:Address {postcode:'E1 1AA'})
CREATE (p)-[:LIVES_AT {since: date('2024-01-01')}]->(a);
// ------------------------------------------------------------------
// RELATIONSHIPS: EXACTLY ONE type, ALWAYS directed, may have
// properties - and the properties are the point.
// ------------------------------------------------------------------
MATCH (a:Account {id:'acc-1'}), (b:Account {id:'acc-2'})
CREATE (a)-[:TRANSFERRED {
amount: 4500.00,
currency: 'GBP',
at: datetime('2026-11-30T14:04:00Z'),
channel: 'mobile'
}]->(b);
// THE TRANSACTION IS ON THE EDGE, which is where it belongs. In a
// relational model this is a row in a table joined to two others;
// here it is the relationship itself.
// DIRECTION IS STORED AND CAN BE IGNORED AT QUERY TIME:
MATCH (a:Account)-[:TRANSFERRED]->(b) RETURN a, b; // outgoing
MATCH (a:Account)<-[:TRANSFERRED]-(b) RETURN a, b; // incoming
MATCH (a:Account)-[:TRANSFERRED]-(b) RETURN a, b; // EITHER WAY
//
// *** THE RULE: store the direction that makes SEMANTIC SENSE and
// *** query in whichever direction you need. ***
// Creating BOTH directions of a symmetric relationship doubles your
// relationship count and your write cost FOR NOTHING. It is the
// commonest beginner mistake, and `--` is the fix.
// ------------------------------------------------------------------
// Cypher's shape: a pipeline. MATCH / WHERE / WITH / RETURN.
// ------------------------------------------------------------------
MATCH (p:Person)-[:OWNS]->(a:Account)-[t:TRANSFERRED]->(b:Account)
WHERE t.amount > 1000
AND t.at > datetime('2026-11-01T00:00:00Z')
WITH p, count(t) AS transfers, sum(t.amount) AS total
WHERE transfers > 5
RETURN p.name, transfers, total
ORDER BY total DESC
LIMIT 20;
// WITH chains stages like a pipeline, and it is where aggregation
// and intermediate filtering happen. A WHERE after WITH filters
// the AGGREGATED rows - which is Cypher's HAVING.
// ------------------------------------------------------------------
// *** INDEX-FREE ADJACENCY, and the SUPERNODE problem. ***
// ------------------------------------------------------------------
// Each node stores POINTERS to its relationships. Finding neighbours
// does not consult an index - it FOLLOWS POINTERS. So the cost of a
// hop is proportional to THE DEGREE OF THE NODE YOU ARE STANDING ON,
// not to the size of the database.
//
// That is why deep traversals are fast here. And it is why a
// SUPERNODE - a node with millions of relationships - is the
// characteristic graph performance problem: the hop that was
// supposed to be cheap now reads millions of pointers.
//
// MEASURE IT in the lab:
MATCH (a:Account {id: 'acc-low-degree'})-[:TRANSFERRED]->(b)
RETURN count(b); // degree 10: ~1 ms
MATCH (a:Account {id: 'acc-clearing'})-[:TRANSFERRED]->(b)
RETURN count(b); // degree 100,000: ~900 ms
//
// Find your supernodes before they find you:
MATCH (n)
RETURN labels(n) AS labels, n.id AS id,
size([(n)--() | 1]) AS degree
ORDER BY degree DESC LIMIT 20;
// ------------------------------------------------------------------
// *** EVERY QUERY NEEDS AN ANCHOR AN INDEX CAN SERVE. ***
// ------------------------------------------------------------------
PROFILE MATCH (p:Person) WHERE p.email = 'ada@example.test' RETURN p;
// NodeByLabelScan | 500,000 rows | 500,001 db hits
// ^^^^^^^^^^^^^^^ EVERY Person
CREATE INDEX person_email IF NOT EXISTS FOR (p:Person) ON (p.email);
PROFILE MATCH (p:Person) WHERE p.email = 'ada@example.test' RETURN p;
// NodeIndexSeek | 1 row | 2 db hits
//
// *** db hits IS THE NUMBER THAT MATTERS. *** Not rows, not time on
// a warm cache - the actual work done. PROFILE every query you
// intend to run twice.
MATCH (n) RETURN count(n);
// This scans the ENTIRE GRAPH. Fine for a count; never as the
// start of a traversal.
// ------------------------------------------------------------------
// DELETE: the safety feature that looks like an inconvenience.
// ------------------------------------------------------------------
MATCH (p:Person {id:'p-0001'}) DELETE p;
// -> Cannot delete node<123>, because it still has relationships.
MATCH (p:Person {id:'p-0001'}) DETACH DELETE p;
// Deletes the node AND its relationships.
//
// A good default: it makes you say that you meant to remove the
// edges too. In bulk, delete in BATCHES or you will exhaust the
// heap on one transaction:
MATCH (p:Person) WHERE p.created_at < datetime('2020-01-01T00:00:00Z')
CALL { WITH p DETACH DELETE p } IN TRANSACTIONS OF 10000 ROWS;
Discussion
No questions on this topic yet. Sign in to ask the first one.