[Yandex Cloud documentation](../../index.md) > [Yandex Data Streams](../index.md) > [Getting started](index.md) > Debezium Change Data Capture (CDC) stream processing

# Debezium Change Data Capture (CDC) stream processing

[Debezium](https://debezium.io) is a service for capturing database changes (Change Data Capture / CDC) and sending them for processing to other systems. With Yandex Data Streams, you can capture these changes and send them to Cloud Functions.

The following architecture is used in this solution:
![debezium](../../_assets/data-streams/debezium.png)

## Setup {#setup}
To enable a data stream, do the following:
1. [Create](#create_stream) a Yandex Data Streams stream.
1. Configure Yandex Data Streams [connection settings](#credentials).
1. [Set up and launch](#debezium_server) Debezium Server.
1. Set up a Cloud Functions [trigger](#sftrigger) for data processing.

### Creating a data stream {#create_stream}

Create a Yandex Data Streams stream named `debezium`. The data stream creation procedure is detailed in the [Yandex Data Streams documentation](../operations/manage-streams.md).

### Configuring Yandex Data Streams connection settings {#credentials}

1. Log in to the [management console](https://console.yandex.cloud). If not signed up yet, navigate to the management console and follow the on-screen instructions.
1. On the [**Yandex Cloud Billing**](https://center.yandex.cloud/billing/accounts) page, make sure you have a linked [billing account](../../billing/concepts/billing-account.md) and its status is `ACTIVE` or `TRIAL_ACTIVE`. If you do not have a billing account yet, [create one](../../billing/quickstart/index.md#create_billing_account).
1. If you do not have a folder yet, [create one](../../resource-manager/operations/folder/create.md).
1. [Create](../../iam/operations/sa/create.md) a service account and [assign](../../iam/operations/sa/assign-role-for-sa.md) it the `editor` role for your folder.
1. [Create](../../iam/operations/authentication/manage-access-keys.md#create-access-key) a static access key.
1. Configure the AWS CLI:
    1. Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) and run this command:

        ```bash
        aws configure
        ```

    1. Enter the following, one by one:

        * `AWS Access Key ID [None]:`: Service account [key ID](../../iam/concepts/authorization/access-key.md).
        * `AWS Secret Access Key [None]:`: Service account [secret key](../../iam/concepts/authorization/access-key.md).
        * `Default region name [None]:`: `ru-central1` availability zone.

### Setting up Debezium Server {#debezium_server}

In our example, we will show how Debezium interacts with PostgreSQL. For this setup, Debezium will be installed on the server already running PostgreSQL.

1. Install the Debezium Server using [this guide](https://debezium.io/documentation/reference/stable/operations/debezium-server.html).
1. Go to the `conf` folder and create a file named `application.properties` with the following contents:

    ```text
    debezium.sink.type=kinesis
    debezium.sink.kinesis.region=ru-central1
    debezium.sink.kinesis.endpoint=<endpoint>
    debezium.source.connector.class=io.debezium.connector.postgresql.PostgresConnector
    debezium.source.offset.storage.file.filename=data/offsets.dat
    debezium.source.offset.flush.interval.ms=0
    debezium.source.database.hostname=localhost
    debezium.source.database.port=5432
    debezium.source.database.user=<user_name>
    debezium.source.database.password=<user_password>
    debezium.source.database.dbname=<DB_name>
    debezium.source.database.server.name=debezium
    debezium.source.plugin.name=pgoutput

    debezium.source.transforms=Reroute
    debezium.source.transforms.Reroute.type=io.debezium.transforms.ByLogicalTableRouter
    debezium.source.transforms.Reroute.topic.regex=(.*)
    debezium.source.transforms.Reroute.topic.replacement=<data_stream>
    ```

    Where:

    * `<endpoint>`: Endpoint for a Data Streams data stream, e.g., `https://yds.serverless.yandexcloud.net/ru-central1/b1g89ae43m6he********/etn01eg4rn1********`. You can see the endpoint on the stream page (see [Viewing a list of streams](../operations/manage-streams.md#list-data-streams)).
    * `<data_stream>`: Data Streams data stream name.
    * `<DB_name>`: PostgreSQL database name.
    * `<user_name>`: User name for connecting to the PostgreSQL database.
    * `<user_password>`: User password for connecting to the PostgreSQL database.
1. Run Debezium using this command:

    ```bash
    JAVA_OPTS=-Daws.cborEnabled=false ./run.sh
    ```

1. Make some changes to the PostgreSQL database, e.g., insert data into a table.
1. If the settings are correct, the Debezium console will show messages like:

    ```text
    2022-02-11 07:31:12,850 INFO  [io.deb.con.com.BaseSourceTask] (pool-7-thread-1) 1 records sent during previous 00:19:59.999, last recorded offset: {transaction_id=null, lsn_proc=23576408, lsn_commit=23576120, lsn=23576408, txId=580, ts_usec=1644564672582666}
    ```

## Setting up a Cloud Functions trigger {#sftrigger}

Create a Cloud Functions trigger for the `debezium` stream you previously created in Yandex Data Streams. 

The trigger creation procedure is detailed in [Cloud Functions documentation](../../functions/concepts/trigger/data-streams-trigger.md).

This trigger will be used by Cloud Functions, receiving notifications about any database changes. You can then process these changes by implementing the required business logic in the trigger code.