Databases

Neo4j

The best-known graph database where nodes and relationships are first-class objects, with the Cypher query language.

What it is

Neo4j stores data as a graph: nodes with labels and properties and relationships with a direction and type. Traversing relationships is fast because each node points directly to its neighbors (index-free adjacency).

Queries are written in Cypher, which describes a pattern with parentheses and arrows: (a)-[:FRIEND]->(b). It suits recommendations, fraud detection, knowledge graphs and routing.

It has ACID transactions, clustering and the Graph Data Science library. The Community Edition has limits, and many enterprise features are in the commercial edition and AuraDB.

Use it when

  • Data with deep relationships: social networks, recommendations, dependencies.
  • Fraud detection through links between entities.
  • Knowledge graphs and pathfinding.

Avoid it when

  • Simple tabular data without complex relationships: a relational database.
  • Mass aggregations over all data (OLAP): ClickHouse.

Key concepts

Node / Relationship
An entity and a typed directed link between entities.
Label / Property
A node type and key-value pairs.
Cypher
A declarative query language based on graph patterns.
Index-free adjacency
Nodes point directly to neighbors with no index lookup.

Example

Friend-of-friend recommendations in Cypher.

Interview questions

  1. 1. When is a graph better than a relational database?

    When queries go deep through relationships (friends of friends, dependency chains). In SQL that is many joins that slow down quickly, while in a graph it is pointer traversal.

  2. 2. What is index-free adjacency?

    Each node keeps direct references to its neighboring relationships, so traversal cost depends on the part you visit, not on the whole graph size.

  3. 3. How do you express a relationship in Cypher?

    With a pattern using an arrow and a type: (a)-[:KNOWS]->(b). MATCH finds such patterns, RETURN returns the result.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).