|
| 1 | +--- |
| 2 | +title: "Change Data Capture" |
| 3 | +url: /refguide/change-data-capture/ |
| 4 | +weight: 85 |
| 5 | +description: "Describes Change Data Capture (CDC) services in Studio Pro, which publish domain model entity changes as Kafka streams for data warehouse and analytics pipelines." |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +{{% alert color="warning" %}} This feature is in beta. For more information, see [Release Status](/releasenotes/release-status/). {{% /alert %}} |
| 11 | + |
| 12 | +Change Data Capture (CDC) lets you stream domain model data out of a Mendix app in near real time. When objects in a tracked entity are created, updated, or deleted, the Mendix Runtime captures those changes and publishes them as events to a Kafka topic. Downstream systems, such as data warehouses or analytics pipelines, can then consume the stream without polling the Mendix database. |
| 13 | + |
| 14 | +CDC is intended for developers who need to move Mendix domain model data to external data stores, such as a data warehouse, data lake, or blob storage. |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +A CDC service document in Studio Pro defines which entities the Mendix Runtime should track. On deployment, each tracked entity gets its own Kafka topic. Every time a committed object change occurs (create, update, or delete) the Mendix Runtime publishes an event to the corresponding topic. |
| 19 | + |
| 20 | +Read events are triggered as snapshots during startup or when a stream changes in a way that constitutes a breaking change. Snapshots populate the new topic with the current data of the tracked entity. For more information, see the [Revisions](/refguide/published-cdc-services/#revisions) section of *Published CDC Services*. |
| 21 | + |
| 22 | +The broker that receives these events is either the [Mendix Event Broker](/appstore/services/event-broker/) or a Bring Your Own Kafka (BYOK) cluster. For BYOK configuration details, see [Mendix Event Broker](/appstore/services/event-broker/). |
| 23 | + |
| 24 | +To move the streamed data to a destination (such as Azure Blob Storage or AWS S3), you configure an [Event Broker Bridge](/appstore/services/event-broker/#manage-mx-broker-bridge) separately in the Event Broker Manager after deployment. |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +{{% alert color="warning" %}} |
| 29 | +Change Data Capture is not available for Free Apps. A licensed Mendix Cloud environment is required. |
| 30 | +{{% /alert %}} |
| 31 | + |
| 32 | +* A licensed Mendix Cloud environment |
| 33 | +* A [Mendix Event Broker](/appstore/services/event-broker/) license, or a BYOK Kafka cluster configured as described in [Mendix Event Broker](/appstore/services/event-broker/) |
| 34 | +* An [Event Broker Bridge](/appstore/services/event-broker/#manage-mx-broker-bridge) configured in the Event Broker Manager if you want to route CDC events to external storage |
| 35 | + |
| 36 | +## Setting Up Change Data Capture |
| 37 | + |
| 38 | +Set up a CDC service in Studio Pro by following the steps below: |
| 39 | + |
| 40 | +1. In Studio Pro, right-click a module in the App Explorer and choose **Add other** > **Change data capture service**. |
| 41 | +2. Select the entities to track and set an exposed name for each. For more information on configuring entities, see the [Entities to Track](/refguide/published-cdc-services/#entities) section of *Published CDC Services*. |
| 42 | +3. Deploy the app. The Runtime creates Kafka topics for each tracked entity automatically. |
| 43 | +4. In the [Event Broker Manager](https://broker.mendix.com/), configure an [Event Broker Bridge](/appstore/services/event-broker/#manage-mx-broker-bridge) to route CDC events to your destination. |
| 44 | + |
| 45 | +## Runtime Configuration {#runtime-configuration} |
| 46 | + |
| 47 | +CDC requires runtime settings to connect to a Kafka broker. Follow the steps below: |
| 48 | + |
| 49 | +1. In Studio Pro, open **App** > **Settings**. |
| 50 | +2. Open the **Configurations** tab. |
| 51 | +3. Select an existing configuration or click **New** to make a new one. |
| 52 | +4. In the configuration, open the **Custom** tab to add the settings documented in the section below. For deployed environments, set these via your environment's custom runtime settings. |
| 53 | + |
| 54 | +{{< figure src="/attachments/refguide/modeling/integration/change-data-capture/cdc-custom-configuration.png" alt="Edit Configuration dialog in Studio Pro showing the Custom tab with Kafka.BootstrapServers set to an IP address and port" >}} |
| 55 | + |
| 56 | +### Running Locally {#local-configuration} |
| 57 | + |
| 58 | +When running the app locally, only the bootstrap server address is required. |
| 59 | + |
| 60 | +| Name | Description | Default Value | |
| 61 | +| --- | --- | --- | |
| 62 | +| `Kafka.BootstrapServers` | The address of the Kafka broker, in the format `host:port`. | | |
| 63 | + |
| 64 | +### Bring Your Own Kafka (BYOK) {#byok-configuration} |
| 65 | + |
| 66 | +When connecting to a BYOK Kafka cluster, provide the bootstrap server address and credentials for authentication. The supported authentication method is `SASL/SCRAM-SHA-512`. |
| 67 | + |
| 68 | +| Name | Description | Default Value | |
| 69 | +| --- | --- | --- | |
| 70 | +| `Kafka.BootstrapServers` | The address of the Kafka broker, in the format `host:port`. | | |
| 71 | +| `Kafka.Username` | The username for `SASL/SCRAM-SHA-512` authentication with the Kafka cluster. | | |
| 72 | +| `Kafka.Password` | The password for `SASL/SCRAM-SHA-512` authentication with the Kafka cluster. | | |
| 73 | +| `EventBroker.Space` | The Event Broker space in which the app is placed. This defines which other applications can exchange events with this app. | `local` | |
| 74 | + |
| 75 | +### Active-Producer Election {#active-producer-election} |
| 76 | + |
| 77 | +In a horizontally-scaled deployment, multiple app instances would all publish CDC events to the same Kafka topics, producing duplicates. Active-producer election ensures that only one instance publishes at a time. |
| 78 | + |
| 79 | +When all three election settings are configured, each instance joins the same Kafka consumer group and subscribes to the election topic. Kafka assigns partition 0 of that topic to exactly one group member, and that instance becomes the active producer. All other instances stand by without publishing. |
| 80 | + |
| 81 | +If the active instance stops sending heartbeats (for example, because it crashed or was scaled down), Kafka triggers a rebalance and assigns the partition to another instance, which then starts producing. Before relinquishing the partition, the departing instance drains any in-flight events to prevent gaps. |
| 82 | + |
| 83 | +The `EventBroker.CdcProducerTransactionId` setting enables Kafka transactions on the active producer, providing exactly-once delivery guarantees during normal operation and a clean handover during failover. |
| 84 | + |
| 85 | +If any of the three election settings is missing, the Mendix Runtime logs a warning and falls back to single-instance mode, where all instances publish independently. |
| 86 | + |
| 87 | +### Message Format {#message-format} |
| 88 | + |
| 89 | +CDC events follow the [Debezium](https://debezium.io/) envelope format. Each event includes the following fields: |
| 90 | + |
| 91 | +* An `op` field indicating the operation type (`c` for create, `u` for update, `d` for delete, `r` for read/snapshot) |
| 92 | +* A `before` and `after` payload with the entity attribute values |
| 93 | +* A `source` block with metadata such as the timestamp and Mendix version |
| 94 | + |
| 95 | +Because the format is Debezium-compatible, BYOK consumers that already support Debezium (such as Kafka Connect sink connectors for databases or data warehouses) can consume CDC events without any message transformation. |
| 96 | + |
| 97 | +To parse messages, the schema for each tracked entity is available as an AsyncAPI document. You can download it from the [Event Broker Manager](https://broker.mendix.com/) on the service details page for the CDC service. |
| 98 | + |
| 99 | +For details on setting up a BYOK cluster with the Mendix Event Broker, see [Mendix Event Broker](/appstore/services/event-broker/). |
| 100 | + |
| 101 | +## Read More |
| 102 | + |
| 103 | +* [Published CDC Services](/refguide/published-cdc-services/) |
| 104 | +* [Mendix Event Broker](/appstore/services/event-broker/) |
| 105 | +* [Event Broker Bridges](/appstore/services/event-broker/#manage-mx-broker-bridge) |
0 commit comments