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

Real-Time Analytics & Dashboards

Lesson opener

In one line: A live KPI reads a serving row that has an age. It does not read the topic.

Why it matters: Northline's sales screen said FX-100 had 80 units while the serving job had already applied the pick to 78. The chart was bound to the night file. A "live" title did not change the query. Figures are illustrative. They are not a refresh promise.

Before this lesson: Lesson 7. You know the serving row updates only when the gate passes.

What you will be able to do

Prerequisites

This lesson does not add a Kafka connector to Power BI. The report reads a table the stream job publishes. You measure how old that table is. The age limit in the example is 5 minutes because the walkthrough chooses 5 minutes.

What the screen is allowed to show

Plain English: A live KPI is a query over a serving row: SKU, quantity, and as_of. Latency is now - as_of, in the same clock you write down. If you allow 5 minutes, a row older than that is stale. The screen should say so. It should not keep a green "live" badge.

An operational dashboard is for people who act during the day, such as a short-pick warning. It uses the serving table. A finance pack that must match the night file uses the night file. Do not point both visuals at whichever table loaded last.

Business monitoring is the age, the lag from lesson 7, and the count of gated-out events. A pretty chart with no age is not monitoring.

Teacher walkthrough: 78, as of 16:11

All figures are illustrative. "Now" is 16:14. The allowance is 5 minutes.

  1. The serving row is FX-100, quantity 78, as_of 16:11.
  2. Age is 3 minutes. 3 is not greater than 5, so the row is fresh.
  3. The night file still says 80 at 16:00. The operational tile does not read it.
  4. Validation: at 16:20 the same row is 9 minutes old and stale.
def age_minutes(now_minute, as_of_minute):
    return now_minute - as_of_minute

def fresh(now_minute, as_of_minute, limit):
    return age_minutes(now_minute, as_of_minute) <= limit

assert fresh(14, 11, 5) is True
assert fresh(20, 11, 5) is False

Minutes here are minutes after 16:00, so 14 is 16:14 and 11 is 16:11.

A second workplace case

Two tiles, two queries. The floor tile reads serving_stock. The close tile reads night_file. Mixing them is a defect even if both numbers are "about stock."

def source_for(tile):
    if tile == "floor":
        return "serving_stock"
    if tile == "close":
        return "night_file"
    raise ValueError(tile)

assert source_for("floor") == "serving_stock"
assert source_for("close") == "night_file"

Failure example: the badge stayed green on the night file

Symptom: At 16:30 the tile still says 80 and shows a live badge. The last file export was 16:00.

Diagnosis: The visual queries the night file. Nothing wrote as_of from the serving job. The root cause is the wrong table, plus a badge that is not computed from age.

Correction: Point the operational visual at serving_stock. Compute age from as_of. Remove the badge when fresh is false. Leave the close pack on the night file.

Validation: Quantity on the floor tile equals the serving row, 78, while that row is fresh. When age exceeds 5 minutes, fresh is false.

def floor_qty(source, serving_qty, file_qty):
    if source != "serving_stock":
        raise ValueError(source)
    return serving_qty

assert floor_qty("serving_stock", 78, 80) == 78

Guided practice: set the limit and use it

Scenario: The team agrees the floor can act on a number up to 5 minutes old. as_of is minute 10. Now is minute 16. The night file says 80. The serving row says 78. Figures are illustrative.

Hints:

Complete solution:

Age is 6. 6 is greater than 5, so the row is stale. The floor tile still must not swap in 80 from the night file. It shows 78 and a stale state, or it shows stale and hides the number. It does not show 80.

def tile(serving_qty, now_minute, as_of_minute, limit):
    stale = (now_minute - as_of_minute) > limit
    return serving_qty, stale

assert tile(78, 16, 10, 5) == (78, True)

Independent practice

Pick one number a person uses during the day.

Acceptance criteria:

Common mistakes

  • Painting "live" on a night-file query.
  • Showing a green badge with no age check.
  • Using the batch number when the serving row is stale, as if stale meant "use the other table."
  • Claiming Power BI subscribes to the Kafka topic.

Quick check

  1. What does the operational tile query?
  2. How is age computed in this lesson?
  3. When is the 16:11 row stale if the limit is 5 minutes and now is 16:20?
  4. What does the close tile read?
  5. Does a stale serving row get replaced by the night file?

Answers:

  1. The serving table.
  2. Now minus as_of.
  3. Yes. The age is 9 minutes.
  4. The night file.
  5. No. It is marked stale. The night file is a different visual.

Quiz alignment

The quiz asks you to bind the KPI to the serving row, to compute staleness, and to keep the night file off the floor tile.

Lesson summary

Live means a serving row with an age you compute. The limit is a choice. The batch report stays on the batch table. The chart does not read Kafka.

Bridge to the next lesson

The next lesson lets an agent read the same event and draft an action. The draft is not allowed to post the warehouse. Bring the rule that the warehouse is still the system of record.