Neo4j is the most widely used graph database. Instead of tables and joins, data is stored as nodes (entities) and relationships (connections between them), both with properties. Queries that would need many joins in SQL — friends of friends, recommendation paths, fraud rings, network dependencies, knowledge graphs for AI — become simple and fast.

When a graph database fits

  • Highly connected data where relationships are as important as the records: social networks, recommendations, access control graphs, supply chains, IT infrastructure maps.
  • Queries that traverse variable-length paths (“all services that depend on this database, directly or indirectly”).
  • GraphRAG and knowledge graphs combined with LLMs.

For ordinary tabular data, a relational database remains simpler. See NoSQL vs SQL.

Editions

Community Edition is free (GPLv3) and runs a single instance. Enterprise adds clustering, role-based access control, online backups and more. This guide uses Community.

Option 1: Docker

docker run -d --name neo4j --restart unless-stopped \
  -p 127.0.0.1:7474:7474 -p 127.0.0.1:7687:7687 \
  -v neo4j-data:/data -v neo4j-logs:/logs \
  -e NEO4J_AUTH="neo4j/$(openssl rand -base64 18)" \
  -e NEO4J_server_memory_heap_max__size=1G \
  -e NEO4J_server_memory_pagecache_size=1G \
  neo4j:5

Note the password (visible with docker inspect neo4j | grep NEO4J_AUTH). Ports:

  • 7474 — HTTP (Neo4j Browser UI)
  • 7687 — Bolt protocol (drivers and the Browser’s database connection)

Option 2: apt package

wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/neo4j.gpg
echo "deb [signed-by=/etc/apt/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" | sudo tee /etc/apt/sources.list.d/neo4j.list
sudo apt update
sudo apt install -y neo4j
sudo neo4j-admin dbms set-initial-password 'a-long-random-password'
sudo systemctl enable --now neo4j

(Check Neo4j’s docs for the current repository and Java requirements.)

Config file: /etc/neo4j/neo4j.conf.

Memory

Neo4j uses a JVM heap and a page cache for the graph store:

server.memory.heap.initial_size=1g
server.memory.heap.max_size=1g
server.memory.pagecache.size=1g

neo4j-admin server memory-recommendation suggests values for your RAM. Keep heap + page cache + OS within available memory — 4 GB RAM is a comfortable minimum for real data.

Keep it private

Neo4j listens on localhost by default (server.default_listen_address). Reach the Browser through an SSH tunnel:

ssh -L 7474:127.0.0.1:7474 -L 7687:127.0.0.1:7687 user@your-server

Open http://localhost:7474, connect to bolt://localhost:7687. If apps on other servers need access, bind to a private IP and firewall port 7687 to those servers; enable TLS for Bolt over untrusted networks.

First Cypher queries

CREATE (a:Person {name: 'Alice'})-[:KNOWS]->(b:Person {name: 'Bob'}),
       (b)-[:KNOWS]->(c:Person {name: 'Carol'}),
       (a)-[:WORKS_AT]->(:Company {name: 'Acme'});

// Friends of friends
MATCH (p:Person {name: 'Alice'})-[:KNOWS*2]->(fof) RETURN fof.name;

// Shortest path
MATCH path = shortestPath((a:Person {name:'Alice'})-[:KNOWS*]-(c:Person {name:'Carol'})) RETURN path;

Create indexes and constraints for lookups:

CREATE CONSTRAINT person_name IF NOT EXISTS FOR (p:Person) REQUIRE p.name IS UNIQUE;

Import data

From CSV (place files in the import directory):

LOAD CSV WITH HEADERS FROM 'file:///people.csv' AS row
MERGE (:Person {id: row.id, name: row.name});

For very large initial loads, neo4j-admin database import is much faster (offline). The APOC library adds many import and utility procedures.

Backups (Community)

Community Edition supports offline dumps:

sudo systemctl stop neo4j
sudo neo4j-admin database dump neo4j --to-path=/var/backups/neo4j
sudo systemctl start neo4j

Restore with neo4j-admin database load. Online backups are an Enterprise feature. Copy dumps off the server.

Drivers

Official drivers exist for Python, JavaScript, Java, .NET and Go; connect with neo4j:// or bolt:// URIs and the database credentials. Use a dedicated user with limited privileges where your edition supports it.

Related: vector databases (often paired with graphs in AI apps) and MongoDB vs MySQL.

  • Neo4j
  • Graph Database
  • Databases