# Data Residency & Composite Databases

> Control where your Identity Knowledge Graph data lives: regions, replicas, routing data to specific locations with a composite database, and location-aware authorization with 3.0-kbac policies.

**Category:** Environment

## Summary

Choose the region your IKG runs in, add a read replica in a second region, route individual nodes to specific locations with a customer-hosted composite database, and run location-aware AuthZEN authorization with 3.0-kbac policies.

## Content

# What is Data Residency?

Data residency controls **where your Identity Knowledge Graph (IKG) physically lives**. Every IndyKite project is created in a region, and that region determines where your graph data is stored and processed.

This matters when your data is subject to regulatory requirements (for example GDPR or sector-specific rules that mandate in-region storage), or when you want the IKG close to your users for latency reasons.

### Which residency settings does a project have?

| Field | Description | Values |
| --- | --- | --- |
| `region` | Region where the project's IKG is provisioned. Required at creation, cannot be changed afterwards. | Depends on your environment, for example `europe-west1`, `us-east1` |
| `ikg_size` | Storage size of the IKG instance; each size comes with a corresponding CPU allocation. | Depends on your environment, for example `2GB`, `4GB`, `8GB`, `16GB`, `32GB`, `64GB`, `128GB`, `192GB`, `256GB`, `384GB`, `512GB` |
| `replica_region` | Optional second region that receives a synchronized read replica of the IKG. | Depends on your environment, for example `europe-west1`, `us-east1`, `us-west1` |
| `ikg_schema_version` | Optional schema version of the IKG. Defaults to `v1` when omitted and cannot be changed after the project is created. `v2` is not supported yet: sending it is refused with `422` and `unsupported ikg_schema_version: only V1 can be set`. The differences between the two versions are in the [Token Introspect guide](/guides/guide-token-introspect#schema-versions). | `v1`, `v2` |
| `ikg_status` | Provisioning state of the IKG (read-only, returned on reads). | `PENDING`, `ACTIVE`, `FAILED`, `PAUSED` |

### How do replicas work?

Setting `replica_region` provisions a **second IKG in another region** that is continuously populated from the primary by change-data-capture replication.

- The replica must be in a **different region than the primary**, but on the **same geographical continent**.
- The replica is **read-only**: it is served through a read-only database user and cannot accept writes.
- Replication is one-way, from the primary region to the replica region.
- Use it for in-region read access (queries, authorization decisions) close to users in a second geography.

# What is a Composite Database?

A region places your *whole* IKG in one location. A **composite database** goes further: it lets **one logical IKG span multiple physical databases**, so that individual nodes can be stored in a specific location: for example, EU customer records in an EU database and US customer records in a US database, while your applications keep talking to a single graph.

A composite IKG is made of **constituent databases**:

| Constituent | What it stores |
| --- | --- |
| **Global database** | The nodes whose location is `global`. A lightweight *proxy node* (external ID, type, and location only: no property data) for every node of another location that was upserted with `create_proxy: true`. The relationships that connect nodes of different locations and, for an endpoint of such a relationship that has no proxy, a bare node with its external ID and type. |
| **Location databases** | The full node data for each logical location (for example `east`, `west`), and the relationships between two nodes of that same location. |
| **Default database** | Nodes ingested *without* a location, and the relationships between two such nodes: they follow the same path as a regular, non-composite IKG. |

Two settings on the project's database connection wire this together:

- `composite_db_name`: the name of the composite database. Leave it empty for a regular single-database IKG.
- `alias_mapping`: a URL-query-encoded map from **logical location names to constituent databases**, for example `global=db1&east=db2&west=db3`. The location names on the left are the values you will later put in the `location` field of Capture API requests.

### When should I use a composite database?

- You must keep certain nodes' data in a specific jurisdiction, but still need one connected graph across all of them (cross-location relationships, single authorization model).
- You want per-record placement decisions (this person's data stays in the EU) rather than a per-project region choice.

**Availability:** composite databases are supported for **customer-hosted** IKGs only: you run your own Neo4j deployment and IndyKite connects to it (requirements and connection URL schemes in the [Graph Database guide](/guides/guide-graph-database#customer-hosted)). IndyKite-managed projects use a regular single-database IKG in the project's region.

# How do I create a project with residency settings?

Residency is set on the [Config API](https://openapi.indykite.com/api-documentation-config) when creating a project. Authenticate with your Service Account token (see the [credentials guide](https://developer.indykite.com/guides/guide-credentials)).

POST /configs/v1/projects

```json
{
  "name": "my-project",
  "display_name": "My Project",
  "organization_id": "gid:your-organization-id",
  "region": "us-east1",
  "ikg_size": "2GB",
  "replica_region": "us-west1"
}
```

With header `Authorization: Bearer <service-account-token>`.

Provisioning is **asynchronous**: the response returns immediately, while the IKG is created in the background. Poll the project until it is ready:

GET /configs/v1/projects/{id}

```json
{
  "id": "gid:your-project-id",
  "region": "us-east1",
  "ikg_size": "2GB",
  "replica_region": "us-west1",
  "ikg_schema_version": "v1",
  "ikg_status": "ACTIVE"
}
```

Wait for `ikg_status` to become `ACTIVE` before ingesting data. `PENDING` means provisioning is still running; `FAILED` means it did not complete.

# How do I set up a composite database?

### Step 1: Create the databases in your Neo4j deployment

The composite database and its constituents must exist **before** you create the project. IndyKite connects to them and configures routing; it does not create the databases for you. On your Neo4j instance:

```text

CREATE DATABASE db1 IF NOT EXISTS;
CREATE DATABASE db2 IF NOT EXISTS;
CREATE DATABASE db3 IF NOT EXISTS;
CREATE COMPOSITE DATABASE ikcomposite IF NOT EXISTS;
CREATE ALIAS ikcomposite.db1 FOR DATABASE db1;
CREATE ALIAS ikcomposite.db2 FOR DATABASE db2;
CREATE ALIAS ikcomposite.db3 FOR DATABASE db3;
```

In a real deployment the constituent databases typically live on servers in different locations; the composite database presents them as one graph.

### Step 2: Create the project with the composite connection

POST /configs/v1/projects

```json
{
  "name": "my-project",
  "display_name": "My Project",
  "organization_id": "gid:your-organization-id",
  "region": "europe-west1",
  "db_connection": {
    "url": "neo4j://your-neo4j-host:7687",
    "username": "neo4j",
    "password": "<your-password>",
    "name": "db1",
    "composite_db_name": "ikcomposite",
    "alias_mapping": "global=db1&east=db2&west=db3"
  }
}
```

| db_connection field | Meaning |
| --- | --- |
| `url`, `username`, `password` | Connection to your Neo4j deployment (required). |
| `name` | The default constituent database: used for operations that carry no `location`. |
| `composite_db_name` | Name of the composite database created in Step 1. Empty means a regular IKG. |
| `alias_mapping` | Location-to-constituent map. By convention, map the `global` location to the constituent that should hold proxy nodes and cross-location relationships. |

### Step 3: Wait for the IKG to become active

As with any project, poll `GET /configs/v1/projects/{id}` until `ikg_status` is `ACTIVE`. The response echoes `db_connection.composite_db_name` and `db_connection.alias_mapping` so you can verify the configuration round-trips.

### Can I change the composite configuration of an existing project?

Yes, with an update (subject to a few rules):

PUT /configs/v1/projects/{id}

```json
{
  "db_connection": {
    "url": "neo4j://your-neo4j-host:7687",
    "username": "neo4j",
    "password": "<your-password>",
    "name": "db1",
    "composite_db_name": "ikcomposite",
    "alias_mapping": "global=db1&east=db2&west=db3"
  }
}
```

- Optionally send an `If-Match: "<etag>"` header (from a previous read) to guard against concurrent updates.
- `db_connection` can only be updated on **customer-hosted** projects; on IndyKite-managed projects it is rejected. Omitting `db_connection` leaves the existing connection untouched.
- The databases referenced by the new mapping must already exist in Neo4j. The update rewires configuration and routing: it does **not** migrate existing data between constituent databases.
- The hosting type itself cannot change: an IndyKite-managed project cannot be turned into a composite one. Composite requires customer-hosted from creation.
- The update is applied asynchronously: poll `ikg_status` as for creation.

# How do I ingest data with locations?

On a composite IKG, the [Capture API](https://openapi.indykite.com/) routes data by location. Authenticate with your Application Agent key: `X-IK-ClientKey: <token-from-credentials-file>`.

- **Nodes** are routed *per node* with an optional `location` field (2–32 characters, must be a key of the project's `alias_mapping`). A located node gets a proxy in the global constituent only when it also sets `create_proxy`.
- **Relationships** are routed *per relationship* by the `location` of their source and target nodes: two nodes of the same location keep the relationship in that location's constituent, and nodes of different locations put it in the global constituent.

### Regular IKG or composite IKG: what differs?

The Capture API has one set of endpoints for every IKG. What a request does depends on one thing: **whether any node in it carries a `location`**.

|  | **Regular IKG** (no `location` in the request) | **Composite IKG** (at least one `location` in the request) |
| --- | --- | --- |
| **Who can use it** | Every project. | Only a project with a composite database configured (`composite_db_name` and `alias_mapping`). |
| **Where a node is written** | The project's one database. | The database of the node's `location`. A node without a `location` goes to the default database. |
| **Where a relationship is written** | The project's one database. | Chosen from the `location` of its source and target nodes: the same location on both, that location's database; different locations, the global database; no location on either, the default database. |
| **`create_proxy` on a node** | Ignored. | `true` also writes a proxy of the node (external ID, type and location, no properties) to the global database. Without it, no proxy is written. |
| **Response** | `{"results": [{"id": "gid:…"}]}`, one entry per item, in request order. | An object with one key per location and, as value, the list of GIDs written or deleted there: `{"east": ["gid:…"], "global": ["gid:…"]}`. |
| **`use_global_db`** | Removed, for both. A request that sets `"use_global_db": true` is refused with `400`. |  |

A request without any `location` behaves the same on both kinds of project, so existing ingestion keeps working unchanged on a regular IKG. Everything below this point applies to a composite IKG only.

### Upsert nodes with per-node locations

Each node may carry two optional fields:

| Field | Meaning |
| --- | --- |
| `location` | 2–32 characters, a key of the project's `alias_mapping`. The node, with all its properties, is written to the database of that location. Without it, the node goes to the default database. The name `__default` is reserved and cannot be used as a location. |
| `create_proxy` | Boolean, default `false`. `true` asks for a **proxy** of the node in the global database: a node with the same external ID and type and with the location, and no properties. Ignored for a node whose location is `global`, which is in the global database already, and in a request where no node has a location. |

POST /capture/v1/nodes

```json
{
  "nodes": [
    {
      "external_id": "person-alice",
      "type": "Person",
      "is_identity": true,
      "location": "east",
      "create_proxy": true,
      "properties": [
        {
          "type": "name",
          "value": "Alice Marchetti"
        },
        {
          "type": "email",
          "value": "alice@example.com"
        }
      ]
    },
    {
      "external_id": "person-karel",
      "type": "Person",
      "is_identity": true,
      "location": "west",
      "properties": [
        {
          "type": "name",
          "value": "Karel Plihal"
        }
      ]
    },
    {
      "external_id": "car-kitt",
      "type": "Car",
      "is_identity": false,
      "properties": [
        {
          "type": "manufacturer",
          "value": "Pontiac"
        }
      ]
    }
  ]
}
```

What happens:

- The full `person-alice` node is stored in the `east` constituent. Because it sets `create_proxy`, a **proxy node** (external ID, type, and location, no properties) is also written to the global constituent.
- The full `person-karel` node is stored in `west`. It does not set `create_proxy`, so the global constituent holds nothing about it.
- `car-kitt` has no `location`, so it goes to the default database, exactly as on a non-composite IKG.

Because the request carries locations, the response is not the usual `results` array. It lists the node GIDs per location, in request order within each list. Nodes without a location are under the key `__default`; proxies are under `global`, after the GIDs of the nodes that live in `global`:

```json
{
  "east": ["gid:AAAA…"],
  "west": ["gid:BBBB…"],
  "__default": ["gid:CCCC…"],
  "global": ["gid:DDDD…"]
}
```

Here `global` holds one GID: the proxy of `person-alice`.

### When do I need a proxy?

A proxy makes a located node present in the global database **with its location**, without copying any of its property data out of its jurisdiction. Ask for one when the node takes part in a relationship with a node of another location, since such relationships live in the global database (next section). A node that is only related to nodes of its own location needs none.

Upsert the node with `create_proxy` **before** its relationships. A relationship written to the global database creates any source or target node missing there, but with the external ID and type only: such a node has no location.

### Upsert relationships: the node locations choose the database

A relationship request carries no routing field of its own. Give each source and target node the `location` it was upserted with, and the platform writes each relationship to exactly one database:

| Source and target | The relationship is written to | Response key |
| --- | --- | --- |
| Same `location` on both, for example `west` and `west` | The database of that location. | `west` |
| Different locations, for example `east` and `west`, `east` and `global`, or `east` and none | The global database. | `global` |
| No `location` on either | The default database. | `__default`, when another relationship of the request carries a location. When none does, the response has the regular `results` shape. |

POST /capture/v1/relationships

```json
{
  "relationships": [
    {
      "source": {
        "external_id": "person-alice",
        "type": "Person",
        "location": "east"
      },
      "target": {
        "external_id": "car-kitt",
        "type": "Car"
      },
      "type": "OWNS",
      "properties": [
        {
          "type": "status",
          "value": "active"
        }
      ]
    },
    {
      "source": {
        "external_id": "person-alice",
        "type": "Person",
        "location": "east"
      },
      "target": {
        "external_id": "person-karel",
        "type": "Person",
        "location": "west"
      },
      "type": "KNOWS"
    }
  ]
}
```

Both relationships connect nodes of different locations (`east` and none, `east` and `west`), so both are written to the global constituent, and the response lists them under `global`:

```json
{
  "global": ["gid:EEEE…", "gid:FFFF…"]
}
```

In the global constituent, `OWNS` and `KNOWS` start at the proxy of `person-alice`, which the node request above created. `person-karel` has no proxy there, so the request creates it in the global constituent with its external ID and type only, without a location and without properties. To have `person-karel` there with its location, upsert it with `create_proxy` first. `car-kitt` is a different case: it was upserted without a location, so it is in the default database, and in this guide's setup the default database and the `global` location are the same database (`db1`). The relationship therefore reuses the existing `car-kitt` node, with its properties. With a default database other than the global one, `car-kitt` would be created in the global constituent like `person-karel`.

A source or target node missing in the database of a relationship is created there the same way in every case: external ID and type only.

### Which delete operations are location-aware?

All Capture API delete endpoints find their target the way the upsert placed it:

| Endpoint | Routing field | What the response lists per location |
| --- | --- | --- |
| `POST /capture/v1/nodes/delete` | `location` per node. The node's proxy, if it has one, is deleted from the global database too. | The GIDs of the nodes deleted there; proxies under `global`. |
| `POST /capture/v1/nodes/properties/delete` | `location` per node | The GIDs of the nodes found there. |
| `POST /capture/v1/nodes/properties/metadata/delete` | `location` per node | The GIDs returned there. |
| `POST /capture/v1/relationships/delete` | `location` of the source and target nodes, by the same rule as the upsert | The GIDs of the relationships deleted there. |
| `POST /capture/v1/relationships/properties/delete` | `location` of the source and target nodes, by the same rule as the upsert | The GIDs of the relationships found there. |

Send the same locations you sent on the upsert: a relationship written to `global` because its nodes were in `east` and `west` is found again only with `east` and `west` on its nodes. Something that is not found has no GID in the response, and a location of the request where nothing was found is still listed, with an empty list.

Example: deleting nodes across locations (deleting a located node removes its data node in the location constituent and, if it has one, its proxy in the global database):

POST /capture/v1/nodes/delete

```json
{
  "nodes": [
    {
      "external_id": "person-alice",
      "type": "Person",
      "location": "east"
    },
    {
      "external_id": "person-karel",
      "type": "Person",
      "location": "west"
    },
    {
      "external_id": "car-kitt",
      "type": "Car"
    }
  ]
}
```

The response lists what was deleted in each location:

```json
{
  "east": ["gid:AAAA…"],
  "west": ["gid:BBBB…"],
  "__default": ["gid:CCCC…"],
  "global": ["gid:DDDD…"]
}
```

`person-alice` is deleted from `east` and its proxy from `global`; `person-karel` had no proxy, and its GID still comes back from `west`.

When nothing is found, for example a delete of the two relationships of the previous section sent a second time, every location of the request is still listed, with no GID:

```json
{
  "global": []
}
```

### What happens if the location is wrong?

A request that fails writes nothing.

| Situation | Applies to | Result |
| --- | --- | --- |
| A `location` that is not a key in the project's `alias_mapping`, on a node or on the source or target of a relationship. Every location is checked, also when the relationship would go to the global database. | Composite IKG | `422`, `invalid locations: "eastB"` |
| `__default` used as a `location` | Composite IKG | `422`, `location __default is reserved and cannot be used` |
| `"use_global_db": true` on a relationship upsert, relationship delete or relationship property delete | Regular and composite IKG | `400`, `use_global_db is removed: set the location of the source and target nodes instead` |
| A `location` on a project with no composite database configured | Regular IKG | Request fails: composite database not configured |
| No `location` at all | Regular and composite IKG | Not an error: the data goes to the default database, and the response has the regular `results` shape |

### Moving a client off use_global_db

1. Remove `use_global_db` from every relationship request. `false` is accepted; `true` is refused.
2. Add the `location` of each source and target node to the relationship requests, upserts and deletes alike.
3. Add `"create_proxy": true` to the located nodes that take part in relationships across locations, and upsert them before those relationships.
4. Read the response by location: an object of GID lists, in place of `results`, whenever the request carries a location.

# How do queries and authorization work on a composite IKG?

Reads do **not** fan out across constituent databases by default. ContX IQ queries (`POST /contx-iq/v1/execute`) and KBAC / AuthZEN authorization checks with `2.0-kbac` policies (`POST /access/v1/*`) execute against the **default constituent database only**: the one named by `db_connection.name`.

- **Point the default at the global constituent** (as in this guide's examples, where `name` is the database mapped to `global`). Authorization decisions that depend on graph *structure* keep working for what is stored there: the nodes located in `global`, the proxy nodes created with `create_proxy`, and the cross-location relationships.
- **Relationships stored outside the default constituent are out of read scope.** A relationship between two nodes of the same location is stored in that location's constituent. When that is not the default constituent, a decision that depends on it needs a `3.0-kbac` policy routed to that location. A relationship between two nodes located in `global` stays visible when the default is the global constituent.
- **Property data stored outside the default constituent is out of read scope.** A node of another location is present in the global constituent only as a proxy, and only when it was upserted with `create_proxy`; a node located in `global` keeps its full properties there. Proxy nodes carry only external ID, type, and location: the full properties stored in a location constituent (for example a person's email in `east`) are not returned by queries and cannot be referenced in policy conditions running against the default database.
- **CIQ and `2.0-kbac` policy Cypher cannot route to a constituent.** A `USE` clause or a `CALL { }` subquery is rejected when the policy is created (see the [CIQ Cypher guide](https://developer.indykite.com/guides/guide-ciq-cypher)).
- **To make authorization decisions against a location constituent**, author the policy as `3.0-kbac`: the next section shows how.

# How does authorization work with data residency? (3.0-kbac)

The `3.0-kbac` policy version makes KBAC / AuthZEN authorization **location-aware**. Where the platform rewrites a `2.0-kbac` condition and always runs it against the default database, a `3.0-kbac` condition is **raw Cypher**: it runs as you wrote it, and you author the composite-database routing yourself with `USE graph.byName(...)`. Residency support is **opt-in per policy**: existing `2.0-kbac` policies are unchanged. Note that `3.0-kbac` itself does not require a composite database - only `USE` routing does; a `3.0-kbac` policy without a `USE` clause evaluates against the default database as plain raw Cypher.

Routing can be:

- **Static**: `USE graph.byName('ikcomposite.db2')`: always evaluates in that constituent.
- **Dynamic**: `USE graph.byName($region)`: `$region` becomes a **location parameter**. The caller passes a *logical location* (a key of the project's `alias_mapping`, for example `"east"`) in the AuthZEN request's `context.input_params`, and IndyKite translates it to the physical constituent just before execution. Callers never see or supply physical database names.

### Example: a location-routed policy

Create the policy on the [Config API](https://openapi.indykite.com/api-documentation-config) (`POST /configs/v1/authorization-policies`) like any other KBAC policy; only the policy JSON differs:

```json
{
  "meta": {
    "policy_version": "3.0-kbac"
  },
  "subject": {
    "type": "Person"
  },
  "actions": [
    "CAN_DRIVE"
  ],
  "resource": {
    "type": "Car"
  },
  "condition": {
    "cypher": "USE graph.byName($region) MATCH (subject:Person)-[:OWNS]->(resource:Car)"
  }
}
```

Then evaluate with a location in `context.input_params`:

POST /access/v1/evaluation

```json
{
  "subject": {
    "type": "Person",
    "id": "person-alice"
  },
  "action": {
    "name": "CAN_DRIVE"
  },
  "resource": {
    "type": "Car",
    "id": "car-kitt"
  },
  "context": {
    "input_params": {
      "region": "east"
    }
  }
}
```

`"east"` is the logical location from `alias_mapping`, not a Neo4j database name. The same pattern works on all AuthZEN endpoints: single evaluation, batch evaluations, and the three search endpoints.

### What can 3.0-kbac Cypher do that 2.0-kbac cannot?

- `USE graph.byName(...)` clauses, top-level or per `CALL { }` subquery, so one condition can combine matches from several constituents.
- `CALL { }` subqueries with inner `RETURN`s (both rejected in `2.0-kbac`).
- Mutating clauses (`CREATE`, `MERGE`, `SET`, `DELETE`, and so on) remain blocked, as does a top-level `RETURN`: the platform appends the projection itself.

### Authoring rules for 3.0-kbac

- The condition must still bind `subject` and `resource` variables; the platform pins them by type and external ID and replaces the final projection.
- The `graph.byName()` argument must be a **string literal or a single parameter**: expressions like `coalesce($region, 'eu')` are rejected at creation.
- A routing parameter **cannot be referenced anywhere else** in the Cypher: its value is rewritten to the physical alias at request time.
- `$subject_external_id`, `$subject_type`, `$resource_external_id`, and `$resource_type` are bound by the platform: never supply them in `input_params` or use them as routing parameters.
- `$subject_id` must not be referenced at all: on a composite IKG the same logical subject has a different internal node ID per location, so it is rejected at creation.
- External (resolver-backed) properties cannot be used in the condition: creation fails with `external properties cannot be used in data-residency policies`. They are supported only in `2.0-kbac` conditions.
- The subject does not need to be an identity node: `3.0-kbac` matches it by type and external ID (`2.0-kbac` requires a subject ingested with `is_identity: true`). With a bearer token on the request, the token's subject must match the requested subject.

### What happens if the location is wrong at decision time?

| Situation | Result |
| --- | --- |
| Required location parameter missing from `context.input_params`, or not a non-empty string | `422 Unprocessable Entity` |
| Location is not a key of the project's `alias_mapping` | `422 Unprocessable Entity` (unknown location) |
| Policy routes with `USE` (static or via a location parameter) but the project has no composite database | `422 Unprocessable Entity` (requires a composite database) |
| Bearer-token call where the token's subject differs from the requested subject | `403 Forbidden` (permission denied) |

See the [AuthZEN guide](https://developer.indykite.com/guides/guide-authzen) for the full request shape, and the `authz-7` / `authz-8` resources for end-to-end examples.

# Related resources

- [Credentials guide](https://developer.indykite.com/guides/guide-credentials): Service Account tokens (Config API) vs Application Agent keys (Capture API)
- [AuthZEN guide](https://developer.indykite.com/guides/guide-authzen): request shape, batch evaluations, and location parameters
- [Why use a Graph Database?](https://developer.indykite.com/guides/guide-graph-database): IKG fundamentals
- [Config API reference](https://openapi.indykite.com/api-documentation-config) and [Capture API reference](https://openapi.indykite.com/)

---

Source: https://developer.indykite.com/guides/guide-data-residency