> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peerdb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# PeerDB Streams for Kafka Quickstart Guide

> Get started with PeerDB Streams for Kafka in a few simple steps.

### Deploying PeerDB

We currently support deploying and testing PeerDB using our Docker Compose file.

<Info>
  {" "}

  Docker can be installed by referring to [these instructions](https://www.docker.com/products/docker-desktop).
  The `docker compose` tool should also be present. The Postgres client tools (specifically
  `psql`) are used to test the PeerDB installation.{" "}
</Info>

**Run the following commands in your terminal:**

```bash theme={null}
git clone --recursive https://github.com/PeerDB-io/peerdb.git
cd peerdb

# Run docker containers: peerdb-server, postgres as catalog, temporal.
# This might take a few minutes, so get a cup of coffee! :)
./run-peerdb.sh
```

That's it! You now have PeerDB up and running on your machine, ready to query away!

### Quickstart

<Info>
  {" "}

  The following steps assume you have PeerDB running locally. We also need `psql` installed and available on your
  PATH.
</Info>

## Setup

This script reuses the PeerDB internal Postgres instance to setup two databases, which we can use to create two peers. It also creates some tables on both databases to use later in the quickstart. Run the following commands in your terminal:

```bash theme={null}
curl -O https://raw.githubusercontent.com/PeerDB-io/peerdb/main/quickstart_prepare_peers.sh
chmod +x quickstart_prepare_peers.sh
./quickstart_prepare_peers.sh
```

### Creating Peers

With PeerDB running, we can create our first peers.

Head over to `localhost:3000` on your browser. This is the PeerDB Dashboard.

Clicking on **Peers** in the sidebar will take us to the **Peers** page.

#### Creating Source Postgres Peer

Let's click on the Create Peer button at the top right to get started.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createpeerbutton.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=10f46f52e063b1f19903a2b984b87b7e" alt="create peer" width="3454" height="564" data-path="images/ui-quickstart/createpeerbutton.png" />

Now, we select the data store for which we wish to create a peer. Let's select **Postgres** and click on the **Continue** button.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/selectpg.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=b2d17258914a1b48303db0fc441fc0ed" alt="select datastore" width="2304" height="914" data-path="images/ui-quickstart/selectpg.png" />

This takes to a form where we can fill in the details for the peer. Let's fill in the details of our PostgreSQL peer.

Fill in the **password** as `postgres`.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createpg1.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=917c9364d474dfcce26d96f517413ee7" alt="source peer" width="1964" height="1342" data-path="images/ui-quickstart/createpg1.png" />

PeerDB validates the connection details and if everything is correct, clicking on **Validate** should show a success message.

Finally, click on **Create** to create the peer.

We now have our **source PostgreSQL peer** ready.

#### Creating Target Kafka Peer

Let's create the **target Kafka peer**.

First lets start a local Kafka (or Redpanda) instance.

```bash theme={null}
mkdir redpanda-setup && cd redpanda-setup
curl -O https://docs.redpanda.com/redpanda-labs/docker-compose/_attachments/single-broker/docker-compose.yml
docker compose up -d

# connect to the peerdb_network network
docker network connect peerdb_network $(docker container ls -qf "name=redpanda-0")
docker network connect peerdb_network $(docker container ls -qf "name=redpanda-console")
```

Once you go to the create peers page, select Kafka as the option.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/kafka-setup-1.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=3dafb17669ce5cf99c61b01dbe8da5e2" alt="create peer" width="2532" height="1166" data-path="images/streams-quickstart/kafka-setup-1.jpeg" />

Fill in the various fields:

* Name: `target`
* Servers: `redpanda-0:9092`
* SASL Mechanism: `Scram SHA 256`
* Partitioner: `Least Backup`
* Disable TLS: `true`

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/kafka-setup-2.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=b0d4bb65700768247c5195e1f0748d78" alt="target peer" width="2448" height="1548" data-path="images/streams-quickstart/kafka-setup-2.jpeg" />

Then click the **Create Peer** button.

Clicking on **Mirrors** in the sidebar will take us to the **Mirrors** page.

#### Real-time CDC

Lets start by creating a CDC mirror. In the side-bar click on **Mirrors**, and then **CDC Mirror**.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/cdc-1.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=6d26a9c40df9f8d97e82404ed105d4a3" alt="mirrorform" width="2222" height="1216" data-path="images/streams-quickstart/cdc-1.jpeg" />

Scrolling down, we can see a section to a **select the table** on our source PostgreSQL peer to sync.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/cdc-2.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=e794b293290215f6e15c222ab989307c" alt="selecttable" width="2256" height="816" data-path="images/streams-quickstart/cdc-2.jpeg" />

Let's select the table we have ready - `public.test`.
Now that we've filled in all the mirror details.

Let's click on **Create Mirror**, which will validate to check if everything is set up correctly, much like we did when creating peers and then will create the mirror.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/cdc-3.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=b173039aff33e528e372ba47bc72f5bf" alt="create-mirror" width="2602" height="1486" data-path="images/streams-quickstart/cdc-3.jpeg" />

Connect to PeerDB via psql:

```bash theme={null}
psql "port=9900 host=localhost password=peerdb"
```

And now we can run the below commands.

```sql theme={null}
--- Verify that the source table has zero rows
SELECT id,c1,c2,t FROM source.public.test;
```

```sql theme={null}
--- Insert a row into the source table
INSERT INTO source.public.test(c1, c2, t) VALUES(1, 2, 'oathbringer');
```

Within a minute, the row should be replicated to the target table. Let's click the mirror link on the `Mirrors` page which we landed on after creating the mirror:

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/mirror-box.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=867bf279a512a395300f8989afd94756" alt="mirrorlink" width="2324" height="688" data-path="images/streams-quickstart/mirror-box.jpeg" />

This takes to the **Mirror Overview** page. Let's click on the **Sync Status tab**, where we can see the status of the mirror and the number of rows replicated:

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/sync-area.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=ae37a3fe4858fb800d2485d2b2db1552" alt="mirroroverview" width="3036" height="1904" data-path="images/streams-quickstart/sync-area.jpeg" />

We can see that the mirror has successfully replicated the row from the source to the target peer. Let's verify this by querying the target topic.

Head over to [Redpanda Console](http://localhost:8080/topics), click on the `public.test` topic:

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/streams-quickstart/rp-console.jpeg?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=3a9a877fda4f81196d54aaf63509a9b1" alt="rpconsole" width="2908" height="1770" data-path="images/streams-quickstart/rp-console.jpeg" />

The above MIRROR takes care of replicating all future DML commands (`INSERT`, `UPDATE`, `DELETE`) from source to target.

### FAQ

If you have any questions about the PeerDB setup and deployment process, don't hesitate to reach out on [Slack](https://slack.peerdb.io). We're more than happy to assist and answer any questions, including:

* What is the performance I can expect during CDC and query based replication?
* How do I know my data sync is successful?
* Can I set a specific time to start my data sync?

If there are any unanswered questions, we'd love to help you get started. Feel free to ask your questions on our community [Slack](https://slack.peerdb.io) channel.

In addition to this, if you require direct access to our team for any assistance, don't hesitate to contact us to discuss our premium support offerings.
