Install Β· Import transactions into MySQL Β· Build a transaction-risk dashboard
| Time | Segment | Activity |
|---|---|---|
| 0β10 min | Recap | From Kafka storage to business decisions |
| 10β20 min | What Is Grafana? | Architecture, users, and business value |
| 20β30 min | Grafana Mental Model | Data sources, queries, panels, dashboards |
| 30β45 min | Setup & Connection | Run MySQL and Grafana with Docker |
| 45β55 min | Existing Dataset | Import the Lecture 10 transactions CSV |
| 50β80 min | Dashboard Lab | Build a Stat, Bar Chart, and Table panel |
| 80β88 min | Interpretation | Read the dashboard and recommend an action |
| 88β90 min | Wrap-Up | Save the dashboard and preview Lecture 15 |
In Modules 2 and 3, you built the full backend: Kafka producers, consumers, MongoDB storage, alert routing, and windowing. All that work produces data β but the data lives in a database only engineers can query. Grafana closes this gap. It turns database queries into visual panels that refresh automatically, putting your streaming data in front of the people who need to act on it.
| What It Is | What It Isn't |
|---|---|
| A dashboard and visualisation platform | A database |
| A query builder (UI on top of your data) | A streaming system |
| An alerting layer with notification routing | A replacement for MongoDB/Kafka |
| Open source + free for self-hosted use | An analytics/BI tool (that's Metabase, Tableau) |
2014 β Created by Torkel Odegaard as a fork of Kibana
2021 β Grafana Labs valued at $3 billion
2024 β ~20 million users, 200,000+ organisations
Default monitoring dashboard at:
Netflix, PayPal, Booking.com, Zepto, Swiggy, Paytm, HDFC Securities
Career context: When you walk into a data-forward company's operations centre and see a wall of live charts, there is a 70%+ chance you are looking at Grafana. Understanding this tool positions you to have meaningful conversations about data infrastructure β as a manager, analyst, or product leader.
Unlike static BI tools, Grafana treats time as the primary dimension. Every dashboard has a time range (last 5 min, last 1 hour, custom). This makes it ideal for streaming data β you can zoom into the exact window when an alert fired.
Why MySQL? Grafana's MongoDB datasource requires an Enterprise entitlement that is not available for this course. MySQL is supported directly by Grafana, so every student can complete the lab without a paid plugin.
# Create one network so Grafana can reach MySQL by container name docker network create sda-analytics docker run -d \ --name sda-mysql \ --network sda-analytics \ -e MYSQL_ROOT_PASSWORD=admin \ -p 3306:3306 \ mysql:8.4 \ --local-infile=1 docker run -d \ --name grafana \ --network sda-analytics \ -p 3000:3000 \ -e GF_SECURITY_ADMIN_PASSWORD=admin \ grafana/grafana:latest # Open http://localhost:3000 and log in with admin / admin
Left sidebar β Connections β Data Sources β Add data source
Search "MySQL" β select the built-in datasource
Host: sda-mysql:3306 | Database: sda_course
User: grafana | Password: grafana | TLS/SSL mode: disabled for this local lab
Keep this browser tab open. Create the database and read-only user below, then return and click "Save & Test".
Reuse the transactions.csv generated in Lecture 10. This is the same dataset used in the Kafka fraud exercise; MySQL is only an additional analytics destination for Grafana.
Live-stream alternative: Instead of importing the CSV, run Lecture 10's consumer_store_mysql.py while transaction_producer.py is publishing. The consumer creates and continuously populates the same sda_course.transactions table used below. Its upsert makes Kafka replays safe.
| Field | Example | Business Meaning |
|---|---|---|
transaction_id | TXN-00847 | Unique transaction reference |
amount | 4500.00 | Transaction value imported as a decimal |
city | Mumbai | Location where the transaction occurred |
merchant | Amazon | Merchant receiving the payment |
timestamp | 2025-08-01 10:00:00 | Business event time imported as DATETIME |
is_fraud | true | Classroom fraud label |
Run these commands from the folder containing transactions.csv:
docker cp transactions.csv sda-mysql:/var/lib/mysql-files/transactions.csv docker exec -it sda-mysql mysql -uroot -padmin
Then run this SQL in the MySQL prompt:
CREATE DATABASE IF NOT EXISTS sda_course;
USE sda_course;
DROP TABLE IF EXISTS transactions;
CREATE TABLE transactions (
transaction_id VARCHAR(20) PRIMARY KEY,
user_id VARCHAR(20),
user_name VARCHAR(100),
card_last4 VARCHAR(4),
amount DECIMAL(12,2),
merchant VARCHAR(100),
city VARCHAR(50),
country VARCHAR(50),
lat DECIMAL(9,4),
lon DECIMAL(9,4),
`timestamp` DATETIME,
is_fraud VARCHAR(5),
ingested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
LOAD DATA INFILE '/var/lib/mysql-files/transactions.csv'
INTO TABLE transactions
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(transaction_id,user_id,user_name,card_last4,amount,merchant,
city,country,lat,lon,`timestamp`,is_fraud);
CREATE USER IF NOT EXISTS 'grafana'@'%' IDENTIFIED BY 'grafana';
GRANT SELECT ON sda_course.* TO 'grafana'@'%';
FLUSH PRIVILEGES;
SELECT COUNT(*) AS total_transactions,
SUM(is_fraud = 'true') AS flagged_transactions
FROM transactions;
Checkpoint: The deterministic Lecture 10 generator produces 2,003 transactions with 76 flagged records. Return to Grafana and click Save & Test.
Scenario: You manage fraud operations for a digital bank. Your team needs one screen that answers three questions: What percentage of transactions are flagged? Which cities carry the most transaction value? Which individual transactions require review?
Stat visualisation for an immediate risk KPI.
Bar Chart to compare geographic exposure.
Table listing transactions requiring attention.
Transaction Risk Overview β Lecture 14.This panel answers: βWhat percentage of transactions are labelled as fraud?β
SELECT 100.0 * SUM(is_fraud = 'true') / COUNT(*) AS value FROM transactions;
Flagged Transaction Rate.This panel answers: βWhere is the bank's transaction value concentrated?β
SELECT city, SUM(amount) AS value FROM transactions GROUP BY city ORDER BY value DESC;
Transaction Value by City.city as the category and value as the numeric field.This panel answers: βWhich transactions should an analyst inspect first?β
SELECT transaction_id, `timestamp`, user_name, merchant, city, amount FROM transactions WHERE is_fraud = 'true' ORDER BY amount DESC LIMIT 20;
Flagged Transactions β Review Queue.Important: Refreshing reruns the queries; it does not generate or re-import transactions. This lab uses a fixed MySQL copy of the Lecture 10 dataset.
Success checklist: Your dashboard has three titled panels, displays a fraud-rate percentage, compares transaction value by city, lists the 20 highest-value flagged transactions, and supports one clear management recommendation.
| Panel Type | Best For | Example Use |
|---|---|---|
| Time Series | Trends over time | Transaction count or value per hour |
| Stat | Single important number | Fraud rate or total transaction value |
| Bar Gauge | Progress / comparison | Flagged transactions by merchant |
| Bar Chart | Categorical comparison | Transaction value by city |
| Table | Raw data / detail view | Flagged transactions requiring review |
| Gauge | Single value with thresholds | Risk score: green/amber/red |
Extend today's transaction dashboard with more panels, reusable variables, and Assignment 3 design guidance. Keep the MySQL and Grafana containers running.