learntodriveai.dev/Data Engineering/Streaming Sensor Data with Kafka
Data EngineeringProject 107 units

Streaming Sensor Data with Kafka

Nalini PersaudChief Operating Officer · Gold mining company · Bartica, Guyana
Meeting transcript · from Nalini
We lost 14 hours of production last quarter because equipment failures weren't caught until the shift report. … I want to know when something is wrong in minutes. Not hours. Minutes.
Chat with Nalini

What you hand back

  • A Kafka stack that survives restarts
  • Produced and landed counts that match
  • Anomaly flags separating sensor dropout from equipment faults
  • A health sensor that detects a stopped consumer
  • A read-only data quality agent with findings
  • A delivery summary and evidence folder

7 units

  1. Unit 1: Meet Nalini and stand up the infrastructure

    Question Nalini about the historian and the mine's constraints, then stand up Kafka in Docker Compose and prove it survives a restart.

    Open unit 1
  2. Unit 2: Build the streaming pipeline

    Design the sensor topic, build the producer and consumer, and compare messages published against rows landed in BigQuery.

    Open unit 2
  3. Unit 3: Verify the hard way — restart, count, and break things

    Kill the consumer mid-stream, restart it, count both sides, handle duplicates, and fix offset commit timing if messages went missing.

    Open unit 3
  4. Unit 4: Land streaming data in the warehouse

    Build the dbt staging, one-minute aggregation and anomaly models, and check that sensor dropout is flagged apart from threshold exceedance.

    Open unit 4
  5. Unit 5: Monitor the monitor

    Add consumer metrics and a Dagster health sensor, then stop the consumer and measure how long detection takes.

    Open unit 5
  6. Unit 6: Delegate and connect — your first custom agent

    Define a read-only data quality agent, set MCP permissions, assess a Kafka MCP server, and configure a second AI tool.

    Open unit 6
  7. Unit 7: Close out — deliver to Nalini

    Send Nalini the delivery summary, handle her request for more data, update the README, and push the finished project.

    Open unit 7
Read the full brief

You're building a streaming data pipeline for a gold mine processing plant near Bartica, Guyana — ingesting sensor readings through Kafka, landing them in BigQuery, transforming them through dbt into anomaly detection, and alerting on equipment problems in minutes.

The discipline skills: Kafka fundamentals (topics, partitions, consumer groups, offsets, at-least-once delivery), Docker Compose for multi-container infrastructure, streaming-specific monitoring (offset lag, consumer group health), and end-to-end count verification between producer and consumer.

The AI-direction lesson: delegation. You'll design your first custom AI agent — not directing AI in real time, but defining a worker: what it does, what it can access, what it cannot touch. A data quality agent with read-only staging access reports findings for you to evaluate. The same agent with write access might "fix" issues it finds. The scope decision is yours. You'll also encounter a second AI tool for the first time, and discover that the infrastructure patterns you've built — project memory, skills, MCP connections — transfer across tools. The other hard part: AI defaults that work on first run don't survive a restart. Docker volumes, Kafka offset persistence, consumer commit behavior — the configuration AI generates passes a demo. You verify by restarting.

Your Role

You're building Nalini's streaming pipeline. Everything so far has been batch. Now the pipeline never stops running. Health isn't "did it complete?" but "is it keeping up?" You design a custom agent and encounter a second AI tool.

What's New

Last time you built enforceable data contracts with CI/CD enforcement, wrote your first skill and hooks, and extracted semi-structured data from MongoDB. The pipeline's promises became code.

This time the ingestion paradigm changes entirely. Kafka introduces continuous event streaming — messages flowing through topics, consumers tracking their position with offsets, and a delivery guarantee (at-least-once) that means duplicates are a system property, not a bug. Docker Compose stands up the multi-container infrastructure. The default configuration AI generates works on the first run. It may not survive a restart.

The hard part is that streaming failures are silent in a way batch failures aren't. A consumer that commits its offset before writing to the database loses messages without raising an error. You find out by counting — produced on one side, consumed on the other — and if the numbers don't match, nobody told you.

Tools

  • Apache Kafka (Docker, KRaft mode) — streaming platform (new this project)
  • Docker / Docker Compose — container infrastructure (new this project)
  • Python — producer and consumer scripts
  • BigQuery — cloud warehouse
  • dbt Core with BigQuery adapter — transformation
  • Dagster — orchestration and streaming health monitoring
  • DuckDB — local development
  • Claude Code — AI directing, custom agents (new: delegation)
  • Codex CLI — second AI tool (new this project)
  • Git / GitHub — version control

Materials

You'll receive:

  • Historian export — one 16-hour production day (06:00 to 22:00) of sensor readings from the processing plant, about one reading per sensor per minute, with known anomalies embedded in the data
  • Sensor metadata — 25 sensors with their types, equipment assignments, normal operating ranges, and alert thresholds
  • Project governance file — CLAUDE.md with the project context, work breakdown, and verification targets
Materials · 3 files
Start Project 10

You work at a computer with a terminal. Signed in, your place is saved.