---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ydb.tech/docs/en/recipes/transfer/quickstart.md?version=v26.1
  - https://ydb.tech/docs/ru/recipes/transfer/quickstart.md?version=v26.1
  - href: en/recipes/transfer/quickstart.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
sourcePath: en/core/recipes/transfer/quickstart.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Transfer — quick start

This guide helps you get started with [transfer](https://ydb.tech/docs/en/concepts/transfer.md?version=v26.1) in YDB using a basic example.

This guide covers the following steps for working with transfers:

* [creating a topic](#step1), for the transfer to read from;
* [creating a table](#step2), for the transfer to write data to;
* [creating the transfer](#step3);
* [populating the topic with data](#step4);
* [verifying the table contents](#step5).

## Step 1. Create a topic {#step1}

First, you need to create a [topic](https://ydb.tech/docs/en/concepts/datamodel/topic.md?version=v26.1) in YDB that the transfer will read data from. You can do this using a [YQL query](https://ydb.tech/docs/en/yql/reference/syntax/create-topic.md?version=v26.1):

```yql
CREATE TOPIC `transfer_recipe/source_topic`;
```

The `transfer_recipe/source_topic` topic lets you transfer any unstructured data.

## Step 2. Create a table {#step2}

After creating the topic, you need to create a [table](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v26.1) that will receive data from the `source_topic` topic. You can do this using a [YQL query](https://ydb.tech/docs/en/yql/reference/syntax/create_table/index.md?version=v26.1):

```yql
CREATE TABLE `transfer_recipe/target_table` (
  partition Uint32 NOT NULL,
  offset Uint64 NOT NULL,
  data String,
  PRIMARY KEY (partition, offset)
);
```

The `transfer_recipe/target_table` table has three columns:

* `partition` — the ID of the topic [partition](https://ydb.tech/docs/en/concepts/glossary.md?version=v26.1#partition) the message was received from;
* `offset` — [the sequence number](https://ydb.tech/docs/en/concepts/glossary.md?version=v26.1#offset) that identifies the message within its partition;
* `data` — the message body.

## Step 3. Create a transfer {#step3}

After creating the topic and the table, you need to create a data [transfer](https://ydb.tech/docs/en/concepts/transfer.md?version=v26.1) that will move messages from the topic to the table. You can do this using a [YQL query](https://ydb.tech/docs/en/yql/reference/syntax/create-transfer.md?version=v26.1):

```yql
$transformation_lambda = ($msg) -> {
    return [
        <|
            partition: $msg._partition,
            offset: $msg._offset,
            data: $msg._data
        |>
    ];
};

CREATE TRANSFER `transfer_recipe/example_transfer`
  FROM `transfer_recipe/source_topic` TO `transfer_recipe/target_table`
  USING $transformation_lambda;
```

In this example:

* `$transformation_lambda` - a transformation rule for converting a topic message into table columns. In this case, the topic message is transferred to the table without any changes. To learn more about configuring transformation rules, see the [documentation](https://ydb.tech/docs/en/yql/reference/syntax/create-transfer.md?version=v26.1#lambda);
* `$msg` - a variable that contains the topic message being processed.


## Step 4. Populate the topic with data {#step4}

After creating the transfer, you can write messages to the topic, for example, using the [YDB CLI](https://ydb.tech/docs/en/reference/ydb-cli/index.md?version=v26.1).

<!-- source: en/_includes/ydb-cli-profile.md -->
{% note info %}

The examples use the `quickstart` profile. To learn more, see [Creating a profile to connect to a test database](https://ydb.tech/docs/en/reference/ydb-cli/profile/create.md?version=v26.1#quickstart).

{% endnote %}
<!-- endsource: en/_includes/ydb-cli-profile.md -->

```bash
echo "Message 1" | ydb --profile quickstart topic write 'transfer_recipe/source_topic'
echo "Message 2" | ydb --profile quickstart topic write 'transfer_recipe/source_topic'
echo "Message 3" | ydb --profile quickstart topic write 'transfer_recipe/source_topic'
```

## Step 5. Verify the table contents {#step5}

After writing messages to the `source_topic` topic, records will appear in the `transfer_recipe/target_table` table after a short delay. You can verify this using a [YQL query](https://ydb.tech/docs/en/yql/reference/syntax/select/index.md?version=v26.1):

```yql
SELECT *
FROM `transfer_recipe/target_table`;
```

Query result:

| partition | offset | data |
|-----------|--------|------|
| 0         | 0      | Message 1 |
| 0         | 1      | Message 2 |
| 0         | 2      | Message 3 |

<!-- source: en/recipes/transfer/_includes/batching.md -->
Rows are not added to the table for each message received from the topic; instead, they are buffered and inserted in batches. By default, data is written to the table every 60 seconds or when the volume of accumulated data reaches 8 MB. These parameters can be explicitly configured when [creating](https://ydb.tech/docs/en/yql/reference/syntax/create-transfer.md?version=v26.1) a transfer or [modified](https://ydb.tech/docs/en/yql/reference/syntax/alter-transfer.md?version=v26.1) later.
<!-- endsource: en/recipes/transfer/_includes/batching.md -->

## Conclusion

This guide provides a basic example of working with a transfer: creating a topic, table, and transfer, writing data to the topic, and verifying the result.

These examples are designed to illustrate the syntax for working with transfers. For a more realistic example, see the [article](https://ydb.tech/docs/en/recipes/transfer/nginx.md?version=v26.1) that describes how to stream NGINX access logs.

## See Also

* [Data transfer](https://ydb.tech/docs/en/concepts/transfer.md?version=v26.1)
* [Transfer — streaming NGINX access logs to a table](https://ydb.tech/docs/en/recipes/transfer/nginx.md?version=v26.1)
