端到端 Twitch 实时与离线数据工程管道:Kinesis、Spark、dbt、Redshift、Airflow 与 Superset
Find a file
2026-07-23 13:41:37 +09:00
.github/workflows 说明 CI 自动化工作流 2026-07-23 13:41:37 +09:00
dags 说明 Airflow 离线调度任务 2026-07-23 13:41:37 +09:00
dbt 说明 dbt 分层建模与测试 2026-07-23 13:41:37 +09:00
docs 说明架构文档与运行手册 2026-07-23 13:41:37 +09:00
glue_jobs 说明 Glue 和 Spark 数据处理作业 2026-07-23 13:41:37 +09:00
infra 补充 Terraform 基础设施说明 2026-07-23 13:41:37 +09:00
results 说明仪表盘快照与示例输出 2026-07-23 13:41:37 +09:00
scripts 说明 Lambda 与数据工具脚本 2026-07-23 13:41:37 +09:00
superset 说明 Superset 图表与仪表盘 2026-07-23 13:41:37 +09:00
tests 说明自动化测试与质量检查 2026-07-23 13:41:37 +09:00
.gitignore Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
4fc7d054bef6d9153ad629e3d51350cd.jpg Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
architecture_diagram.drawio Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
Dockerfile Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
Makefile Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
README.md Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
requirements.txt Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
面试押题.md Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00
项目概览.md Import Twitch data pipeline demo 2026-07-23 12:05:43 +09:00

Twitch Chat Data Pipeline — Lambda Architecture on AWS

An end-to-end data-engineering project on real Twitch chat data (~290K messages, 8 channels). It implements a Lambda architecture: a speed layer for live metrics and a batch layer that builds a dimensional warehouse for analytics.

Real data, real AWS deployment. Streaming side reacts in seconds; batch side rebuilds a star-schema warehouse and serves BI dashboards.


Architecture

Architecture — speed layer (Kinesis → Lambda → DynamoDB → live dashboard) and batch layer (S3 → Spark → Glue → Redshift/dbt → BI), orchestrated by Airflow

  • Speed layer answers "what is happening right now" (live message rate, sentiment, top emotes, viewers).
  • Batch layer answers "what happened and why" (per-channel daily reports, revenue events, raid attribution) on a clean star schema.

Dashboards

Offline analytics — batch layer, served from the Redshift Gold star schema (snapshot):

Offline analytics dashboard

Live chat — speed layer, Kinesis → Lambda → DynamoDB, auto-refreshing every 2s:

Live chat dashboard — all channels

The live view has a per-channel tab; selecting one drills the whole board down to that channel:

forsen lirik
forsen lirik

Tech stack

Layer Tooling
Streaming ingest Amazon Kinesis Data Streams (2 streams)
Stream processing AWS Lambda (Python) — shared VADER scoring lib
Realtime serving DynamoDB (composite key + TTL) + Lambda Function URL dashboard
Data lake Amazon S3 — Bronze, Parquet
Batch processing AWS Glue (Spark / PySpark) — distributed sentiment scoring
Catalog Glue Data Catalog (Crawler)
Warehouse Redshift Serverless + Redshift Spectrum
Modeling dbt — Silver + Gold star schema, data-quality tests
Orchestration Airflow (dags/)
BI Superset chart SQL (superset/) + serverless Chart.js dashboards
IaC Terraform (infra/)
CI / tests GitHub Actions + pytest
Packaging Docker
Sentiment VADER + custom Twitch-emote lexicon

Repository layout

.
├── dags/                 # Airflow DAG — orchestrates the batch pipeline
├── glue_jobs/            # PySpark job — distributed VADER sentiment scoring
├── dbt/                  # dbt project — Silver + Gold star schema + tests
├── scripts/              # ingestion / replay / realtime Lambda / warehouse build
├── superset/             # BI — chart SQL + deployed serverless dashboards
├── results/              # verified outputs (snapshot, validation log)
├── tests/                # pytest — unit tests for the sentiment scorer
├── infra/                # Terraform — IaC for the AWS resources
├── docs/                 # screenshots + data dictionary + runbook
├── .github/workflows/    # CI (lint + tests + dbt parse)
├── Dockerfile  Makefile  requirements.txt  .gitignore
└── architecture_diagram.svg / .drawio

Data model (Gold, star schema)

Built by dbt in dbt/models/. Grain-first dimensional design:

  • Fact tables (one business process / grain each): fact_message (one chat line), fact_event (one discrete event: raid / sub / resub), fact_viewer (one viewer-count sample).
  • Dimensions (the recurring "group by" axes): dim_channel, dim_user, dim_date, dim_game.
  • Tests: uniqueness, not-null, and referential-integrity (relationships) on keys.

Full column reference: docs/DATA_DICTIONARY.md.


Quickstart

make install                       # or: pip install -r requirements.txt

# --- Batch layer (offline warehouse) ---
make dbt-build                     # build + test Silver + Gold (dbt run + dbt test)
make snapshot                      # query Gold -> results/dashboard_snapshot.json
make deploy-dashboards             # push snapshot into the BI Lambda

# --- Speed layer (live) ---
make replay CH=chat_forsen.jsonl   # replay chat -> Kinesis (loops)

Raw commands are in the Makefile; the batch flow also runs as an Airflow DAG in dags/.


Testing & CI

  • make test runs pytest (tests/) — unit tests for the VADER + emote sentiment scorer.
  • GitHub Actions (.github/workflows/ci.yml) runs lint + tests + dbt parse on every push / PR.

Infrastructure

infra/ is Terraform that recreates the whole AWS stack (Kinesis, DynamoDB, S3, Glue, Redshift Serverless): cd infra && terraform init && terraform apply -var="account_id=<acct>".

Docs


Results (verified on AWS)

Metric Value
Messages modeled (fact_message) 286,521
Unique users (dim_user) 43,663
Channels 8
Raids attributed 7
dbt data-quality tests 8 / 8 passing

Full snapshot: results/dashboard_snapshot.json.


What is actually deployed vs. represented

Being explicit (this matters):

  • Deployed & verified on AWS: Kinesis → Lambda → DynamoDB → live dashboard; S3 → Glue Spark → Crawler → Redshift Spectrum → dbt models (8/8 tests) → BI dashboard.
  • dags/ encodes the batch flow as an Airflow DAG (the same dbt build + test steps). Runs on any Airflow/MWAA.
  • infra/ is Terraform that codifies the resources (created via CLI/console during dev) — apply it to rebuild from scratch.
  • superset/ holds the BI chart SQL; the dashboards actually shipped are the serverless superset/offline_dashboard_lambda.py and superset/realtime_dashboard_lambda.py.