পাঠ ২১ · ২৯-এর মধ্যে · মডিউল ৩

Change Data Capture (CDC)

CDC — turning the database into a stream
৭ মিনিট পড়া মাঝারি · Intermediate Debezium · Kafka Connect

এই পাঠে যা শিখবেন

  • CDC কী, কেন nightly batch dump-এর চেয়ে শ্রেষ্ঠ
  • তিন পদ্ধতির trade-off — log-based, trigger-based, query-based
  • Debezium + Kafka Connect setup ও event format
  • Bangladesh-এর bank ও ecommerce-এ CDC-র বাস্তব use case

১ · CDC কেন দরকার?

একটি ব্যাংকের core banking system MySQL-এ। Risk team চায় — প্রতি transaction-এর immediate copy data lake-এ যাক, fraud model real-time scoring করুক। সরল উপায় — প্রতি ৫ মিনিটে SELECT * FROM transactions WHERE created_at > ?। কিন্তু এতে DB load বাড়ে, latency ৫ মিনিট, এবং DELETE/UPDATE মিস হয়।

CDCChange Data CaptureDatabase-এর change events-কে capture করে downstream system-এ pump করার technique। Source DB-র transaction log (binlog/WAL) থেকে read করায় source-এ minimum overhead। এই সমস্যার elegant সমাধান। DB-র নিজস্ব transaction log (MySQL-এর binlog, Postgres-এর WAL) পড়ে — প্রতিটি change event Kafka-তে publish। Source DB-তে query overhead নেই, latency সেকেন্ড-সাব-সেকেন্ড, এবং সব operation (insert/update/delete) capture।

মূল ধারণা

Database একটি state store। কিন্তু সেই state পৌঁছানোর জন্য একটি event log-ও আছে — transaction log। CDC সেই log-কে first-class API হিসেবে expose করে। ফলে DB একসাথে state store + event source হয়ে যায় — microservice, analytics, search index সবাই একই source-of-truth থেকে subscribe করতে পারে।

২ · তিন CDC পদ্ধতি

(ক) Query-based — সরল কিন্তু lossy

SELECT … WHERE updated_at > last_run। সবচেয়ে সরল।

  • Pros: কোনো special permission লাগে না, যেকোনো DB-তে কাজ করে।
  • Cons: DELETE detect হয় না (row চলে গেছে — কীভাবে জানবেন?); polling overhead; missed updates যদি একই second-এ একাধিক change হয়; latency = poll interval।

(খ) Trigger-based — invasive

DB trigger বসিয়ে — প্রতি INSERT/UPDATE/DELETE-এ একটি audit table-এ entry দিন। CDC consumer সেই audit table পড়ে।

  • Pros: সব operation capture, transactional consistency।
  • Cons: প্রতি write-এ extra DB work — latency বাড়ে, throughput কমে; schema বদলালে trigger update দরকার; production DB-তে DBA সচরাচর অনুমোদন দেন না।

(গ) Log-based — gold standard

DB-র native transaction log (MySQL binlog, Postgres WAL, SQL Server CDC, Oracle redo log) সরাসরি পড়া।

  • Pros: source-এ প্রায় শূন্য overhead; সব operation capture; sub-second latency; transactional ordering preserve।
  • Cons: DB-specific protocol, replication permission প্রয়োজন; initial snapshot + log streaming combine করা কঠিন; schema evolution-এ কেয়ার দরকার।

Modern data engineering-এ log-based CDC-ই default। বাকিগুলো legacy বা escape hatch।

৩ · MySQL binlog ও Postgres WAL — under the hood

MySQL binlog: প্রতিটি committed transaction binary log-এ লেখা হয় — replication-এর জন্য। binlog_format=ROW থাকলে — প্রতিটি row-level change (before + after image) capture। Debezium MySQL connector এই log পড়ে replica-র মতো।

Postgres WAL: Write-Ahead Log — প্রতিটি page-change WAL-এ লেখা হয় DB-তে commit-এর আগে। Logical replication slot তৈরি করে — Debezium সেই slot থেকে decoded change event পায়।

$$\text{transaction log} \;\Rightarrow\; \text{binlog/WAL} \;\Rightarrow\; \text{Debezium} \;\Rightarrow\; \text{Kafka topic}$$

ভাবুন একটি bank ledger বই। প্রতিটি deposit, withdrawal, transfer ক্রমানুসারে লেখা হয়। কেউ যদি এই বইয়ের carbon copy পেয়ে যান — তিনি কখনো branch-এ ফোন না করেও বুঝতে পারেন কোন account-এ কী ঘটল। CDC-র binlog ঠিক সেই carbon copy। DB কে আপনি বিরক্ত করছেন না — শুধু তার নিজস্ব log পড়ছেন।

৪ · Debezium — open-source CDC platform

DebeziumDebeziumRed Hat-এর open-source CDC platform (২০১৬)। Kafka Connect source connector হিসেবে চলে। MySQL, Postgres, MongoDB, SQL Server, Oracle, Cassandra সাপোর্ট। বিশ্বের production CDC-র ৭০%+ এতে। Red Hat-এর open-source project (২০১৬)। Kafka Connect-এর সাথে integrate — প্রতিটি DB-র জন্য একটি source connector। Configuration JSON-এ; কোনো code নেই।

  • Initial snapshot: connector শুরুতে পুরো table read করে (consistent snapshot)।
  • Streaming phase: snapshot শেষে binlog/WAL position থেকে real-time event stream।
  • Topic per table: dbserver.dbname.tablename format।
  • Schema registry: Avro/Protobuf schema track — schema evolution handle।

৫ · Debezium event format

প্রতিটি event-এ থাকে — before (পরিবর্তনের আগের state), after (পরের state), op (c=create, u=update, d=delete, r=read snapshot), source (DB metadata)।

op="d" event-এ after=null, before-এ মুছে যাওয়া row। এই পদ্ধতিতে delete-ও capture হয় — query-based-এ যেটা impossible।

৬ · Kafka Connect — execution layer

Debezium নিজে service নয় — Kafka Connect-এর plugin। Kafka Connect cluster JVM workers চালায়, connector configuration accept করে, fault tolerance + scaling সামলায়। দু'টি mode:

  • Standalone: single JVM, dev/test।
  • Distributed: multiple worker, shared metadata Kafka topic-এ। Production default।

৭ · CDC architecture — bank ledger replication

CDC Pipeline — Bank Ledger Replication MySQL binlog → Debezium → Kafka → consumers 🏦 Core Bank DB MySQL · transactions binlog ROW format ~10K txn/min 📡 Debezium Kafka Connect MySQL connector snapshot + stream 📨 Kafka bank.core.txn key=account_id retention: 7 days 📊 Data Lake S3 + Iceberg 🔍 Fraud (Flink) real-time score 🔎 Elasticsearch customer 360 Event payload (JSON) { "op": "u", "before": { "balance": 12000.00, "acc": "01711..." }, "after": { "balance": 11500.00, "acc": "01711..." }, "source": { "db": "core", "table": "txn", "ts_ms": ... } } single source-of-truth · multiple downstream consumers · zero polling load
Debezium MySQL binlog পড়ে Kafka topic-এ event publish করে। Multiple consumer (data lake, fraud detection, search) একই stream subscribe করে — DB-তে কোনো বাড়তি query load নেই।

৮ · Debezium configuration — MySQL connector

Kafka Connect REST API-তে এই JSON POST করলে — connector চালু হয়।

JSON · Debezium MySQL connector config
{
  "name": "bank-core-mysql",
  "config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "tasks.max": "1",

    "database.hostname": "mysql.bank.local",
    "database.port":     "3306",
    "database.user":     "debezium",
    "database.password": "${file:/secrets/db.properties:pwd}",
    "database.server.id": "184054",
    "database.server.name": "bank",

    "database.include.list": "core",
    "table.include.list":    "core.transactions,core.accounts",

    "schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
    "schema.history.internal.kafka.topic": "schema-history.bank",

    "snapshot.mode":  "initial",
    "snapshot.locking.mode": "minimal",
    "include.schema.changes": "true",

    "decimal.handling.mode": "string",
    "time.precision.mode":   "connect",

    "transforms": "unwrap",
    "transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState",
    "transforms.unwrap.drop.tombstones": "false",
    "transforms.unwrap.delete.handling.mode": "rewrite"
  }
}

    
snapshot.mode=initial — connector শুরুতে full table snapshot, তারপর binlog stream। decimal.handling.mode=string — money column-এ precision loss এড়াতে। ExtractNewRecordState SMT (Single Message Transform) Debezium-এর nested envelope থেকে শুধু after field বের করে — downstream consumer-এর জন্য সরল payload।

৯ · Bash — connector deploy ও monitor

Bash · Kafka Connect REST API
# Connector POST
curl -s -X POST -H "Content-Type: application/json" \
  --data @bank-core-mysql.json \
  http://kafka-connect:8083/connectors

# Status check
curl -s http://kafka-connect:8083/connectors/bank-core-mysql/status | jq

# Topic-এ event দেখুন
kafka-console-consumer.sh \
  --bootstrap-server kafka:9092 \
  --topic bank.core.transactions \
  --from-beginning \
  --max-messages 5

# Lag check (snapshot শেষ কিনা)
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
  --describe --group connect-bank-core-mysql

    
Connector deploy করার পর status RUNNING দেখায়। প্রথম কিছু মিনিট snapshot — সব row op="r" (read) হিসেবে publish। তারপর live binlog tailing — INSERT "c", UPDATE "u", DELETE "d"।

১০ · Bangladesh use cases

  • Bank ledger → data lake: core banking MySQL থেকে S3 Iceberg-এ near-real-time replication। nightly batch dump-এর বদলে — risk team-এর জন্য always-fresh data।
  • Daraz inventory sync: central catalog DB থেকে Elasticsearch search index, Redis cache, ও warehouse system-এ propagation।
  • Microservice eventing: "outbox pattern" — service local DB-তে domain event লেখে; Debezium সেটাকে Kafka-তে publish। Distributed transaction এড়ানোর সবচেয়ে নির্ভরযোগ্য pattern।
  • BTRC/regulatory reporting: Telco-র subscriber DB-র change real-time central regulator system-এ পাঠানো।
  • Audit trail: CDC stream Iceberg-এ append-only — full history of every change, GDPR/audit-ready।
CDC PII (phone, NID, account) carry করে। Topic-level ACL, encryption-at-rest, Schema Registry-তে field masking অপরিহার্য। Bangladesh-এর Personal Data Protection বিল-এর আলোকে এই control থাকা চাই।

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ একটি Bangladeshi bank-এর core banking system থেকে data warehouse-এ "প্রতি ১৫ মিনিট" batch sync চলে। DBA বলছেন প্রতি batch-এ DB load বাড়ছে। আপনি CDC সুপারিশ করছেন — DBA-কে কীভাবে convince করবেন?

DBA-রা stability conservative থাকেন — যৌক্তিক কারণে। Core banking-এ ১ সেকেন্ড downtime মানে BDT লক্ষ-কোটি হারানো। তাই argument data-driven ও risk-aware হতে হবে।

Argument 1 — Source load comparison:

  • Current batch: প্রতি ১৫ মিনিটে SELECT * FROM transactions WHERE updated_at > ?। যদি ১০ লক্ষ row scan হয় — buffer pool eviction, lock contention, query plan disruption।
  • CDC log-based: binlog একটি sequential file — DB এটি rapidly fsync করে disk-এ। Debezium সেই file-ই পড়ে (replica-র মতো)। DB-র query engine-এ কোনো load নেই; শুধু binlog reader-এর কিছু network bandwidth।
  • Empirical: large bank-এ batch query CPU ১৫-২৫% spike দেখায়; CDC ১-৩%।

Argument 2 — Replication-এর সমান সাবধানতা:

  • "Binlog তো replica-র জন্য — আপনার team replication চালাচ্ছেন না কী?" — হ্যাঁ, prod-এ standby MySQL আছে। Debezium সেই same protocol ব্যবহার করে — শুধু আরেকটা replica যেন।
  • Performance impact prod-এ একই — replica-র মতো।

Argument 3 — Risk mitigation:

  • প্রথমে staging-এ চালান, ২ সপ্তাহ। সব load metric (CPU, IO, replication lag) compare।
  • Production-এ read-replica থেকে CDC — primary-তে কোনো ছোঁয়া নেই। DBA-র সবচেয়ে বড় ভয় দূর।
  • Snapshot phase carefully tune — snapshot.locking.mode=minimal বা none, off-peak হোক।
  • Connector পুরোপুরি কোনো ক্ষতিকর effect-এ pause/stop করার ability — DBA-র control।

Argument 4 — Business value:

  • Latency ১৫ min → ১-২ second — fraud detection-এ এটা গেম-চেঞ্জার। ভাবুন ১০ মিনিটে ৫০ লক্ষ TK suspicious transfer; আপনি ১ minute-এ ধরে ৫ minute-এ block করতে পারবেন।
  • DELETE detection — current batch সম্পূর্ণ miss করে, যা compliance audit-এ ভয়াবহ।
  • Multiple consumer একই stream subscribe — risk, fraud, KYC, marketing — প্রতি team-এর আলাদা batch query bypass।

Argument 5 — Industry precedent:

  • JPMorgan, Goldman, ING — সবাই Debezium-based CDC production-এ চালায়।
  • Bangladesh-এ Brac Bank, City Bank-এর modern data team-এ এটা চালু হচ্ছে।
  • "Industry standard" বললে DBA-রা আরো comfortable।

DBA-র objections আগেই address করুন:

  • "Binlog disk-fill হবে" → retention policy + monitoring; standby-র জন্য already retained।
  • "Schema change-এ break হবে" → Debezium schema evolution support; DDL events captured।
  • "Network failure-এ data loss" → checkpoint + replay from last LSN — exactly-once recovery।

মূল উপলব্ধি: CDC sales pitch শুধু feature list নয় — risk mitigation plan। DBA-র মতো production-conscious stakeholder-কে শুধু performance data, gradual rollout, এবং rollback plan দেখাতে পারলেই তারা buy-in দেন। Engineering = communication + persuasion + technology।

প্র ০২ Daraz-এর inventory DB-তে CDC বসাচ্ছেন — search index, cache, warehouse system সবাই subscribe করবে। কিন্তু স্কিমা একদিন বদলে গেল (নতুন column যোগ)। কী হবে?

Schema evolution distributed system-এর সবচেয়ে কঠিন সমস্যাগুলোর একটি। CDC pipeline-এ এটা বিশেষভাবে — কারণ producer (DB) আর consumer-এর version unsynchronized হতে পারে দিনের পর দিন।

Debezium কীভাবে handle করে:

  • include.schema.changes=true — DDL event আলাদা topic-এ publish হয়।
  • Connector internal "schema history" topic-এ সব DDL track করে; binlog-এ এক বছর আগের event এলেও — সেই version-এর schema দিয়ে decode সম্ভব।
  • নতুন event-এ নতুন field automatically appear।

Consumer side challenge:

  • Search index (Elasticsearch): dynamic mapping enabled থাকলে — নতুন field auto-add। কিন্তু wrong type-এ infer হতে পারে। Solution: explicit mapping template।
  • Cache (Redis): JSON store — নতুন field harmless, ignore হবে। কিন্তু কোনো consumer যদি field absence assume করে — bug।
  • Warehouse (Iceberg/Delta): এদের schema evolution native — নতুন column add হলে old data-তে NULL। কিন্তু column drop, type change — destructive change, careful migration লাগে।

Schema Registry — best practice:

  • Avro/Protobuf serialization + Confluent Schema Registry।
  • Compatibility mode: BACKWARD — নতুন schema পুরোনো consumer-এ deserialize করতে পারে। নতুন field-এর default value থাকতে হবে।
  • FULL compatibility — দুদিকেই compatible। সবচেয়ে নিরাপদ।
  • Producer (Debezium) Schema Registry-তে register; consumer fetch করে dynamic deserialize।

Breaking changes — কী করবেন:

  • Column drop: deprecated mark করুন, ৩-৬ মাস wait, তারপর drop। Consumer-দের update করতে দিন।
  • Type change (VARCHAR → INT): never in-place — নতুন column add, app dual-write, পুরোনো deprecate।
  • Required new column: nullable হিসেবে add, default value, কোডে slowly mandatory।

Daraz-specific scenario:

  • "discount_pct" নতুন column add হলো inventory table-এ।
  • Debezium event-এ after.discount_pct immediately appear।
  • Search team এই field index করতে চাইলে — Elasticsearch mapping update; reindex existing docs (কারণ পুরোনো event-এ ছিল না)।
  • Cache → no-op, JSON ignore।
  • Warehouse → Iceberg ALTER TABLE ADD COLUMN; পুরোনো partition-এ NULL।
  • Analytics dashboard query-এ COALESCE(discount_pct, 0) defensive।

Communication & process:

  • "Schema-as-code" repo — সব table definition Git-এ। Pull request দিয়ে যেকোনো DDL।
  • Slack channel #cdc-schema-changes — DDL deploy-এর আগেই broadcast।
  • Contract testing — consumer-গুলো sample CDC payload-এর বিরুদ্ধে CI-তে validate।

মূল উপলব্ধি: CDC একদিকে producer DB, অন্যদিকে diverse consumer-এর contract। Schema হলো সেই contract-এর ভাষা। Schema Registry + backward-compat + clear process — এই তিন ছাড়া CDC pipeline ৬ মাসে production নরকে পরিণত হবে। Tool যত ভালো হোক, governance ছাড়া অসম্ভব।

প্র ০৩ Outbox pattern কী, এবং কেন এটা microservice-এ "dual write" সমস্যার সবচেয়ে নির্ভরযোগ্য সমাধান?

Microservice architecture-এ একটি classic problem — service local DB-তে data সংরক্ষণ করে এবং Kafka-তে event publish করে। দু'টি ভিন্ন system-এ atomic write কিভাবে?

Naive approach (broken):

// pseudo
db.save(order);          // step 1
kafka.publish(event);    // step 2
  • Step 1 success, step 2 fail (network, broker down) → DB-তে order আছে কিন্তু event missing। Inventory adjust হলো না, customer-কে confirmation যায়নি।
  • Step 1 success, step 2 success, কিন্তু crash before commit → duplicate event সম্ভব।
  • "Two-phase commit (XA)" — distributed transaction — performance horrendous, ops nightmare, modern systems-এ rejected।

Outbox pattern:

  • একই DB-তে একটি outbox table তৈরি।
  • Order save এবং outbox-এ event row insert — দু'টোই একই DB transaction-এ → atomic।
  • Debezium সেই outbox table-এ CDC বসায় → Kafka-তে event publish।
  • Outbox row delete বা archive (idempotent flag)।
BEGIN;
  INSERT INTO orders (id, user, amount) VALUES (...);
  INSERT INTO outbox (event_type, payload, ts)
    VALUES ('OrderCreated', '{...}', now());
COMMIT;
-- Debezium captures the outbox INSERT, publishes to Kafka

কেন এটা bulletproof:

  • Atomic: দু'টি write এক transaction-এ — হয় দু'টোই save, না হলে কোনোটাই না।
  • Reliable delivery: Debezium binlog-এ outbox INSERT দেখলেই — Kafka-তে publish। Kafka temporarily down থাকলেও — later replay।
  • Exactly-once: Debezium offset checkpoint + Kafka transactional sink → প্রতিটি outbox row ঠিক একবার Kafka-তে।
  • No service code complexity: service শুধু একটা সাধারণ DB transaction লেখে। Kafka client, retry logic, circuit breaker — কিছুই দরকার নেই।

Bangladesh use case (bKash):

  • Money send — transactions table-এ row + outbox-এ {type: TransferComplete, sender, receiver, amount}।
  • Atomic commit।
  • Debezium event Kafka topic bkash.outbox.transfer-এ যায়।
  • Notification service event consume → SMS পাঠায়।
  • Fraud service event consume → real-time score।
  • Ledger service event consume → ledger DB-তে update।
  • Service crash বা Kafka outage হলেও — outbox row binlog-এ আছে, Debezium recovery-এ replay।

Implementation tips:

  • Outbox row-এ event_id UUID — consumer-এ idempotency check।
  • Debezium OutboxEventRouter SMT — outbox row থেকে appropriate Kafka topic-এ route।
  • Old outbox rows TTL/cleanup job — DB bloat avoid।
  • Schema versioning event payload-এ — schema change সামাল।

Trade-offs:

  • Latency: outbox INSERT → Debezium read → Kafka publish — সাধারণত ১-৫ সেকেন্ড। Sub-100ms চাইলে inadequate।
  • Service-DB-Debezium ৩-component dependency — operational overhead।
  • Outbox table যদি hot হয় — DB write amplification।

মূল উপলব্ধি: "Just send to Kafka after DB commit" simple-looking কিন্তু catastrophically broken at scale। Outbox pattern একটি database transaction-এর atomicity-কে distributed event delivery-র correctness-এ rope করে। বাংলাদেশ ও বিশ্বের সব serious microservice architecture (bKash, Pathao backend, Daraz checkout) এই pattern-এ চলে। CDC ছাড়া এই pattern impossible — তাই CDC শুধু analytics tool নয়, microservice-এর basic infrastructure।

প্র ০৪ আপনি একটা Bangladeshi insurance startup-এ join করলেন। Production MySQL-এ ১০০ table আছে, পুরোনো batch ETL ১২ ঘণ্টায় সব dump করে। CDC migration plan কী?

Greenfield CDC সহজ; existing batch থেকে migration কঠিন। সাবধানতার সাথে phased rollout লাগবে — production কে কখনোই disrupt করা যাবে না।

Phase 0 — Discovery (২ সপ্তাহ):

  • ১০০ table-এর ক্রমিক list — কোনটা PII, কোনটা high-volume, কোনটা rarely-changing।
  • Downstream consumers map — কারা batch dump-এ depend। Risk team? Reporting? Marketing?
  • Current batch SLA — সকাল ৬টার মধ্যে data warehouse-এ ready হতে হবে?
  • DBA stakeholder interview — concerns, infrastructure (replica আছে?)।
  • MySQL config check: binlog_format=ROW, binlog_row_image=FULL, retention যথেষ্ট কিনা।

Phase 1 — Infrastructure (৩-৪ সপ্তাহ):

  • Kafka cluster setup (managed: AWS MSK, Confluent Cloud) বা self-host। ৩-broker minimum।
  • Kafka Connect distributed cluster — ৩ worker।
  • Schema Registry (Confluent বা Apicurio)।
  • Monitoring: Prometheus + Grafana + Kafka Connect metrics + connector lag alerts।
  • MySQL read-replica যদি না থাকে — production team-এর সাথে কাজ করে set up। CDC এই replica থেকে।
  • Network/security: Kafka Connect → MySQL VPC peering, TLS, ACL।

Phase 2 — Pilot (৪-৬ সপ্তাহ):

  • ৫টা low-risk table বাছুন — যেমন products, categories, policy_types। Volume মাঝারি, schema stable।
  • Debezium connector deploy। Initial snapshot off-peak (রাত ২টা)।
  • Kafka topic-এ event flow verify। Schema Registry-তে schema register।
  • Sink consumer তৈরি — Iceberg-এ append/upsert। Existing batch parallel চালু থাকবে।
  • Daily reconciliation: CDC-derived warehouse table vs batch-derived — count, sum, max(updated_at) match কিনা।
  • ২ সপ্তাহ smooth চললে — Phase 3।

Phase 3 — Expansion (৮-১২ সপ্তাহ):

  • Table-গুলো group-এ migrate (১০ table প্রতি সপ্তাহ)।
  • High-volume / high-risk table (e.g., claims, payments) সবচেয়ে শেষে — সব lesson learned apply করার পর।
  • Stakeholder communication — risk, marketing team-এ access bridge (CDC stream → আগের warehouse table-এর adapter)।
  • Data quality framework — CDC-derived data-তে freshness, completeness, accuracy check।

Phase 4 — Cutover (২ সপ্তাহ):

  • সব table CDC-তে migrate, ১ মাস dual-running।
  • Reconciliation report — discrepancy <০.০১% হলে batch decommission।
  • Old batch jobs disable, archive, document the change।
  • Cost saving compute — DBA-কে দেখান (CFO-কে justify করার জন্য)।

Risk mitigation throughout:

  • Rollback plan ready: connector pause + batch resume — ১৫ মিনিটের মধ্যে।
  • On-call rotation Phase 2 থেকে।
  • Documentation runbook: connector restart, snapshot trigger, lag alert response।
  • Kafka retention conservative শুরুতে (৭ days), পরে কমান।

Common pitfalls:

  • "সব table একসাথে migrate" — অসম্ভব। Connector load, schema issue, downstream surprise — হবেই।
  • "Pilot skip করা" — production-এ first try কখনোই না।
  • "Reconciliation skip করা" — silent data drift detect না হলে — ৩ মাস পর audit-এ ধরা পড়লে catastrophic।
  • "Schema Registry skip করা" — short-term সহজ, long-term debt।
  • "Stakeholder communicate না করা" — ML team batch table-এ depend করছে, একদিন তাদের না জানিয়ে cutover — trust ধ্বংস।

Timeline summary: ২০-২৪ সপ্তাহ (৫-৬ মাস) — সাবধানী, gradual। দ্রুত করতে চাইলে production accident certain।

Business case slide (CTO-কে):

  • Latency: ১২ ঘণ্টা → ৩০ সেকেন্ড। Risk team realtime fraud, claims team near-real-time visibility।
  • DB load: peak query 25% → 3%। DB infra scale-down possible।
  • Reliability: batch failure (~মাসে ১-২ বার) → fault-tolerant streaming।
  • Cost: ETL Hadoop cluster ($৩K/মাস) → Kafka + Connect ($১.৫K/মাস)।
  • Future-proof: microservice eventing, real-time dashboard — সব unlocked।

মূল উপলব্ধি: CDC migration একটা technology project-এর চেয়ে বেশি — organizational change। Engineer-এর কাজ — risk-aware, communication-rich, gradual rollout। "Big bang" cutover-এ blast radius বড়; phased approach-এ each step revertible। Bangladesh-এর insurance/banking-এ এই discipline-ই প্রকৃত মূল্য আনে।

অনুশীলন

  1. পদ্ধতি বাছুন: একটি startup MongoDB থেকে CDC চাচ্ছে। কোন পদ্ধতি ও কেন?

    Log-based। MongoDB-র oplog (operations log) replication-এর জন্য — Debezium MongoDB connector এই oplog পড়ে। Source MongoDB-তে কোনো query overhead নেই, full insert/update/delete capture, replica set requirement (production-এ এমনিতেই থাকে)।

    Trigger-based MongoDB-তে নেই (no native triggers); query-based find({updated_at: {$gt: ?}}) সম্ভব কিন্তু DELETE miss হবে।

  2. Debezium event পড়ুন: এই event-এ কী operation? কী বদলেছে?
    {
      "op": "u",
      "before": {"id": 7, "balance": 5000},
      "after":  {"id": 7, "balance": 4500},
      "source": {"table": "accounts"}
    }

    op="u" = UPDATE। accounts table-এ id=7 row-এর balance ৫,০০০ → ৪,৫০০ (৫০০ withdraw)।

    Downstream consumer-এ এই event দিয়ে — fraud check (sudden ৫০০ TK debit?), notification (SMS), warehouse upsert সব trigger।

  3. Design করুন: Daraz-এর order table-এ CDC বসিয়ে — search index, fraud detection, notification তিনটি system update করতে চান। Kafka topic structure কেমন হবে?
    • Single topic, multiple consumers: daraz.shop.orders — তিনটি consumer group (search-indexer, fraud-detector, notif-sender) একই topic থেকে independent offset-এ পড়বে।
    • Key: order_id — একই order-এর সব event একই partition-এ → ordering preserved।
    • Partition count: ১২-২৪ — peak rate ও parallelism অনুযায়ী।
    • Retention: ৭ days (replay buffer)।
    • SMT: ExtractNewRecordState — payload simplified।

    fan-out তিনটি consumer একে অপরকে ব্যাক করে না; একজন slow হলে others affected না (Kafka-র killer feature)।

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

কোড রানার কাজ না করলে? Debezium full stack locally চালাতে — Docker Compose-এ MySQL + Kafka + Kafka Connect + Debezium plugin। অথবা Google Colab এ event payload Python-এ parse করে পরীক্ষা করুন।
পূর্ববর্তী পাঠ
পাঠ ২০ · Apache Flink পরিচিতি