Ingestion
How data gets into the platform: scheduled extracts, partner file drops, and change data capture with Debezium from PostgreSQL into Kafka, on OpenShift with Streams for Apache Kafka.
Ingestion copies data out of a source without getting in the source's way. A core table, a CSV a branch sent, and a row that changed a second ago are three different copies, and each one must be safe to run again. That is the landing rule from the pipeline overview.
This lab uses Streams for Apache Kafka and the object store on our OpenShift cluster. Batch files land in the bucket. Row changes from PostgreSQL land in Kafka through Debezium. Spark writes both into Iceberg. The lakehouse lab is where those paths sit.
Prerequisites
- OpenShift 4.x,
oc, and the right to create workloads indata-pipeline - Streams for Apache Kafka, cluster
lab-kafka(KRaft, three brokers in our lab) - PostgreSQL you may read logically. Ours is Crunchy Postgres for Kubernetes, cluster
payments-pginpayments, databasepayments - The
lakehousebucket from the lakehouse lab, and theawsCLI for file drops
oc get kafka lab-kafka -n data-pipeline
oc get kafka lab-kafka -n data-pipeline -o jsonpath='{.spec.kafka.version}{"\n"}'
The version that prints is the version on Kafka Connect below.
Three ways in
| Way | When it fits | Lands in | Runs |
|---|---|---|---|
| Scheduled extract | A daily or hourly grain is enough | One object per run | A CronJob, later owned by orchestration |
| File drop | A partner already produces a file | A landing prefix, then bronze | When the file appears |
| Change data capture | You need each insert, update and delete | A Kafka topic per table | Continuously |
Use CDC for the few tables that feed fraud, a cache or a same-day view. Use extracts for everything a report can wait for. Polling a busy table every minute loads the source and still misses the shape of each change.
Scheduled extracts
An extract is a query with a window, written to one partition and overwritten if the job runs twice. Bangladesh does not change clocks, so pin the window to Asia/Dhaka. CURRENT_DATE follows the database session.
The lab image extract contains psql and the AWS CLI. It reads DATABASE_URL and the bucket credentials from secrets:
DT=$(TZ=Asia/Dhaka date +%F)
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 \
-c "SET TIME ZONE 'Asia/Dhaka'" \
-c "\copy (
SELECT id, account_no, balance, updated_at
FROM accounts
WHERE updated_at >= (CURRENT_DATE - INTERVAL '1 day')
AND updated_at < CURRENT_DATE
) TO STDOUT WITH (FORMAT CSV, HEADER true, ENCODING 'UTF8')" \
| aws s3 cp - "s3://${BUCKET}/bronze/accounts/dt=${DT}/accounts.csv" \
--endpoint-url "${S3_ENDPOINT}"
\copy runs as the client. The same DT replaces that object, so the day is not doubled. Wrap it in a CronJob named extract-accounts: schedule: "15 2 * * *", timeZone: Asia/Dhaka (2:15 a.m. in Dhaka, including when the nodes are UTC), concurrencyPolicy: Forbid, image extract, command /opt/jobs/extract_accounts.sh, envFrom the extract-accounts and lakehouse secrets.
oc apply -f extract-accounts-cronjob.yaml
oc create job -n data-pipeline extract-accounts-manual --from=cronjob/extract-accounts
oc logs -n data-pipeline job/extract-accounts-manual
Move this schedule to Airflow or Argo in the orchestration lab once the extract is part of a larger pipeline.
File drops
Some data never sits in a database you control. Land it at landing/accounts/incoming/, and after a good load move it to landing/accounts/accepted/. Spark reads bronze/accounts/dt=.../.
BUCKET=$(oc get cm lakehouse -n data-pipeline -o jsonpath='{.data.BUCKET_NAME}')
HOST=$(oc get cm lakehouse -n data-pipeline -o jsonpath='{.data.BUCKET_HOST}')
PORT=$(oc get cm lakehouse -n data-pipeline -o jsonpath='{.data.BUCKET_PORT}')
aws s3 cp branch-accounts.csv \
"s3://${BUCKET}/landing/accounts/incoming/branch-accounts.csv" \
--endpoint-url "http://${HOST}:${PORT}"
The keys are AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in the lakehouse secret. Export them in that shell. Do not commit them.
Names in Bangla (নাম, branch titles, addresses) survive only as UTF-8. Check with file -bi before you accept the object; a Windows-1252 file will load and the names will be wrong. Map a header such as হিসাব,নাম,ব্যালেন্স to account_no, holder_name, balance in the silver job, and leave the landing file untouched. After a good load, aws s3 mv the object from incoming/ to accepted/. On S3 that is copy then delete, so delete only after the bronze copy is in place.
Change data capture with Debezium
CDC reads the database log. On the Crunchy cluster, set Patroni postgresql.parameters wal_level=logical, max_wal_senders=10 and max_replication_slots=10, and let the operator roll the pods.
PRIMARY=$(oc get pods -n payments \
-l postgres-operator.crunchydata.com/cluster=payments-pg,postgres-operator.crunchydata.com/role=master \
-o jsonpath='{.items[0].metadata.name}')
oc exec -n payments "$PRIMARY" -- psql -d payments -c "SHOW wal_level;"
You want logical. Create a replication role and a publication as a superuser. The publication lists the tables, so the connector itself is not a superuser. Put the same password in the secret, not in Git.
CREATE ROLE debezium WITH LOGIN REPLICATION PASSWORD 'change-me';
GRANT CONNECT ON DATABASE payments TO debezium;
GRANT USAGE ON SCHEMA public TO debezium;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO debezium;
CREATE PUBLICATION debezium_payments FOR TABLE public.transactions;
oc create secret generic debezium-pg -n data-pipeline \
--from-literal=username=debezium \
--from-literal=password='change-me'
Kafka Connect runs as its own cluster. Streams builds the image: the operator's Kafka Connect base, plus the Debezium PostgreSQL plugin 3.6.3.Final (the release we run). version is the Kafka version printed above. On a disconnected cluster, host that same archive on an internal URL and use that URL. The standalone Debezium container image is a different layout; do not put it in spec.image.
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnect
metadata:
name: lab-connect
namespace: data-pipeline
annotations:
strimzi.io/use-connector-resources: "true"
spec:
version: 4.2.0
replicas: 1
bootstrapServers: lab-kafka-kafka-bootstrap:9092
config:
group.id: lab-connect
offset.storage.topic: lab-connect-offsets
config.storage.topic: lab-connect-configs
status.storage.topic: lab-connect-status
offset.storage.replication.factor: 3
config.storage.replication.factor: 3
status.storage.replication.factor: 3
config.providers: secrets
config.providers.secrets.class: io.strimzi.kafka.KubernetesSecretConfigProvider
build:
output:
type: imagestream
image: lab-connect:latest
plugins:
- name: debezium-postgres
artifacts:
- type: tgz
url: https://repo1.maven.org/maven2/io/debezium/debezium-connector-postgres/3.6.3.Final/debezium-connector-postgres-3.6.3.Final-plugin.tar.gz
The Connect service account is lab-connect-connect. It needs get on the secret debezium-pg, or the task fails with an error that does not mention RBAC. A Role limited to that secret, bound to the service account, is enough.
The PostgreSQL connector is one task. One task owns the replication slot.
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
name: payments-postgres
namespace: data-pipeline
labels:
strimzi.io/cluster: lab-connect
spec:
class: io.debezium.connector.postgresql.PostgresConnector
tasksMax: 1
config:
database.hostname: payments-pg-primary.payments.svc
database.port: "5432"
database.user: ${secrets:data-pipeline/debezium-pg:username}
database.password: ${secrets:data-pipeline/debezium-pg:password}
database.dbname: payments
topic.prefix: payments
plugin.name: pgoutput
publication.name: debezium_payments
publication.autocreate.mode: disabled
slot.name: debezium_payments
table.include.list: public.transactions
snapshot.mode: initial
heartbeat.interval.ms: "10000"
tombstones.on.delete: "false"
topic.prefix plus schema and table is the topic: payments.public.transactions. snapshot.mode: initial copies the table once, then follows the log. The heartbeat advances the slot when transactions is idle. Deletes arrive as "op":"d" because tombstones are off; the silver MERGE applies them.
oc apply -f lab-connect.yaml
oc apply -f payments-connector.yaml
oc get kafkaconnector payments-postgres -n data-pipeline \
-o jsonpath='{.status.connectorStatus.connector.state}{"\n"}'
oc exec -n data-pipeline deploy/lab-connect-connect -- \
curl -s localhost:8083/connectors/payments-postgres/status
BROKER=$(oc get pods -n data-pipeline -l strimzi.io/cluster=lab-kafka,strimzi.io/kind=Kafka -o jsonpath='{.items[0].metadata.name}')
oc exec -n data-pipeline "$BROKER" -- bin/kafka-console-consumer.sh \
--bootstrap-server lab-kafka-kafka-bootstrap:9092 \
--topic payments.public.transactions --from-beginning --max-messages 3
RUNNING on the connector and on task 0 is healthy. If the connector never appears, look at the OpenShift Build for lab-connect. A record's op is r (snapshot), c, u or d. For a database window, PUT http://localhost:8083/connectors/payments-postgres/pause from the Connect pod, then PUT the same path with resume. A paused slot keeps WAL until the volume fills; read pg_replication_slots on the primary, and drop the slot only when the connector will not come back. The Kafka CDC lab and the Kafka labs go further.
Extracts and files land in the bucket. The change stream lands in Kafka, and a sink or a small job can write the same events to bronze when you also need to replay them as a table. The serving database can be rebuilt. The raw object, or the topic with a retention you chose, is what a restatement starts from.
Oracle
The same Connect cluster can run io.debezium.connector.oracle.OracleConnector beside PostgreSQL. Oracle CDC reads redo through LogMiner, so the database must be in ARCHIVELOG mode, with supplemental logging on the database and on the captured columns (ALTER DATABASE ADD SUPPLEMENTAL LOG DATA, then supplemental log groups). Add the Oracle plugin archive the same way as the PostgreSQL one, and add the Oracle JDBC driver as a jar artifact you supply: the driver is not in the plugin archive. LogMiner needs more memory than pgoutput. Give Oracle its own Connect cluster if the PostgreSQL tasks cannot share that load. The topic name and the op / before / after envelope match, so the silver job does not care which database produced the event.
When the first load looks wrong
| What you see | Likely cause | What to do |
|---|---|---|
Connector FAILED |
WAL is still replica, the publication name differs, or the secret is not readable |
curl the status; the task trace names the missing piece |
Topic empty after RUNNING |
table.include.list does not match, or the snapshot is still running |
Check the task, then the publication's table list |
| Slot inactive and the disk grows | The connector is paused or crashed | Resume or fix it the same day |
| A rerun doubled the rows | The extract used a new object name | Write to the same dt= key and rerun once |
What's next
- Apache Spark: merge this bronze data and these topics into Iceberg.
- Orchestration: own the 2:15 a.m. extract. Leave the connector running outside the DAG.
- Data lakehouse: the bucket, the catalog and the bronze, silver and gold layout.
- Kafka CDC with Debezium: the connector in more depth, including the outbox pattern.
The pipeline overview is the map this lab is one box on.