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
- Draw the path and name every hop.
- Write the topic, the key, the group, and the checkpoint.
- Keep the warehouse as the system of record.
- Score the pack and mark every number you invented as a choice.
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 personThe night file remains the batch close. It is not this path.
Event-flow diagrams
One pick of 2 for FX-100:
- The warehouse commits. The binary log has a position.
- The connector publishes one change, keyed by SKU, after the snapshot phase is finished.
serving-totalapplies it once and checkpoints.serving_stockshows 78 and anas_of.- 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
| Topic | Key | Who writes | Who may change stock |
|---|---|---|---|
| stock.picked | sku | CDC connector | group serving-total only |
| stock.picked.dlq | sku | the consumer, on a rejected event | nobody |
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
| Signal | Page when |
|---|---|
| Consumer lag | Above the limit you wrote |
| Checkpoint age | The query has not committed within the age you wrote |
| Gate failures | A dead-letter record is produced |
| Serving age | now - 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
| Risk | How you notice | Control |
|---|---|---|
| Double deduct | Quantity falls by twice the pick | One group, pick id or source position stored |
| Lost pick | Offset moved, quantity unchanged | Commit after apply |
| Blank SKU published | Name empty on the tile | Gate, previous row kept, dead letter |
| Second snapshot | History duplicated | Do not snapshot to catch up |
| Stale green badge | Tile age past the limit | Compute fresh from as_of |
| Agent posted stock | Warehouse row without a picker | No write tool, approval, request id |
| Secret in a prompt | password= in a transcript | Refuse, rotate |
Recovery strategy
- Bad event: dead-letter it, leave
serving_stockon the previous good quantity. - Consumer crash: resume from the checkpoint and the committed offset. Do not start at zero unless you mean to rebuild.
- Query change: new checkpoint directory.
- Repeated source position: skip.
- Leaked connector secret: rotate, and confirm new audit rows are clean.
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.
- Days 1–30: topic, key, one consumer group, connector snapshot and tail, gate. Done when one pick changes
serving_stockonce. - Days 31–60: checkpoint, event-time window, dead-letter topic, tile with
as_of. Done when a late event follows the rule you wrote and a blank SKU does not publish. - Days 61–90: alert to a named person, audit for replay, agent draft with approval. Done when a secret in a prompt is refused and a second request id does not post.
Rubric
Score each row 0 to 3. The pack is ready when every row is at least 2 and none is 0.
| Row | 0 | 2 | 3 |
|---|---|---|---|
| Path | A logo slide | Warehouse, log, topic, job, tile | A colleague can point at the write stop |
| Kafka | No key, two deduct groups | Key is the SKU, one deduct group | Idle consumers and replication are written as choices |
| CDC | Polling balances | Snapshot then tail, position stored | A repeated position does not move the quantity |
| Serving | Night file labeled live | Tile reads serving_stock and an age | Stale is visible and does not swap in the night file |
| Agent | Posts the warehouse | Draft only, person approves | Request id and secret check both hold |
Self-review checklist
- [ ] The diagram matches the topic table. The night file is not the stream.
- [ ] One consumer group deducts. The key is the SKU.
- [ ] CDC is snapshot then binary log. A source position is applied once.
- [ ] The Spark query has a checkpoint. A changed query has a new directory.
- [ ] The gate holds the previous serving row.
- [ ] The tile reads
serving_stockand computes age. - [ ] The dead-letter topic has an error and an offset, and no secret.
- [ ] The alert names a person and does not claim to pause the cluster.
- [ ] The agent cannot post. An approved post is idempotent.
- [ ] Partition count, lateness, lag, and age limits are marked as choices.
- [ ] No currency figure and no uptime percent was invented.
Teacher walkthrough: Monday's pack
All figures are illustrative.
- Read the diagram from the warehouse down to the draft. Say which arrow is allowed to change
serving_stock. - Point at the group name
serving-totaland the topic keysku. - Show a repeated
binlog:100leaving the quantity at 78. - Validation: the floor tile quantity equals
serving_stock, a prompt withpassword=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 FalseA 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:
- Which group may deduct?
- What does the floor tile name after the fix?
- What stays if the SKU is blank?
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:
- You include the architecture, the event flow, the topic design, CDC, the streaming query, monitoring, the dashboard, and the agent rule.
- You include governance, security, risks, recovery, cost, and a roadmap.
- You score yourself with the rubric and mark every limit as a choice.
- You name the system of record and the check that a repeated event does not apply twice.
- You do not claim a price, a legal duty, or a latency the product page did not state.
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
- What is the system of record for on-hand quantity?
- What does the floor tile read?
- What is the Kafka key on
stock.picked? - What happens to a repeated source position?
- What is the agent forbidden to do?
Answers:
- The warehouse database.
serving_stock, and it computes age.- The SKU.
- The apply step skips it.
- 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.