Rana Maninder Singh
Lesson 12 of 12Real-Time Data Engineering

Real-Time Data Engineering Capstone

Lesson opener

In one line: The pack is a path a second person can point at, from the warehouse commit to the screen and the draft.

Why it matters: Northline can name Kafka, a dashboard, and an agent, and still lose the 16:10 pick. The pack says which log is read, which group may deduct, which table the tile reads, and what happens when the same binlog position arrives twice. Figures are illustrative. They are not a service level, a price, or a legal duty.

Before this lesson: Lessons 1 to 11.

What you will be able to do

Prerequisites

The cited product pages are the Kafka 4.1 introduction (https://kafka.apache.org/41/getting-started/introduction/), the Spark 4.0.1 Structured Streaming guide (https://spark.apache.org/docs/4.0.1/structured-streaming-programming-guide.html), and the Debezium MySQL connector (https://debezium.io/documentation/reference/stable/connectors/mysql.html).

The pack

Real-time architecture

Warehouse database (system of record)
  |  committed pick in the binary log
  v
Debezium snapshot, then tail
  |
  v
Kafka topic stock.picked
  key = sku, group serving-total may deduct
  |
  v
Spark Structured Streaming
  checkpoint directory, event-time window, gate
  |
  +--> serving_stock (the operational tile)
  |
  +--> lake path for the closed windows you chose to keep
  |
  +--> dead-letter topic stock.picked.dlq
  |
  v
Power BI reads serving_stock, not the topic
  |
  v
Copilot or agent may draft
  warehouse post waits for a named person

The night file remains the batch close. It is not this path.

Event-flow diagrams

One pick of 2 for FX-100:

  1. The warehouse commits. The binary log has a position.
  2. The connector publishes one change, keyed by SKU, after the snapshot phase is finished.
  3. serving-total applies it once and checkpoints.
  4. serving_stock shows 78 and an as_of.
  5. A draft, if the written rule says so, does not post.

A second copy of the same source position does step 3 as a skip.

Kafka topic design

TopicKeyWho writesWho may change stock
stock.pickedskuCDC connectorgroup serving-total only
stock.picked.dlqskuthe consumer, on a rejected eventnobody

Partition count and replication factor are written on the pack as choices. Replication factor 1 is called out as "one disk." Extra consumers beyond the partition count sit idle. A second consumer group must not deduct.

CDC strategy

Snapshot once, then the binary log. Do not snapshot again to catch up. The value carries the new quantity and the source position. Apply a position once per SKU. The warehouse remains the system of record.

Streaming pipeline design

Ingest from stock.picked. Enrich from the product table. Reject a blank SKU, a non-positive quantity, or an unknown SKU. Window by event time. The allowed lateness is a number on the pack. Output mode matches whether the window row can still change. The sink overwrites (sku, window_start). Checkpoint directory is new when the query changes.

Monitoring framework

SignalPage when
Consumer lagAbove the limit you wrote
Checkpoint ageThe query has not committed within the age you wrote
Gate failuresA dead-letter record is produced
Serving agenow - as_of is past the tile limit

An alert emails a named person. It does not pause Kafka by itself.

Dashboard architecture

The floor tile reads serving_stock and shows stale when the age limit fails. The close tile reads the night file. Neither tile subscribes to Kafka. Copilot text, if any, is a draft from fields already on the serving row.

AI integration model

The agent has a read role on the serving event. It may draft when a written rule matches. It has no warehouse write tool and no CDC password. A post stores the approver and a request id. A second post with that id does not run.

Governance framework

One owner for serving-total. One owner for the connector user. A new required field is a schema change: consumers who cannot read it are upgraded first, or the field has a default. Topic names are not permissions. A replay from the dead-letter topic is an audit row.

Security controls

Connector credentials stay in the platform secret store. They are not in git, prompts, dead-letter values, or alert text. Readers of the topic cannot become the database user. The agent prompt is refused if it contains password=.

Risk register

RiskHow you noticeControl
Double deductQuantity falls by twice the pickOne group, pick id or source position stored
Lost pickOffset moved, quantity unchangedCommit after apply
Blank SKU publishedName empty on the tileGate, previous row kept, dead letter
Second snapshotHistory duplicatedDo not snapshot to catch up
Stale green badgeTile age past the limitCompute fresh from as_of
Agent posted stockWarehouse row without a pickerNo write tool, approval, request id
Secret in a promptpassword= in a transcriptRefuse, rotate

Recovery strategy

A recovery-time number is a choice the business writes. This pack does not invent one.

Cost model

Name what you would grow: partition count, replication factor, retention, and Spark state. Do not write a currency amount. More partitions than you have consumers in the deduct group does not make that group faster than the partition count.

Deployment roadmap

Illustrative 30, 60, and 90 days. Not a promise.

Rubric

Score each row 0 to 3. The pack is ready when every row is at least 2 and none is 0.

Row023
PathA logo slideWarehouse, log, topic, job, tileA colleague can point at the write stop
KafkaNo key, two deduct groupsKey is the SKU, one deduct groupIdle consumers and replication are written as choices
CDCPolling balancesSnapshot then tail, position storedA repeated position does not move the quantity
ServingNight file labeled liveTile reads serving_stock and an ageStale is visible and does not swap in the night file
AgentPosts the warehouseDraft only, person approvesRequest id and secret check both hold

Self-review checklist

Teacher walkthrough: Monday's pack

All figures are illustrative.

  1. Read the diagram from the warehouse down to the draft. Say which arrow is allowed to change serving_stock.
  2. Point at the group name serving-total and the topic key sku.
  3. Show a repeated binlog:100 leaving the quantity at 78.
  4. Validation: the floor tile quantity equals serving_stock, a prompt with password= is refused, and the dead-letter path does not deduct.
def apply_once(done, position, qty):
    if position in done:
        return done[position]
    done[position] = qty
    return qty

done = {}
assert apply_once(done, "binlog:100", 78) == 78
assert apply_once(done, "binlog:100", 78) == 78

def allow_prompt(text):
    return "password=" not in text

assert allow_prompt("FX-100 is 78") is True
assert allow_prompt("password=secret") is False

A second workplace case

A sister warehouse wants the same pack. Copy the stages. Do not copy the partition count, the lag limit, or the age limit as if they were laws. Write those numbers again for that warehouse.

Failure example: a poster of logos

Symptom: The slide shows a database, a cloud, and a robot. There is no topic, no group, and no as_of. The floor tile still reads the night file.

Diagnosis: The slide has vendors and no decisions. The root cause is a missing path. The services may exist. The pack does not say how a pick moves.

Correction: Replace the slide with the diagram and the tables in this lesson. Point the floor tile at serving_stock before the next review.

Validation: A colleague who was not in the build can answer: what owns on-hand quantity, what the tile reads, and what a repeated log position does.

Guided practice: finish two cells

Scenario: The topic table lists stock.picked. The group cell is blank. The tile still reads the night file. Figures are illustrative.

Hints:

Complete solution:

The group is serving-total. The key is the SKU. The floor tile reads serving_stock and its as_of. A blank SKU goes to stock.picked.dlq and leaves the previous serving quantity in place. You do not add a second group to finish the cell faster.

def owners():
    return ["serving-total"]

assert owners() == ["serving-total"]

Independent practice

Build the pack for one fact your employer changes during the day.

Acceptance criteria:

Common mistakes

  • Two consumer groups deducting.
  • Polling the table instead of the log.
  • A live badge on the night file.
  • A checkpoint reused after the query changes.
  • An agent with the connector password.
  • A retry loop with no dead-letter topic.

Quick check

  1. What is the system of record for on-hand quantity?
  2. What does the floor tile read?
  3. What is the Kafka key on stock.picked?
  4. What happens to a repeated source position?
  5. What is the agent forbidden to do?

Answers:

  1. The warehouse database.
  2. serving_stock, and it computes age.
  3. The SKU.
  4. The apply step skips it.
  5. Post the warehouse, or see a secret.

Quiz alignment

The quiz asks you to walk the path, to keep one deduct group, to skip a repeated log position, and to stop the tile and the agent from writing the warehouse by accident.

Lesson summary

The pack connects a committed change to a serving row a person can age. One group deducts. The log position is applied once. The chart reads the serving table. The agent drafts. Recovery skips, resumes, or dead-letters. It does not invent a second copy of the truth.

Bridge to the next lesson

This is the last lesson in Real-Time Data Engineering. There is no next lesson in this course. Take the pack to one table you can point at, and fill the choices with numbers you are willing to defend.