# Why use a Graph Database?

> Understanding why graph databases are essential for identity, authorization, and the IndyKite platform.

**Category:** Environment

## Summary

Why graph databases outperform relational databases for connected data and authorization use cases.

## Content

# What is a Graph Database?

A graph database stores data as **nodes**, **relationships**, and **properties** instead of tables and rows. This structure mirrors how data exists in the real world—as interconnected entities with meaningful relationships.

Think of it as sketching ideas on a whiteboard: you draw circles (entities) and connect them with arrows (relationships). A graph database stores data exactly that way.

### What are the core components?

| Component | Description | Example |
| --- | --- | --- |
| **Node** | An entity or object in your domain | `Person`, `Document`, `Application` |
| **Label** | A tag that classifies nodes into groups | `:User`, `:Employee`, `:Document` |
| **Relationship** | A named, directed connection between two nodes | `OWNS`, `MEMBER_OF`, `CAN_ACCESS` |
| **Property** | A key-value pair on nodes or relationships | `email: "alice@example.com"` |

# Why are relationships important?

In graph databases, **relationships are first-class citizens**—they are stored natively alongside nodes, not computed at query time.

This is fundamentally different from relational databases, where relationships are represented as foreign keys and computed through JOIN operations.

### What does "first-class citizen" mean?

- **Stored natively**: Each node physically points to its connected nodes.
- **Always available**: Relationships exist as persistent data, not derived from keys.
- **Rich with properties**: Relationships can have their own attributes (e.g., `GRANTED_ON: "2024-01-15"`).
- **Directional**: Every relationship has a start node, end node, and type.

# How do graph databases compare to relational databases?

### Why do relational databases struggle with connected data?

Relational databases were designed for structured, tabular data. When data becomes highly connected, they face significant challenges:

| Challenge | Relational Database | Graph Database |
| --- | --- | --- |
| **Representing relationships** | Foreign keys in separate tables | Native relationship objects |
| **Querying relationships** | JOIN operations across tables | Direct traversal between nodes |
| **Multi-hop queries** | Multiple JOINs, exponential complexity | Simple path traversal |
| **Schema changes** | ALTER TABLE, migrations, downtime | Add nodes/relationships on the fly |
| **Performance at scale** | Degrades with more JOINs | Consistent regardless of data size |

### What is the JOIN problem?

In relational databases, answering the question "Can Alice access Document X?" might require:

1. Query the `users` table to find Alice.
2. JOIN with `user_groups` to find her groups.
3. JOIN with `group_roles` to find roles for those groups.
4. JOIN with `role_permissions` to find permissions for those roles.
5. JOIN with `resource_permissions` to check if any permission grants access to Document X.

Each JOIN adds latency and computational cost. As the number of hops increases, performance degrades exponentially.

### How does a graph database solve this?

The same query in a graph database:

```cypher
MATCH (alice:User {email: "alice@example.com"})-[:MEMBER_OF]->(:Group)-[:HAS_ROLE]->(:Role)-[:CAN_ACCESS]->(doc:Document {id: "X"})
RETURN doc
```

The graph database traverses from Alice through her groups, roles, and permissions in a single operation. Performance remains consistent regardless of data size because it only visits the nodes connected to Alice—not the entire dataset.

# When should I use a graph database?

Graph databases excel when **relationships between data points matter more than the individual points themselves**.

### What are the ideal use cases?

| Use Case | Why Graphs Work Better |
| --- | --- |
| **Identity & Access Management** | Users, groups, roles, permissions form a natural hierarchy of relationships |
| **Authorization** | Access decisions depend on traversing relationship paths |
| **Fraud Detection** | Detecting fraud requires finding suspicious patterns across connected entities |
| **Recommendation Engines** | "Users who liked X also liked Y" is a relationship query |
| **Knowledge Graphs** | Representing semantic relationships between concepts |
| **Network & IT Operations** | Infrastructure components are interconnected by nature |
| **Master Data Management** | Connecting data across siloed systems |

### When are relational databases still appropriate?

- Primarily tabular data with few relationships.
- Simple CRUD operations on isolated records.
- Transactional systems with rigid schemas.
- Reporting and analytics on flat data.

# Why is a graph database essential for authorization?

Authorization is fundamentally about relationships:

- Does this **user** have a **relationship** to this **resource** that permits this **action**?
- Is this **user** a **member of** a **group** that has a **role** with **permission** to access this **resource**?

These questions are naturally expressed as graph traversals.

### What problems do traditional authorization systems have?

| Problem | With Relational DB | With Graph DB |
| --- | --- | --- |
| **Role explosion** | Create thousands of roles to cover all combinations | Model relationships directly, no artificial roles needed |
| **Policy sprawl** | Maintain long ACLs for every resource | Define policies as graph patterns |
| **Complex hierarchies** | Recursive queries or denormalization | Natural hierarchy traversal |
| **Real-time decisions** | Cached permissions, stale data | Live traversal of current state |
| **Audit trails** | Difficult to trace decision path | Clear, traceable graph paths |

# What is the Identity Knowledge Graph (IKG)?

The Identity Knowledge Graph is IndyKite's graph database that stores all identity and resource data. It is the foundation of the IndyKite platform.

### What does the IKG contain?

- **Human identities**: Users, customers, employees with their attributes.
- **Non-human identities**: Applications, services, devices, AI agents.
- **Resources**: Documents, APIs, data, any protected asset.
- **Relationships**: How all these entities connect to each other.
- **Context**: Attributes, metadata, and environmental data.

### Why is the IKG important for IndyKite?

Every IndyKite capability operates on the IKG:

| Capability | How it uses the IKG |
| --- | --- |
| **Capture** | Stores nodes and relationships in the graph |
| **KBAC (AuthZEN)** | Evaluates policies by traversing graph relationships |
| **ContX IQ (CIQ)** | Reads and updates graph data with authorization |
| **Token Introspect** | Maps token claims to nodes in the graph |
| **Outbound Events** | Triggers events when graph data changes |

# Why is a graph database important for KBAC?

**Knowledge-Based Access Control (KBAC)** is IndyKite's authorization model that uses the IKG to make intelligent, context-aware access decisions.

### How does KBAC use the graph?

KBAC policies are defined as **graph patterns**. When an authorization request arrives, IndyKite:

1. Maps the request to nodes in the IKG (subject, resource, action).
2. Evaluates the policy by traversing relationships in the graph.
3. Returns a decision based on whether the pattern exists.

### Example: Can Alice drive Car X?

Policy definition:

```json
{
  "meta": {
    "policy_version": "2.0-kbac"
  },
  "subject": {
    "type": "Person"
  },
  "actions": [
    "CAN_DRIVE"
  ],
  "resource": {
    "type": "Car"
  },
  "condition": {
    "cypher": "MATCH (subject:Person)-[:OWNS]->(resource:Car)"
  }
}
```

This policy says: A `Person` can `CAN_DRIVE` a `Car` if there is an `OWNS` relationship between them.

The graph database traverses from Alice to Car X, looking for an `OWNS` relationship. If it exists, access is granted. If not, access is denied.

### Why can't relational databases do this efficiently?

- **Variable-depth traversals**: "Can Alice access any document in any project she's a member of?" requires recursive queries.
- **Multiple relationship types**: Different paths may grant access (direct ownership, group membership, role assignment).
- **Real-time evaluation**: Authorization must be checked at request time, not from cached data.
- **Contextual attributes**: Decisions may depend on attributes along the path, not just endpoints.

# Why is a graph database important for CIQ?

**ContX IQ (CIQ)** delivers authorized data retrieval and mutation. It uses the graph to:

- **Define what data can be accessed**: Policies specify graph patterns.
- **Query related data**: Knowledge Queries traverse relationships to find results.
- **Update connected data**: Create or modify nodes and relationships in context.

### Example: Get license plates for a person's vehicles

Policy pattern:

```cypher
MATCH (subject:Person)-[:ACCEPTED]->(contract:Contract)-[:COVERS]->(vehicle:Vehicle)-[:HAS]->(ln:LicenseNumber)
```

This query traverses from a Person through their Contracts to covered Vehicles and their License Numbers. The graph database follows these relationships efficiently, regardless of how many contracts, vehicles, or license numbers exist in the system.

# How does graph performance scale?

### Why is graph traversal fast?

Graph databases use **index-free adjacency**: each node directly references its connected nodes. This means:

- **No index lookups**: Relationships are stored as direct pointers.
- **Local traversal**: Queries only visit relevant nodes, not the entire dataset.
- **Constant time per hop**: Adding more data doesn't slow down individual traversals.

### How does this compare to JOIN performance?

| Aspect | Relational JOIN | Graph Traversal |
| --- | --- | --- |
| **Time complexity** | O(n × m) for each JOIN | O(k) where k = nodes visited |
| **Multi-hop queries** | Exponential slowdown | Linear with path length |
| **Index dependency** | Requires careful index design | Built-in via adjacency |
| **Dataset growth** | JOINs slow as tables grow | Unaffected by total size |

Graph databases can traverse millions of relationships per second, maintaining consistent performance year over year.

# How does schema flexibility help?

### What is schema-optional?

Graph databases like Neo4j are **schema-optional**: you can add new node types, relationship types, and properties without schema migrations.

### Why does this matter for identity and authorization?

- **Evolving requirements**: Add new entity types (AI agents, IoT devices) without restructuring.
- **Heterogeneous data**: Different nodes can have different properties.
- **Integration**: Connect data from multiple sources with different schemas.
- **Rapid iteration**: Model changes don't require downtime or migrations.

### Example: Adding AI agents to your system

With a relational database, adding AI agents as a new identity type might require:

1. Creating new tables (`ai_agents`, `ai_agent_permissions`).
2. Modifying existing tables to reference the new tables.
3. Updating all JOIN queries to include the new tables.
4. Running migrations and potentially causing downtime.

With a graph database:

1. Create nodes with the `:AIAgent` label.
2. Create relationships to existing resources.
3. Existing queries continue to work.
4. New queries can traverse to AI agents immediately.

# What is Cypher?

**Cypher** is Neo4j's declarative query language for graph databases. It is designed to express graph patterns intuitively.

### How does Cypher work?

Cypher uses ASCII art-like syntax to describe graph patterns:

- `(node)` — Represents a node
- `-[:RELATIONSHIP]->` — Represents a directed relationship
- `{property: value}` — Filters by property

### Example queries

**Find all documents Alice can access:**

```cypher
MATCH (alice:User {email: "alice@example.com"})-[:CAN_ACCESS]->(doc:Document)
RETURN doc
```

**Find access through group membership:**

```cypher
MATCH (alice:User {email: "alice@example.com"})-[:MEMBER_OF]->(group:Group)-[:CAN_ACCESS]->(doc:Document)
RETURN doc
```

**Variable-length path (any depth):**

```cypher
MATCH (alice:User {email: "alice@example.com"})-[:MEMBER_OF*1..5]->(group:Group)-[:CAN_ACCESS]->(doc:Document)
RETURN doc
```

### How does IndyKite use Cypher?

IndyKite KBAC and CIQ policies use Cypher in the `condition.cypher` field to define graph patterns. When a policy is evaluated, IndyKite executes the Cypher pattern against the IKG to determine access.

# How does the IKG support real-time decisions?

### What problem does real-time authorization solve?

Traditional authorization systems often use cached permissions:

- Permissions are computed periodically and stored.
- Changes take time to propagate.
- Stale data can grant access that should be revoked.

### How does the IKG enable real-time decisions?

The IKG maintains the current state of all entities and relationships:

- **Live data**: Authorization queries traverse current relationships.
- **Immediate revocation**: Delete a relationship, access is revoked instantly.
- **Contextual factors**: Evaluate time, location, device at request time.
- **No cache invalidation**: No need to manage permission caches.

# IndyKite-hosted or customer-hosted: which IKG do I get?

The database behind the IKG is Neo4j in both cases. The choice is made once, when the organization is created, and applies to every project in it; it cannot be changed afterwards. What differs is who runs Neo4j and what you supply when you create a project.

| Aspect | IndyKite-hosted | Customer-hosted |
| --- | --- | --- |
| Who runs Neo4j | IndyKite provisions and operates the database; nothing to install. | You run your own Neo4j Enterprise deployment, on your infrastructure or on Neo4j Aura, and IndyKite connects to it. |
| What you choose per project | `region` (where the IKG and the project's data live), optional `replica_region` for a synchronized read replica in a second region, and `ikg_size`: 2GB (1 CPU), 4GB (1 CPU), 8GB (2 CPUs), 16GB (3 CPUs), 32GB (6 CPUs), 64GB (12 CPUs), 128GB (24 CPUs), 192GB (36 CPUs), 256GB (48 CPUs), 384GB (82 CPUs), 512GB (96 CPUs). Optionally `ikg_schema_version`, the schema version of the IKG: `v1` (the default) or `v2`; `v2` is not supported yet and is refused with `422`. Region, replica region and schema version cannot be changed afterwards. What the schema version changes, today only the subject fields of a Token Introspect configuration, is in the [Token Introspect guide](/guides/guide-token-introspect#schema-versions). | `region` for the control plane, plus `db_connection`: `url`, `username`, `password` and optionally `name`, the database to use (see below). |
| Data residency | One region per project, optionally with a replica. | Any location you can host Neo4j in, and the only option for **composite databases**, which place individual nodes in different locations (see the [Data Residency guide](/guides/guide-data-residency)). |
| Change data capture | Enabled by IndyKite. | Enabled by IndyKite on the database at project creation, except on a customer-hosted **Neo4j Aura** instance, where it cannot be switched on from outside. Replication and the live data schema depend on it, so they are not available there. |
| Deleting the IKG or the project | Data and database are removed with the project. | Deleting the IKG removes the data from your database; deleting the project removes only the project configuration. The instance stays yours. |
| Created with | `POST /configs/v1/projects` without `db_connection`, or Terraform `indykite_application_space` with `ikg_size`. | The same call with `db_connection`, or the Terraform resource with a `db_connection` block (see the [Terraform guide](/guides/guide-terraform)). |

## Minimum requirements for a customer-hosted database

Before linking a project, the platform connects to your database and checks it. A database that fails a check is not linked, and project creation fails with `The database does not meet the minimum requirements.`

| Requirement | Minimum |
| --- | --- |
| Neo4j version | `5.24` or newer, including the calendar-versioned releases (`2026.x`). The latest stable release is recommended. |
| Edition | Enterprise Edition. Community Edition is refused. |
| Plugin | [APOC](https://neo4j.com/docs/apoc/current/installation/) installed and enabled. |
| Reachability | The database must accept connections from the IndyKite platform. Open the firewall or private-network route before creating the project; an unreachable database fails with `Unable to connect to your database. Please check your connection details and availability.` |
| Credentials | A user with administrator rights. At project creation the platform creates the constraints and indexes the IKG relies on and enables change data capture on the database (an `ALTER DATABASE` statement), which ordinary users cannot do. |
| Database | The database named in `db_connection.name` must already exist; otherwise `The specified database does not exist. Please create it first.` Without a name, the server's default database is used. One database (server plus database name) can be linked to one project only; a second attempt fails with `This database is already linked to another project.` Other databases on the same server can serve other projects. |

Creation is asynchronous. The project's `ikg_status` is `PENDING` while the checks and the setup run, then `ACTIVE`, or `FAILED` with one of the messages above.

## Which connection URL scheme should I use?

`db_connection.url` is a Neo4j connection URL. The platform accepts it as given and uses the scheme to decide how to connect; a value without a scheme or without a host is refused at once with `422` and `invalid db connection URL: connection URL is missing a scheme` or `invalid db connection URL: connection URL is missing a host`. A host written as a literal loopback, link-local or private-range address is refused the same way with `db connection URL: destination is not permitted`: the database has to be reachable from the IndyKite platform over a public address. A host name is not resolved at this point; whether it can be reached is found out by the connection check that follows.

| Scheme | Connects to | Encryption |
| --- | --- | --- |
| `neo4j://` | your cluster, with routing | none |
| `neo4j+s://` | your cluster, with routing | TLS, CA-signed certificate |
| `neo4j+ssc://` | your cluster, with routing | TLS, self-signed certificate |
| `bolt://` | one single server | none |
| `bolt+s://` | one single server | TLS, CA-signed certificate |
| `bolt+ssc://` | one single server | TLS, self-signed certificate |

- **Use a `neo4j` scheme unless you have a reason not to.** The driver asks the server for a routing table and sends each query to an instance that can serve it. Neo4j Aura requires it: always use the `neo4j+s://` URL shown on the instance's details page. Any cluster should use it too.
- **A `bolt` scheme reaches exactly one server and never routes.** It fits a single-instance Neo4j, and a database reached through a tunnel, a port-forward or a bastion host where the addresses a cluster advertises are not reachable from outside.
- **Do not use `bolt` against a cluster or against Aura.** In Neo4j 5 a database need not be hosted on every server, and Aura serves its databases behind one endpoint that expects routing. When the single server you reach does not host your database's leader, operations fail, often intermittently: the same URL works once and fails the next time. When a connection check fails on a `bolt` URL, the platform adds this hint to the failure: `The failure may be caused by the bolt scheme, which connects to a single server and does not route. Clusters and Aura instances have to be accessed through the neo4j(+s) schemes instead.` Switching to the matching `neo4j` scheme, `neo4j+s://` instead of `bolt+s://`, resolves it.

A project on a customer-hosted database, created through the Config API with Service Account credentials:

```json
POST /configs/v1/projects
Authorization: Bearer <service-account-token>
{
  "organization_id": "gid:AAAABbbbCCCC...",
  "name": "project-name",
  "display_name": "Project name",
  "region": "europe-west1",
  "db_connection": {
    "url": "neo4j+s://xxxxxxxx.databases.neo4j.io",
    "username": "neo4j",
    "password": "example-password",
    "name": "neo4j"
  }
}
```

Resource [environment-1](/resources/environment-1) shows the complete project setup. For a first try, a free Neo4j Aura instance from the [Neo4j Aura Console](https://console.neo4j.io) satisfies the requirements, with the limitation on change data capture noted above.

# Summary: Why graphs for IndyKite?

The graph database is essential to IndyKite because:

| Requirement | Why Graphs Deliver |
| --- | --- |
| **Identity relationships** | Users, groups, roles, resources are naturally connected |
| **Authorization decisions** | Access depends on relationship paths, not table rows |
| **Real-time evaluation** | Traverse current state, not cached permissions |
| **Policy flexibility** | Express rules as graph patterns (Cypher) |
| **Performance at scale** | Millions of traversals per second, consistent latency |
| **Schema evolution** | Add new identity types without migrations |
| **Context awareness** | Attributes on nodes and relationships inform decisions |
| **Auditability** | Clear paths show why access was granted or denied |

# Next Steps

- **Environment setup**: [Environment Guide](https://developer.indykite.com/guides/guide-environment)
- **Capture data**: [Developer Hub Resources](https://developer.indykite.com/resources)
- **KBAC policies**: [Dynamic Authorization Guide](https://developer.indykite.com/guides/guide-dynamic-authz)
- **CIQ queries**: [ContX IQ Guide](https://developer.indykite.com/guides/guide-contx-iq)
- **AuthZEN**: [AuthZEN Guide](https://developer.indykite.com/guides/guide-authzen)
- **Terraform**: [Terraform Guide](https://developer.indykite.com/guides/guide-terraform)
- **Neo4j documentation**: [Neo4j Getting Started](https://neo4j.com/docs/getting-started/)
- **Cypher reference**: [Cypher Manual](https://neo4j.com/docs/cypher-manual/current/)

---

Source: https://developer.indykite.com/guides/guide-graph-database