> For the complete documentation index, see [llms.txt](https://docs.elimity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elimity.com/technical-guides/gateways-and-import-agents/how-imports-are-split.md).

# How imports are split

How gateways split one import into many short requests, and how to set requestTimeoutSeconds and parallel for the platform you run them on.

Some gateways import a large source system in many short requests instead of one long one. Every request does part of the work and passes the rest on to the next request in a **cursor**. This keeps every request within the limits of the platform the gateway runs on, and keeps memory use flat however large the source system is.

These gateways need **SDK version 2** in the custom gateway configuration of the source. Each gateway's documentation says whether it works this way.

## How it works

```mermaid
graph LR
    D[First request: directory] --> C1[Chain 1: part 1] --> C1b[part 2] --> C1c[...]
    D --> C2[Chain 2: part 1] --> C2b[part 2] --> C2c[...]
    D --> Cn[Chain n: part 1] --> Cnb[...]
```

1. **The first request** collects everything that is shared by the whole import, such as users and groups, and splits the remaining work into **chains** of items.
2. **Each chain** is worked through by a series of requests, the **parts**. A part works on several items at once and, when its time is up, hands the items it did not get to on to the next part of its chain.
3. **Chains run side by side**: Elimity Insights keeps one request open per chain. How many chains there are is set with `parallel`.

Every part sends a line to the source's logs when it starts, a line saying it is still working whenever it has nothing else to send for two minutes, and a summary at the end. Proxies and ingresses that cut connections that stay silent for a few minutes therefore never see a silent request.

## Configuration values

| Key                     | Required | Description                                                                                      |
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------ |
| `requestTimeoutSeconds` | Yes      | The longest one request to the gateway may take, in seconds. At least `120`; we recommend `600`. |
| `parallel`              | No       | How many chains the import runs as: `false` (default) is one, `true` is eight, or a number.      |

### `requestTimeoutSeconds`

This is a hard limit on every request. A part stops starting new items once the time left is shorter than its items have taken so far, and stops whatever is still running 10 seconds before the limit: what finished is imported, the rest goes to the next part. An item only sends its data once it is complete, so a stopped item never leaves partial data behind.

Set it **below the request limits of the platform the gateway runs on** (see below). If not a single item can finish within the limit, the import fails with an error that names the item, for example:

> No ... finished within the request timeout of 120 s (the first was ...). Raise requestTimeoutSeconds, keeping it within the request limit of the platform the gateway runs on.

{% hint style="info" %}
Why 600 rather than the minimum: source systems can throttle the account Elimity uses, delaying every request once it has used its share for a while. One item can then take several minutes. With a low `requestTimeoutSeconds` parts then finish nothing; with 600 they keep making progress.
{% endhint %}

### `parallel`

#### One chain (`parallel: false`, the default)

The whole import is a single chain. Elimity Insights sends one request at a time, and only sends the next one once the previous one has ended:

```mermaid
graph LR
    D[First request] --> P1[Part 1: up to requestTimeoutSeconds] --> P2[Part 2: up to requestTimeoutSeconds] --> P3[...] --> PN[Last part]
```

* **`requestTimeoutSeconds` decides how many parts the import takes.** Every part works until its limit, or until the items run out, and hands the rest on. An import with about 20 minutes of work runs as 2 parts with `600`, or as about 10 parts with `120`.
* **The total time is the sum of the parts.** A lower limit does not slow the import down by itself, but every part starts by reading its cursor and signing in to the source system again, so many very short parts waste some time.
* **Only one gateway instance is busy at any moment**, and Elimity Insights has only one connection to the gateway open. This suits a gateway on a single fixed machine, or a platform where scaling out is not wanted.
* **The platform's request limits still apply to every part**, so `requestTimeoutSeconds` has to stay within them here too.

#### Several chains (`parallel: true` or a number)

The items are dealt over that many chains, and Elimity Insights works on all chains at the same time, each one part after the other as above. This finishes the import sooner, but only up to a point:

* Chains share the gateway instance they run on. More chains help most when the platform starts extra instances for them (Cloud Run and Azure Container Apps do, when their scaling allows it).
* The source system's own rate limits stay the same. Once those are reached, more chains do not make the import faster.

If one chain takes too long, try `true` (eight chains), and only go higher after measuring.

## Choosing the values per platform

| Platform                            | Set on the platform                                                               | `requestTimeoutSeconds`               |
| ----------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------- |
| **Google Cloud Run**                | Request timeout of the service (up to 3600 s), e.g. `900`                         | Below the request timeout, e.g. `600` |
| **Azure Container Apps**            | Ingress request timeout and `terminationGracePeriodSeconds`, e.g. both 10 minutes | At most both, e.g. `600`              |
| **Behind a proxy or load balancer** | Its total request or response timeout, if it has one                              | Below that timeout                    |

On **Google Cloud Run**, the request timeout counts from when a request arrives, `requestTimeoutSeconds` from when the gateway starts handling it. Starting a new instance can take half a minute, so keep the service's request timeout at least a minute above `requestTimeoutSeconds`.

On **Azure Container Apps**, two settings matter, and both should be in line with `requestTimeoutSeconds`:

* **The ingress request timeout.** The ingress ends a request that has sent nothing for this long (4 minutes on the default ingress; configurable with premium ingress). The parts' still-working lines, at least every two minutes, keep requests within it.
* **`terminationGracePeriodSeconds`.** The platform removes surplus replicas a few minutes after the load drops, and it does not know which ones still have a request open. A replica that is being removed gets `terminationGracePeriodSeconds` to finish (30 seconds by default). With `requestTimeoutSeconds` at most the grace period, every running request can still finish on time.

For example, set all three to 3 minutes (`requestTimeoutSeconds` = `180`), or all three to 10 minutes (`600`).

## Troubleshooting

| Message in the source's logs                                         | Cause and fix                                                                                                                                                             |
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Invalid configuration: requestTimeoutSeconds is required: ...`      | The configuration value is missing. Add `requestTimeoutSeconds` (at least `120`).                                                                                         |
| `requestTimeoutSeconds must be at least 120, not ...`                | Raise the value.                                                                                                                                                          |
| `No ... finished within the request timeout of ... s`                | Not a single item could finish within the limit, usually because the source system is throttling. Raise `requestTimeoutSeconds`, keeping it within the platform's limits. |
| `... stopped at the request timeout of ... s; ... left for part ...` | Not an error: the part reached its limit and the next part continues.                                                                                                     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.elimity.com/technical-guides/gateways-and-import-agents/how-imports-are-split.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
