The system. A fraud relationship graph: people, accounts, devices, addresses, phone numbers and transfers. Queries find rings - people connected through shared attributes - score accounts by their connectivity, trace money paths, and feed an investigator interface. An analyst role can see the graph without seeing account identifiers.
Three invariants must hold:
- Every query in the application has a bounded traversal - an upper hop limit, a relationship type list, and an anchored start - demonstrated by a PROFILE for each.
- The graph has no duplicate entities: one node per person, account, device, address and phone, enforced by constraints and proved by a query that finds none.
- The restricted analyst role returns different results, not errors, and cannot read the properties it is denied - tested, not asserted.
Invariant 1 is this capstone's distinguishing requirement, and the evidence is the PROFILE. A query that is bounded by inspection is not demonstrated; a query whose profile shows a NodeIndexSeek start and a bounded expansion is.
What is assessed. 20% knowledge checks, 35% laboratory portfolio, 15% troubleshooting practical, 30% capstone. Three things carry the capstone.
Bounded traversals with profiles as evidence. Every application query, with its PROFILE, its database hits, and the four bounds identified. A capstone containing an unbounded * anywhere fails this criterion, and the query limits from Module 6 must be configured as a backstop with proof that they fire.
A graph model defended on what it can express. Not "we used a graph database because the data is connected" - for each shared-attribute node, the fraud question it enables and the fact that a property model could not ask it. Include the model comparison from Module 2.
A defensible account of failure modes, operational limits and cost. Three things specifically: the supernode risk, with your highest-degree nodes identified and the queries that touch them bounded accordingly; the edition decision, with what Community would cost you in backup downtime and application-layer authorisation; and the page cache sizing, derived from the measured store size.
Deliverables: architecture diagram; the graph model with a diagram and the node-against-property reasoning; the numbered query list with a PROFILE for each; source code including transaction functions and batched writes; reproducible dataset with a realistic degree distribution; benchmark report with database hits; security review including the restricted-role test results; recovery runbook with measured RPO and RTO; sizing and cost plan with the edition comparison; and a short design defence.
// ================= Invariants, as runnable checks ==================
// 1. *** EVERY APPLICATION QUERY HAS A BOUNDED TRAVERSAL, PROVED BY
// *** A PROFILE. *** Bounded by inspection is not demonstrated.
PROFILE
MATCH (p:Person {id: $personId})
-[:LIVES_AT|USED_DEVICE|HAS_PHONE|OWNS*1..4]-
(other:Person)
WHERE other <> p
RETURN DISTINCT other.id, other.name
LIMIT 100;
// The profile must show:
// NodeIndexSeek <- an ANCHORED start (bound 4)
// VarLengthExpand(Pruning) <- with an UPPER LIMIT (bound 1)
// and NAMED TYPES (bound 2)
// db hits in the thousands, not the millions
//
// *** A CAPSTONE CONTAINING AN UNBOUNDED `*` ANYWHERE FAILS THIS
// *** CRITERION. *** Grep for it:
// grep -n '\[\*\]\|\*\.\.\]\|\[\*[^0-9]' *.cypher *.py
// 2. NO DUPLICATE ENTITIES. Constraints enforce it; a query PROVES it:
MATCH (p:Person) WITH p.id AS id, count(*) AS n WHERE n > 1
RETURN id, n; // expected: empty
MATCH (d:Device) WITH d.fingerprint AS fp, count(*) AS n WHERE n > 1
RETURN fp, n; // expected: empty
MATCH (a:Address) WITH a.normalised AS k, count(*) AS n WHERE n > 1
RETURN k, n; // expected: empty
// And the constraints that make it structural:
SHOW CONSTRAINTS;
// Note the normalisation: an Address node keyed on a NORMALISED
// string, because '1 High St' and '1 High Street' must be the SAME
// node or the fraud ring is invisible. That normalisation function
// is part of the model, and the design defence should say so.
// 3. THE RESTRICTED ROLE RETURNS DIFFERENT RESULTS, NOT ERRORS.
// Tested, not asserted:
// as fraud_app: MATCH (p:Person)-[:OWNS]->(a:Account)
// RETURN count(a) -> 500,000
// as analyst: the same query -> 0, NO ERROR
// as analyst: MATCH (p:Person) RETURN p.name, p.email
// -> name set, EMAIL NULL, NO ERROR
// Both outcomes are the DESIGN WORKING. A report that is silently
// shorter for one role is expected, and the test suite says so.
// ================= The model, defended by what it expresses ========
// For EACH shared-attribute node: the fraud question it enables, and
// the fact a property model could not ask it.
//
// :Address -> "who else lives here?" property: impossible
// :Device -> "who else used this device?" property: impossible
// :Phone -> "who else has this number?" property: impossible
// :Session -> "person + device + location
// at one time" property: impossible
// (three entities -> a NODE, Module 2 heuristic 3)
//
// "We used a graph database because the data is connected" is not a
// defence. "A property model cannot express the ring query, and here
// is the ring query" is.
// ================= The capstone queries ===========================
// Ring detection, bounded:
PROFILE
MATCH (seed:Person {id: $personId})
CALL {
WITH seed
MATCH path = (seed)-[:LIVES_AT|USED_DEVICE|HAS_PHONE*1..3]-(p:Person)
WHERE p <> seed
RETURN p, min(length(path)) AS hops
}
WITH p, hops
MATCH (p)-[:OWNS]->(a:Account)
RETURN p.id, hops, collect(DISTINCT a.id)[0..5] AS accounts
ORDER BY hops, p.id LIMIT 50;
// Money path, bounded, with a weight:
PROFILE
MATCH (from:Account {id: $fromId}), (to:Account {id: $toId}),
path = shortestPath((from)-[:TRANSFERRED*..6]->(to))
WHERE all(r IN relationships(path) WHERE r.amount > 100)
RETURN [n IN nodes(path) | n.id] AS route,
reduce(s = 0.0, r IN relationships(path) | s + r.amount) AS total,
length(path) AS hops;
// Connectivity score, bounded and DISTINCT:
PROFILE
MATCH (a:Account {id: $accountId})
OPTIONAL MATCH (a)-[:TRANSFERRED*1..2]-(peer:Account)
WITH a, count(DISTINCT peer) AS reach
OPTIONAL MATCH (a)<-[:OWNS]-(:Person)-[:USED_DEVICE]->(d:Device)
<-[:USED_DEVICE]-(:Person)
WITH a, reach, count(DISTINCT d) AS shared_devices
RETURN a.id, reach, shared_devices,
reach * 0.1 + shared_devices * 2.0 AS score;
// ================= Declare the baseline BEFORE measuring ==========
//
// Edition: Enterprise or Aura (RBAC and online backup REQUIRED
// by invariant 3 and the runbook - state this as a
// requirement, with what Community would cost)
// Instance: 16 GB heap, 32 GB page cache <- page cache SIZED
// FROM THE MEASURED STORE SIZE, not guessed
// Limits: db.transaction.timeout=60s
// dbms.memory.transaction.max=1g
// dbms.memory.transaction.total.max=4g
// dbms.transaction.concurrent.maximum=200
// Dataset: 2,000,000 Person, 3,000,000 Account, 1,500,000 Device,
// 1,000,000 Address, 40,000,000 TRANSFERRED
// *** with a REALISTIC DEGREE DISTRIBUTION *** - a few
// supernodes, because a uniform graph does not test
// what breaks
//
// Claim - latency AND DB HITS, per query:
// ring detection (3 hops) p99 < 80 ms db hits < 50,000
// money path (6 hops) p99 < 150 ms db hits < 200,000
// connectivity score p99 < 40 ms db hits < 20,000
// investigator node view p99 < 15 ms db hits < 5,000
// page cache hit ratio > 0.98
// restore RTO < 30 min, MEASURED
// RPO = the backup interval, stated
//
// AND the supernode inventory, because the bounds depend on it:
MATCH (n) WITH n, size([(n)--() | 1]) AS degree
WHERE degree > 10000
RETURN labels(n)[0] AS label, n.id AS id, degree
ORDER BY degree DESC LIMIT 20;
// For each one: which queries touch it, and what bound keeps them
// safe. A 500,000-degree clearing account makes a 3-hop traversal
// through it a different query from the same traversal elsewhere.
// ================= Failure modes ==================================
// an unbounded traversal the heap, and the server. The four
// bounds, plus the query limits as a
// BACKSTOP - and prove they fire.
// a SUPERNODE a hop that should be cheap reads
// millions of pointers. Identify
// them; bound the queries that pass
// through them; consider modelling
// around them (a :ClearingBatch node
// between the account and its
// transfers).
// MERGE on a non-identifying DUPLICATE ENTITIES, silently.
// property Invariant 2, and constraints make
// it structural.
// MERGE on a relationship duplicate NODES, silently. Merge
// pattern the nodes separately.
// missing OPTIONAL MATCH rows DISAPPEAR. The commonest cause
// of "my query is missing results".
// count() without DISTINCT path duplicates counted. A
// CORRECTNESS bug, not just a cost.
// Eager in a write query the heap. Batch with
// IN TRANSACTIONS.
// CartesianProduct a missing relationship or WITH.
// page cache too small every hop is a disk read and the
// whole architectural advantage is
// gone. The most important metric.
// deadlock under concurrency TRANSIENT. Transaction functions
// retry it; explicit transactions do
// not.
// bolt:// after an election the app talks to a node that
// refuses writes. Use neo4j://.
// reading a secondary without occasionally does not see its own
// a bookmark write. Measure the miss rate.
// Community backup DOWNTIME. Which is why the edition
// is a stated requirement.
//
// Verify after every restore with the three invariants, and AWAIT
// THE INDEXES before measuring anything - a restore does not
// guarantee they finished building.
CALL db.awaitIndexes(600);
Discussion
No questions on this topic yet. Sign in to ask the first one.