Most databases change all day: users sign up, orders are placed, and each order moves from one status to the next. Change data capture (CDC) turns those changes into a stream of events that other systems can read as they happen. In this post, a simulated online shop writes to PostgreSQL in real time, Debezium streams every change to Kafka, and a sink connector saves the changes as files in object storage. Everything runs on your own machine.
[Update 2026-11-15] The simulation is now one YAML file, ecommerce/simulation/shop.yaml, which desflow 1.0.0 runs with desflow run. It replaces run.py, shop.py and catalogue.py, and reads the distribution centres, products and cities from CSV files beside it. The code, commands, log and figures below show the new version.
[Update 2026-10-16] dynamic-des is now desflow (0.20.0). The code and commands below use the new name: pip install desflow, import desflow and the desflow command.
The shop’s data model follows the theLook eCommerce dataset. The source code is in benchtop/ecommerce-cdc. It is one of the Benchtop projects, which run locally from a fresh clone.
What You Will Build
- Run the simulation, which fills the tables and keeps changing them.
- Deploy the connectors: Debezium streams every insert and update to Kafka, and the S3 sink saves them as files.
- Look at the changes in Kafka and in SeaweedFS.
- Change the simulation while it runs, and see the change in the stream.
To start again at any point, python -m ecommerce.stores.cleanup removes everything this project has created and keeps the services running. Clean Up describes what it removes.
Architecture

The data moves in one direction: a simulation writes to PostgreSQL, Debezium reads the changes into Kafka topics, and the S3 sink writes the topics to files in SeaweedFS.
- Change data capture means reading a database’s changes as a stream of events, instead of querying its tables again and again. PostgreSQL records every change in its write-ahead log (WAL) before it applies it, and CDC reads that log.
- Kafka stores streams of events in topics. A topic keeps its events in order, and any number of readers can read it.
- Kafka Connect runs connectors. A source connector copies data into Kafka, and a sink connector copies data out of it. You deploy a connector by sending its settings, as JSON, to Connect’s REST API.
- Debezium is a source connector for CDC. It first copies every existing row, which is called a snapshot. It then streams each new change from the WAL, and writes one topic per table.
- A replication slot is PostgreSQL’s record of how far a reader has got in the WAL. PostgreSQL keeps the part of the WAL the slot has not read yet, so Debezium can stop and carry on without losing a change.
- A publication names the tables whose changes PostgreSQL sends. odctl’s PostgreSQL has a publication,
cdc_pub, that covers every table in thecdcschema. - Aiven’s S3 sink is a sink connector. It reads the topics and writes their events to files in SeaweedFS, an object store with the same API as Amazon S3.
- desflow runs the simulation, a discrete-event model of the shop written in one YAML file. desflow (documentation) is a Python library for simulations that stream their output.
The simulation writes six tables in PostgreSQL’s cdc schema:
| Table | Rows | Changes |
|---|---|---|
dist_centers | 10 distribution centres | inserted once |
products | 260 products | inserted once |
users | registered users | inserted, and updated when a user moves address |
orders | orders | inserted as Processing, then updated to Shipped, Delivered, Cancelled or Returned |
order_items | the products in each order | inserted, and updated with their order’s status |
events | page views in web sessions, including anonymous visitors | inserted only |
Setup
You need Docker (Docker Desktop, OrbStack or Docker Engine), uv and Python 3.13. Clone the repository and run every command from the project folder:
1git clone https://github.com/jaehyeon-kim/benchtop.git
2cd benchtop/ecommerce-cdc
3
4uv venv # create .venv
5source .venv/bin/activate # activate it, in each new shell
6uv pip install -r requirements.txt
7
8odctl up postgres kafka-lite storage
odctl is a command line tool that starts a local data stack with Docker Compose. Its profiles start these services:
postgres: PostgreSQL, already set up for CDC. It runs withwal_level=logical, which makes the WAL hold enough detail for CDC. It also has the schemacdcwith the publicationcdc_pub.kafka-lite: one Kafka broker, Kafka Connect with the Debezium and Aiven S3 connectors, Karapace and Kafka UI. Karapace is a schema registry: it stores the schema of each topic’s messages, so a message carries only a short schema id.storage: SeaweedFS.
The web UIs:
- Kafka UI: http://127.0.0.1:8086, for the topics, their messages and the connectors
- SeaweedFS file browser: http://127.0.0.1:8889
Simulation Model
A discrete-event simulation (DES) moves a clock from one event to the next, such as a visitor arriving or an order being packed. Nothing happens between events, so the model only has to say what each event does and how long it is until the next one. Here the clock runs at the speed of real time.
The model is one YAML file, ecommerce/simulation/shop.yaml. It has three kinds of entity. An entity, such as a visit or an order, goes through a chain of tasks, and each task names the next one:
- Visitor: visitors arrive at random, about one a second. Each views the home page and one to four products, and spends a few seconds on each page. Six in ten are registered users. Three in ten buy: they view the cart, sign up first if they are new, and place an order of one to four products.
- Order: each order waits for one of the warehouse’s pickers. Three pickers pack orders, one at a time each. When orders arrive faster than they are packed, they queue. An order that waits longer than its customer’s patience, about two minutes, is cancelled. A packed order is shipped, delivered about a minute later, and one in ten is returned.
- Move: now and then a registered user moves to a new address.
Each part of this model is a section of the file:
| Part | Key in shop.yaml | Here |
|---|---|---|
| random arrivals | arrivals | visitors, and address moves |
| fixed rows at the start | arrivals with initial | the distribution centres and products, read from CSV files, and the first 100 users |
| time spent on a step | services | a page view, packing, transit, patience and the time until a return |
| limited capacity | resources | the pickers, which make orders queue |
| chances | variables | a visitor is registered, a visitor buys, an order is returned |
| the steps of a visit or an order | tasks, with next and spawn | each page of a visit, and each status of an order |
| live changes | the registry and ingress | any of the above, while it runs |
| writes | egress | one per table, upserting on id |
Each parameter is added to desflow’s registry, a store of named parameters that the model reads each time it draws a value. The top of the file holds the Kafka reader for live changes and the parameters:
1# Parameter changes from ecommerce.simulation.control
2ingress:
3 - type: Kafka
4 config:
5 bootstrap_servers: "127.0.0.1:9092"
6 topic: ecommerce-control
7
8# Shares of visitors or orders, from 0 to 1
9variables:
10 returning: 0.6 # a visitor is a registered user
11 buy: 0.3 # a visitor buys at the end of the visit
12 return: 0.1 # a delivered order is returned
13
14# Warehouse pickers packing orders at once
15resources:
16 pickers: {current_cap: "${PICKERS:-3}", max_cap: 10}
17
18# Mean and standard deviation, in seconds
19services:
20 page_view: {dist: lognormal, mean: 4.0, std: 2.0} # time on a page before the next one
21 # how long an order waits for a picker before it is cancelled
22 patience: {dist: lognormal, mean: 120.0, std: 60.0}
23 pick: {dist: lognormal, mean: 5.0, std: 2.0} # a picker packs an order
24 transit: {dist: lognormal, mean: 60.0, std: 20.0} # a shipped order reaches the customer
25 return_after: {dist: lognormal, mean: 60.0, std: 30.0} # a returned order comes back
The order’s tasks are in the same file. pick_order asks for a picker, with a patience time drawn from the patience service. If the order waits longer than its patience, it leaves the queue and goes to cancel_order (on_renege). Each status change sets the order’s attributes, and order_row writes the order again with the same id. items then writes a row for each of its items and chooses the next status. *now is the simulated time as ISO 8601 text, defined once earlier in the file with a YAML anchor:
1 # A picker packs the order and it ships, unless it waits for a picker longer than
2 # its patience and is cancelled.
3 pick_order:
4 resource: pickers
5 service: pick
6 patience: {gen: sample, service: patience}
7 on_renege: cancel_order
8 payload: null
9 set: {status: Shipped, updated_at: *now, shipped_at: *now}
10 next: order_row
11 cancel_order:
12 payload: null
13 set: {status: Cancelled, updated_at: *now, cancelled_at: *now}
14 next: order_row
15 deliver_order:
16 service: transit
17 payload: null
18 set:
19 status: Delivered
20 updated_at: *now
21 delivered_at: *now
22 sent_back: {gen: boolean, p: {gen: param, path: ecommerce.variables.return}}
23 next: order_row
24 return_order:
25 service: return_after
26 payload: null
27 set: {status: Returned, updated_at: *now, returned_at: *now}
28 next: order_row
29 # The orders row after each status change, then a row for each of its items
30 order_row:
31 payload:
32 __table__: cdc.orders
33 id: {gen: attr, name: order_id}
34 user_id: {gen: attr, name: user_id}
35 status: {gen: attr, name: status}
36 num_of_items: {gen: expr, expr: "len(attr.items)"}
37 created_at: {gen: attr, name: created_at}
38 updated_at: {gen: attr, name: updated_at}
39 shipped_at: {gen: attr, name: shipped_at}
40 delivered_at: {gen: attr, name: delivered_at}
41 cancelled_at: {gen: attr, name: cancelled_at}
42 returned_at: {gen: attr, name: returned_at}
43 next: items
44 items:
45 wait:
46 each: attr.items
47 branch: {task: item_row, args: {item: {gen: expr, expr: each.value}}}
48 payload: null
49 next:
50 when:
51 - {condition: "attr.status == 'Processing'", task: pick_order}
52 - {condition: "attr.status == 'Shipped'", task: deliver_order}
53 - {condition: "attr.status == 'Delivered' and attr.sent_back", task: return_order}
The egress section has one PostgreSQL writer per table, each upserting on id. An upsert inserts a row, or updates it when a row with the same key exists. So a changed order reaches PostgreSQL as an update, and Debezium sees it as one. Each writer also creates its table when it is missing, from the columns its tables entry lists. The first writer is shown here, and the other five differ only in their table and its columns:
1# A few rows a second for each table
2batching: {batch_size: 4, flush_interval: 1.0}
3
4# One sink for each table. Each creates its table at the start when it does not exist,
5# and upserts on `id`, so a changed order or user reaches PostgreSQL as an update. Times
6# are ISO 8601 text in UTC. A row's `__table__` names the sink that writes it, and
7# `envelope: false` writes the row alone, with no record of a task being queued or
8# started, and `when` drops the record of an order that leaves the picking queue,
9# which `cancel_order` writes as a row instead.
10egress:
11 - type: Postgres
12 when: &rows {expr: "record.stream_type == 'event' and record.value.status != 'reneged'"}
13 envelope: false
14 config:
15 connection_dsn: &dsn "postgresql://user:password@127.0.0.1:5432/odctl"
16 upsert_keys: &key [id]
17 tables:
18 cdc.dist_centers:
19 primary_key: id
20 columns:
21 id: BIGINT
22 name: TEXT
23 latitude: DOUBLE PRECISION
24 longitude: DOUBLE PRECISION
Times are stored as ISO 8601 text in UTC. desflow publishes each row as JSON-friendly values, so a time reaches PostgreSQL as a string, and a timestamp column does not accept a string.
Step 1: Run the Simulation
1desflow run ecommerce/simulation/shop.yaml --until "16 min" # or leave out --until, and stop with Ctrl + C
It creates the six tables if they are missing, and writes the centres, the products and 100 users. It then runs in real time. With the default parameters it places about 18 orders a minute, and each order changes three or four times over the next few minutes. Its log shows the Kafka reader and one PostgreSQL writer per table:
14:40:26 [INFO] desflow.builder.context: Building SimulationContext for 'ecommerce'...
14:40:26 [INFO] desflow.builder.context: No random_seed was given, so this run uses 1778597616. Repeat it with: desflow run ecommerce/simulation/shop.yaml --seed 1778597616 --until 13min
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.core.environment: PostgresEgress has envelope: false, so it skips telemetry and the queued and started records, and writes each event's value alone.
14:40:26 [INFO] desflow.builder.context: Simulation engine started.
14:40:26 [INFO] aiokafka.consumer.subscription_state: Updating subscribed topics to: frozenset({'ecommerce-control'})
14:40:26 [INFO] aiokafka.consumer.group_coordinator: Metadata for topic has changed from {} to {'ecommerce-control': 1}.
14:40:26 [INFO] desflow.connectors.ingress.kafka: Connected to Kafka Ingress topic: ecommerce-control
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.products
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.users
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.order_items
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.events
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.orders
14:40:26 [INFO] desflow.connectors.egress.postgres: PostgresEgress connected to cdc.dist_centers
Leave it running, and use a second terminal for the next steps.
Step 2: Deploy the Connectors
1python -m ecommerce.cdc.connectors
It sends two JSON files to Kafka Connect. Connect creates each connector, or updates it if it exists. The source connector’s settings are in ecommerce/cdc/source.json:
1{
2 "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
3 "tasks.max": "1",
4 "database.hostname": "postgres",
5 "database.port": "5432",
6 "database.user": "user",
7 "database.password": "password",
8 "database.dbname": "odctl",
9 "plugin.name": "pgoutput",
10 "publication.name": "cdc_pub",
11 "publication.autocreate.mode": "disabled",
12 "slot.name": "ecommerce_cdc",
13 "table.include.list": "cdc.users,cdc.products,cdc.dist_centers,cdc.orders,cdc.order_items,cdc.events",
14 "topic.prefix": "ecommerce",
15 "snapshot.mode": "initial",
16 "key.converter": "io.confluent.connect.avro.AvroConverter",
17 "key.converter.schema.registry.url": "http://karapace:8081",
18 "value.converter": "io.confluent.connect.avro.AvroConverter",
19 "value.converter.schema.registry.url": "http://karapace:8081"
20}
These settings tell Debezium to:
- read the database
odctlwith PostgreSQL’s built-inpgoutputdecoder; - use the existing publication
cdc_pub, and never create one (publication.autocreate.modeisdisabled); - keep its place in the WAL in its own replication slot,
ecommerce_cdc; - capture only this project’s six tables, and name the topics
ecommerce.cdc.<table>; - take a snapshot of the existing rows first (
snapshot.modeisinitial); - write Avro, a compact binary format, with each table’s key and value schemas registered in Karapace as the subjects
ecommerce.cdc.<table>-keyandecommerce.cdc.<table>-value.
The sink connector’s settings are in ecommerce/cdc/s3-sink.json:
1{
2 "connector.class": "io.aiven.kafka.connect.s3.AivenKafkaConnectS3SinkConnector",
3 "tasks.max": "1",
4 "topics.regex": "ecommerce\\.cdc\\..*",
5 "consumer.override.metadata.max.age.ms": "30000",
6 "aws.access.key.id": "user",
7 "aws.secret.access.key": "password",
8 "aws.s3.endpoint": "http://seaweed:8333",
9 "aws.s3.region": "us-east-1",
10 "aws.s3.bucket.name": "odctl-dev",
11 "file.name.template": "ecommerce-cdc/{{topic}}/{{partition}}-{{start_offset}}.jsonl",
12 "file.compression.type": "none",
13 "format.output.type": "jsonl",
14 "format.output.fields": "key,value,offset,timestamp",
15 "format.output.fields.value.encoding": "none",
16 "key.converter": "io.confluent.connect.avro.AvroConverter",
17 "key.converter.schema.registry.url": "http://karapace:8081",
18 "value.converter": "io.confluent.connect.avro.AvroConverter",
19 "value.converter.schema.registry.url": "http://karapace:8081"
20}
It reads every topic whose name matches ecommerce.cdc.*, and decodes each message with its schema from Karapace. It writes JSON lines files to the bucket odctl-dev, under ecommerce-cdc/<topic>/, with one change event on each line. The sink writes a file each time Connect commits its offsets, which record how far the sink has read. That happens about once a minute. The orders topic is created only when the first order is placed, after the sink has started. The sink subscribes by a topic pattern, and a Kafka consumer looks for new topics only when it refreshes its list of topics, every five minutes by default. consumer.override.metadata.max.age.ms makes the sink’s consumer refresh it every 30 seconds instead. In a test run, the first orders file appeared after about a minute.
Each connector’s status should show RUNNING for the connector and its task:
1curl -s http://127.0.0.1:8083/connectors/ecommerce-cdc-source/status
2curl -s http://127.0.0.1:8083/connectors/ecommerce-cdc-s3/status
Kafka UI lists both connectors under Kafka Connect.

Step 3: Look at the Changes
Debezium creates one topic per table. The simulation creates ecommerce-control, which carries parameter changes. The topics after a run:
ecommerce-control
ecommerce.cdc.dist_centers
ecommerce.cdc.events
ecommerce.cdc.order_items
ecommerce.cdc.orders
ecommerce.cdc.products
ecommerce.cdc.users


In Kafka UI, open a topic such as ecommerce.cdc.orders. Each message is one change, and its op field says which kind:
op | Meaning |
|---|---|
r | a row read in the first snapshot |
c | a new row (create) |
u | an update: after holds the row’s new values |

This update shows an order moving from Processing to Shipped, with the time it shipped. source records where the change came from: the table, the transaction and its position in the WAL (lsn).
1{
2 "before": null,
3 "after": {
4 "id": "23b2d4a9-360d-4973-a6da-fd1cc394ca10",
5 "user_id": "862dd089-c746-4127-89d7-db4fcab59a2e",
6 "status": "Shipped",
7 "num_of_items": 1,
8 "created_at": "2026-09-30T13:38:56+00:00",
9 "updated_at": "2026-09-30T13:39:01+00:00",
10 "shipped_at": "2026-09-30T13:39:01+00:00",
11 "delivered_at": null,
12 "cancelled_at": null,
13 "returned_at": null
14 },
15 "source": {
16 "version": "3.7.0.Final",
17 "connector": "postgresql",
18 "name": "ecommerce",
19 "ts_ms": 1790775541329,
20 "snapshot": "false",
21 "db": "odctl",
22 "sequence": "[\"161004032\",\"161004832\"]",
23 "ts_us": 1790775541329358,
24 "ts_ns": 1790775541329358000,
25 "schema": "cdc",
26 "table": "orders",
27 "txId": 45922,
28 "lsn": 161004832,
29 "xmin": null,
30 "origin": null,
31 "origin_lsn": null
32 },
33 "transaction": null,
34 "op": "u",
35 "ts_ms": 1790775541830,
36 "ts_us": 1790775541830602,
37 "ts_ns": 1790775541830602065
38}
before is null for updates, because PostgreSQL logs only the new row by default.
In the SeaweedFS file browser, go to odctl-dev/ecommerce-cdc/. There is a folder per topic. Each file holds the change events of one partition, one per line. The first line of the first orders file, 0-0.jsonl, is a create event. The sink adds the message’s key, offset and time around the change event:
1{
2 "offset": 0,
3 "value": {
4 "before": null,
5 "after": {
6 "id": "23b2d4a9-360d-4973-a6da-fd1cc394ca10",
7 "user_id": "862dd089-c746-4127-89d7-db4fcab59a2e",
8 "status": "Processing",
9 "num_of_items": 1,
10 "created_at": "2026-09-30T13:38:56+00:00",
11 "updated_at": "2026-09-30T13:38:56+00:00",
12 "shipped_at": null,
13 "delivered_at": null,
14 "cancelled_at": null,
15 "returned_at": null
16 },
17 "op": "c"
18 },
19 "key": {
20 "id": "23b2d4a9-360d-4973-a6da-fd1cc394ca10"
21 },
22 "timestamp": "2026-09-30T13:38:57.992Z"
23}
The line is shown across several lines here. source, transaction and the ts_* times are left out of value, because they have the same fields as the change event above.

Step 4: Change the Simulation While It Runs
The simulation reads parameter changes from the Kafka topic ecommerce-control, through the ingress entry of shop.yaml. It uses each new value from the next time it draws one. control.py sends a change. With the simulation and both connectors running, cut the pickers from three to one:
1python -m ecommerce.simulation.control ecommerce.resources.pickers.current_cap 1
Sent ecommerce.resources.pickers.current_cap = 1.0 to ecommerce-control
One picker packs about 12 orders a minute, which is fewer than the 18 or so placed, so the queue grows. The Shipped updates in ecommerce.cdc.orders fall from about 20 a minute to about 13. Cancelled updates appear as customers’ patience runs out, which never happens with three pickers. In one run, the change was sent at 03:45:11 UTC. These are the changes per minute in ecommerce.cdc.orders, counted by the minute of each Debezium event:
| Minute (UTC) | Pickers | New orders | Shipped | Cancelled |
|---|---|---|---|---|
| 03:41 | 3 | 16 | 20 | 0 |
| 03:42 | 3 | 21 | 17 | 0 |
| 03:43 | 3 | 22 | 23 | 0 |
| 03:44 | 3 | 16 | 18 | 0 |
| 03:46 | 1 | 26 | 12 | 0 |
| 03:47 | 1 | 16 | 14 | 1 |
| 03:48 | 1 | 20 | 12 | 6 |
| 03:49 | 1 | 20 | 14 | 2 |
| 03:50 | 1 | 19 | 13 | 4 |
| 03:51 | 1 | 20 | 12 | 10 |
| 03:52 | 1 | 13 | 12 | 6 |
Other parameters work the same way, such as ecommerce.arrival.visitor.rate for visitors a second, or ecommerce.variables.buy for the chance a visitor buys. python -m ecommerce.simulation.control --help lists them all. A change lasts until the simulation stops.
Clean Up
1python -m ecommerce.stores.cleanup
It removes only this project’s objects, and keeps the services running:
- Connectors: it stops both and deletes their stored offsets, so a new source connector takes a fresh snapshot. It then deletes them.
- Replication slot: it drops
ecommerce_cdc. PostgreSQL keeps the WAL for an unused slot forever, so a slot left behind makes the WAL grow without limit. - Tables: it drops the six tables in
cdc. - Kafka: it deletes the topics starting with
ecommerce., andecommerce-control. - SeaweedFS: it deletes the files under
odctl-dev/ecommerce-cdc/.
In a test run, the first clean-up deleted both connectors, the seven topics and 45 files. A second run found nothing left to delete, so it is safe to run twice.
To stop the services and delete their data:
1odctl down --all --volumes # answer y; --volumes also deletes the data
2deactivate
3rm -rf .venv
Related posts
- Change Data Capture (CDC) Local Development with PostgreSQL, Debezium Server and Pub/Sub Emulator - change data capture from PostgreSQL with Debezium Server and a Pub/Sub emulator instead of Kafka Connect
- Data Lake Demo using Change Data Capture (CDC) on AWS - Part 1 Local Development - an earlier local setup with Debezium and an S3 sink connector on Kafka Connect, the start of a data lake series
- Defining Data-Streaming Simulations in YAML, Without Writing Python - the simulation library that runs the shop, now configurable in plain YAML

Comments