Designing Data-Intensive Applications
Ch. 2

Graph-Like Data Models

When connections between entities matter more than the entities themselves, graph models are the natural fit.

Many domains are inherently connected: social graphs, supply chains, knowledge bases, fraud detection. Representing these as relational tables with join tables works but makes traversal queries verbose and slow.

Property Graphs

In a property graph, vertices represent entities and edges represent relationships, both carrying key-value properties. Finding friends-of-friends or shortest paths becomes a native index traversal rather than a recursive SQL query.

In practice

LinkedIn's early social graph used custom graph storage; today Neo4j, Amazon Neptune, and Azure Cosmos DB (Gremlin API) handle relationship-heavy workloads. Banks use graph queries to trace money-laundering rings across accounts — a multi-hop traversal that would require recursive CTEs in PostgreSQL.

LinkedIn at scale

People You May Know and connection suggestions traverse multi-hop paths over billions of edges. A property graph makes friends-of-friends a native index walk instead of a four-table SQL join.

typescript — Graph pattern query (Cypher)
// LinkedIn-style graph traversal (Cypher / Neo4j pattern)
const mutualConnections = await graph.run(`
  MATCH (me:User {id: $userId})-[:CONNECTED_TO]-(friend)-[:CONNECTED_TO]-(fof)
  WHERE fof.id <> $userId AND NOT (me)-[:CONNECTED_TO]-(fof)
  RETURN DISTINCT fof.id, fof.name LIMIT 50
`, { userId });
// Multi-hop in one declarative query — expensive as SQL recursive CTE
  • Cypher (Neo4j): pattern-matching syntax for graph traversal.
  • SPARQL: W3C standard for RDF triple-stores.
  • Datalog: logic-based queries with recursive rules.
Key Takeaways
  • Property graphs store nodes, edges, and properties — ideal for social networks and recommendations.
  • Triple-stores represent facts as (subject, predicate, object) for semantic web data.
  • Graph traversals replace expensive multi-table joins in relational schemas.
  • Cypher and SPARQL express path queries declaratively.
  • Graph databases trade specialized traversal for weaker bulk analytics.
  • Neo4j and Amazon Neptune power fraud detection and knowledge graphs in production.
property graphNeo4jNeptuneCypherSPARQLgraph traversal