Graph
Model connected data as nodes and edges — Neo4j, and the traversal patterns behind social and recommendation features.
Graph databases represent entities as nodes and the connections between them as edges. Both can carry properties: a person node might have a name, while a FOLLOWS edge might record when the connection began. Relationships are first-class data, so traversing several connections is a natural operation rather than a series of manually assembled joins.
Picture it: Draw three dots for people and connect them with labelled arrows. If the question is about following those arrows, you are thinking in graphs.
Model the relationships
Consider a small professional network. A person is a node, a company is another node, and WORKS_AT connects them. A question such as “find people who work with someone I follow” becomes a traversal: start at one person, follow their FOLLOWS edges, then follow each person’s WORKS_AT edges.
In Neo4j’s Cypher syntax, a query might look like this:
MATCH (me:Person {name: "Ari"})-[:FOLLOWS]->(contact:Person)
-[:WORKS_AT]->(company:Company)
RETURN DISTINCT company.name
ORDER BY company.name;
The pattern describes connected nodes and edges. Graph query languages differ by product; RDF systems often represent facts as subject-predicate-object triples and may use SPARQL instead.
When a graph is a good fit
Graphs are useful when the relationships themselves are central to the questions being asked: recommendation paths, fraud rings, dependency maps, identity relationships, and knowledge graphs. Traversal performance depends on the database, indexes, graph shape, and how many neighboring nodes a query visits. A graph is not inherently faster for every workload; simple reports over large sets of independent records may fit a relational or analytical database better.
Design and operate a graph
- Identify the entity types, relationship types, and properties that matter to real queries.
- Give nodes stable identifiers and enforce uniqueness where the database supports constraints.
- Avoid uncontrolled high-degree nodes if common queries would have to traverse enormous neighborhoods.
- Add indexes for properties used to locate starting nodes.
- Review query plans and limit traversals to the path depth the question actually requires.
Start with a few representative questions, model only the necessary relationships, and test the queries against realistic graph sizes before committing to a graph database.