All Revision Notes

COM6002 Big Data Management · Week 1

Introduction to Big Data Management

COM6002 · Week 1 · Source: 1-Introduction.pptx (30 slides)

Contents · 12 sections

🎯 本講重點 (Learning outcomes)

  • 講出 File-based data management 的優缺點,以及 DBMS 點樣解決呢啲問題
  • 理解 Relational Model (E. F. Codd, 1970) 同 SQL 的角色
  • 分辨 Scale Up (vertical scaling) 同 Scale Out (horizontal scaling),以及 scale out 的難處
  • 用 4 V's (Volume, Variety, Veracity, Velocity) 描述 Big Data,並舉例
  • 分辨 Structured / Semi-structured / Unstructured data
  • 認識 NoSQL (Not Only SQL) 的種類、data pipeline 各 layer、Data Warehouse / Data Lake / Lakehouse

⭐ 考試必溫 Top-5

  1. File-based data management 的 5 個缺點(Inefficiency, Redundancy & Inconsistency, No Concurrency Control, Lack of Atomic Transactions, Data Isolation & Security)
  2. Scale Up vs Scale Out 的定義、例子同 scale out 的挑戰
  3. 4 V's of Big Data,每個 V 的意思同例子
  4. Structured vs Semi-structured vs Unstructured data(含例子:SQL table / JSON, XML, YAML / text, audio, image, video, PDF)
  5. Data Warehouse vs Data Lake vs Lakehouse;data pipeline 的 Ingestion / Processing / Orchestration / Serving / Storage layers

1. Evolution of Data Management:由 File 到 DBMS

1.1 File-Based Data Management

最原始的做法係將資料直接放喺一個 file 入面(例如 CSV file)。寫 Python 讀寫 CSV 好簡單,所以 Pros: Convenient — minimal effort in coding。但當資料量大、多人同時用,問題就嚟:

⭐ 考試重點:File-based 的 5 大缺點 (Cons)
缺點Slide 原文解釋 / 例子
InefficiencyWrite the entire file every time you have a tiny updateCSV 冇辦法「只改一行」—改一個股價都要重寫成個 1GB file。
Data Redundancy & InconsistencySame entity stored across multiple files同一個學生喺 students.csv 同 enrol.csv 都有地址;改咗一個冇改另一個 → 兩份資料唔一致。
No Concurrency ControlSimultaneous writes lead to corruption or simply blocking the entire system兩個程式同時寫同一個 file,結果互相覆蓋或者 file 爛咗;或者要成個 file 鎖住,其他人全部等。
Lack of Atomic TransactionsPartial writes leave system in inconsistent state upon failure寫到一半斷電 → file 只有一半新資料,冇「all-or-nothing」保證。
Data Isolation & SecurityHard to enforce fine-grained access control across custom filesOS 只可以控制「成個 file 讀唔讀得」,好難做到「某人只可以睇某幾欄 / 某幾行」。

1.2 Database Management Systems (DBMS)

ExamDBMS 的核心思想:Decoupling Data Storage & Access from Application Logic——application 唔再自己處理 file 點樣存、點樣鎖、點樣 recover,而係交俾 DBMS 處理。DBMS addresses all the concerns in File-Based Data Management。

Traditional DBMSs 的特徵:

  • Centralized(集中喺一部機)
  • Based on Relational Model (using tables) — 出自 E. F. Codd: A Relational Model of Data for Large Shared Data Banks, Commun. ACM 13(6), 1970
  • Use SQL to interact with the database

Slide 4 的 relational data 例子:一個股價 table,每行係一日,每欄係一個 attribute:

DateOpenHighLowCloseVolume
1/13.23.53.13.21.6M
2/13.23.32.931M
3/133.62.93.52M
4/13.53.93.13.62.3M
💡 直覺理解

File-based 好似每個部門自己有本 notebook 記資料;DBMS 就好似公司有個中央檔案室 + 專業管理員:佢負責「邊個可以睇乜」、「兩個人同時改點算」、「改到一半停電點復原」。Application 只需要用 SQL 話俾管理員知要乜。

2. From Centralized to Distributed:Scale Up vs Scale Out

問題:How to improve the capacity of the database system? 有兩條路:

⭐ 考試重點:Scale Up vs Scale Out
Scale Up (Vertical Scaling)Scale Out (Horizontal Scaling)
定義Adding more power to an existing single machineAdding more machines to a distributed network to share the workload
例子Upgrading CPU, RAM加多幾部 server,資料 / 工作分散處理
難度簡單(程式唔使改),但一部機有物理上限、愈升級愈貴Very challenging! — What if one of the machines fails? What if two machines are working on the same data record?

歷史:Distributed database systems already existed in 1990s(但因為 network 慢,performance 差);到 late 2000s 先流行起嚟。

💡 直覺理解

Scale up = 請一個更勁的廚師;Scale out = 請多幾個廚師一齊煮。後者理論上可以無限加人,但要協調:一個廚師病咗(machine fails)點算?兩個廚師同時加鹽落同一煲湯(two machines working on the same record)點算?呢啲正正係 Week 3 concurrency control / recovery 要解決的問題,而喺 distributed 環境更難。

3. What is Big Data?

Definition (Wikipedia):Big data primarily refers to data sets that are too large or complex to be dealt with by traditional data-processing application software.

Slide 6 亦提醒:有啲人講 Big Data,其實只係指「佢手上嗰份 data」,而份 data 根本唔大(slide 6 附有 MIMIC-III critical care database 的引用及一張圖片,圖片內容擷取不到)。重點係「traditional software 處理唔到」,唔單止係「大」。

4. Characteristics of Big Data:4 V's

⭐ 考試重點:4 V's of Big Data
V意思Slide 例子
VolumeToo much data to handle研究 bitcoin 自 2009 年起的社交情緒:Twitter archive 約 5M messages/day ≈ 2GB/day(Twitter 實際約 500M messages/day)
VarietyMultiple types / formats一個 tweet 有 multi-lingual text、images、videos…;follow 關係形成 graph data
VeracityData quality — Is your data always correct?GIGO;missing / duplicated / ambiguous / outdated / inconsistent data
VelocitySpeed of data — real-time, generated continuouslyBinance BTCUSDT 交易隊列;家用 security camera 影片

4.1 Volume

Worked example(用 slide 數字):由 2009 到 2026 大約 17 年 ≈ 6,200 日。每日 2GB → 約 12 TB,而呢個只係 archive 的 1% sample(5M vs 500M)。如果要全量,就係 ~1.2 PB——一部普通電腦明顯處理唔到,所以需要 big data 技術。

4.2 Variety 與 Graph data

X / Twitter 上可以搵到:multi-lingual text、images、videos 等等。另外「Alice is following Elon, Bob is following Elon…」呢類關係可以 represented in a graph(node = 用戶,edge = follow)。Graph analysis 可以答:Who is a KOL (Key Opinion Leader)?——例如被最多人 follow(in-degree 最高)的 node,喺 slide 例子中就係 Elon(Alice、Bob、Cathy、Doris 都指向佢)。

4.3 Types of data

⭐ 考試重點:三種資料類型
Type特徵例子
StructuredWith fixed-schemaTraditional SQL tables, spreadsheets
Semi-structuredWith certain format; flexible, self-describing formats with tags or key-value pairsJSON, XML, YAML
UnstructuredFormats without an internal schema or structural markersRaw text documents, audio files, images, videos, PDFs

例如同一個 tweet 用 JSON 表示(semi-structured):

{
  "user": "Alice",
  "text": "BTC to the moon 🚀",
  "lang": "en",
  "media": [{"type": "image", "url": "..."}],   // 有啲 tweet 有,有啲冇
  "retweets": 25
}

每個 key 自己描述自己(self-describing),而且唔同 tweet 可以有唔同 key——呢個就係「flexible」,同 SQL table 每行都要有一樣 columns(fixed schema)唔同。至於 media 指向的 image 本身就係 unstructured data。

⚠️ 易混淆

JSON / XML 唔係 unstructured!佢哋有 tags / key-value 結構,只係 schema 唔固定 → semi-structured。PDF 雖然有格式,但內容冇 internal schema → slide 歸類為 unstructured。

4.4 Veracity:data quality

🖼️ 圖片內容

Slide 12 用兩張圖片(標註 "Mechanism?" 同 "Terrorist?")說明資料可能唔正確,圖片內容文字擷取不到;請對照原 slide 第 12 頁。

ExamGIGO — Garbage in, garbage out:Data quality is very important! 輸入資料錯,無論 model 幾勁,輸出都係垃圾。Types of data quality concerns:

  • Missing data — 例如某日股價冇記錄
  • Duplicated data — 同一筆交易記咗兩次
  • Ambiguous data — slide 例子:“There is a bird in a cage that can talk.” Who can talk?(bird 定 cage?語意含糊)
  • Outdated data — 舊地址、過期價錢
  • Inconsistent data — 一個 file 寫 “HK”,另一個寫 “Hong Kong”

4.5 Velocity:speed of data

Real-time data:data is generated continuously;而且 the data source does not always keep all the data for you to download later——錯過咗就冇。

例子 1:記錄 Binance BTCUSDT futures 的資料。要儲乜?每次 update 的 trade queue 都儲?資料量會極大。
例子 2:Home security camera app — Will you keep the video data? 一部 CCTV 一日可產生幾 GB 至幾十 GB 影片(slide 15 引用 Quora 數據,圖片部分擷取不到)。

4.6 Streaming algorithms

What if the data generation speed far exceeds our storage capability? → Streaming algorithms:資料流過時只睇一次、只保留摘要。Key design issues:

  • How to extract key summaries and what to keep?
  • Can we find the exact answers to queries?
  • If it is an approximation, how close will it be? Any bounds on the performance?
💡 直覺理解

例如要計 BTC 一整日的平均成交價,你唔需要儲晒每一筆交易,只要不斷更新兩個數:sum 同 count,最後 sum/count 就係 exact answer。但如果要「今日出現過幾多個唔同 wallet」(distinct count),就要儲晒所有 wallet ID——太大;streaming algorithm 會用近似方法(例如 HyperLogLog),並保證誤差喺某個 bound 之內。

5. Why do we have Big Data?

  • Internet! Many data sources are available to the public — Social network: Twitter;Finance: Cryptocurrency market data
  • Increased capability of machines, e.g., increased storage → We tend to store more data。Slide 圖示:1990's 磁碟 1.44MB;而家 256 GB 記憶卡約 HKD $100;個人雲端 15 GB 免費。

6. Next-generation Data Management:NoSQL

NoSQL stands for Not Only SQL——data is not well structured as a table。Types of NoSQL databases:

  • Graph database(例如儲 follow 關係)
  • Key-value store
  • Document store — Example: MongoDB

ExamNote: RDBMS are still the most widely used DBMS(db-engines.com ranking)。NoSQL 唔係取代 RDBMS。

Example MongoDB data(slide 19)

{ "Symbol": "BTC", "Date": "1/1", "Open": 3.1, "High": 3.3, "Low": 2.9, "Close": 3.1,
  "Sentiment": 0.39, "Basis": 0.0003, "Whale transactions": 1056 }
{ "Symbol": "ETH", "Date": "1/1", "Close": 11.3, "BTC Correlation": 0.77 }
{ "Symbol": "DOGE", "Date": "1/1", "Close": 0.000065, "Twitter mention": 25694 }

Q: What happens if we put the data in a table?
答:Table 要 fixed schema,即係 columns = 所有 document 出現過的 key 的聯集(Symbol, Date, Open, High, Low, Close, Sentiment, Basis, Whale transactions, BTC Correlation, Twitter mention)。結果 ETH 同 DOGE 好多欄都係 NULL(sparse table,浪費空間);而且將來加新指標就要 ALTER TABLE 改 schema。Document store 就可以每個 document 有自己的欄位。

Which type of database should we use?

This is a core topic of this module! RDBMS vs NoSQL 會喺之後幾堂詳細比較;而且仲要考慮其他選項,例如 single file / HDFS。

7. Use of Big Data:Big Data Analytics

Big Data is almost understood as Big Data Analytics。Data analytics 其實歷史好長:

“Beer and Diapers” (early 1990s):超市做 market basket analysis,分析顧客一齊買咩。預期結果:bread and butter;意外發現:beer and diapers 經常一齊被買。而家幾乎任何 data analytics task 都被叫做 Big Data Analytics——Is this a good sign?(暗示「Big Data」一詞被濫用。)

🖼️ 圖片內容

Slide 21 只有一張圖片(Big Data Analytics),文字擷取不到;請對照原 slide 第 21 頁。

Big Data Analytics tools

  • Data cleaning — Improve the data quality of your data
  • ETL — Extract-transform-load pipeline to preprocess your data for your analysis
  • Analytics tools — Machine learning / Data mining / Artificial Intelligence
  • OLAP — Online Analytical Processing(Week 5 Power BI 會詳講)

8. Data Pipeline

🖼️ 圖片內容

Slide 24 "Example Data Pipeline" 係一張架構圖,文字擷取不到;請對照原 slide 第 24 頁。以下根據 slide 25 文字解釋。

⭐ 考試重點:Common data pipeline components
Layer功能例子工具
Ingestion LayerExtracts raw data from diverse source systems;store data into the central storageAPI、web scraping(Week 2)
Processing LayerPerforms computation on raw ingested data, such as cleaning, schema transformations, aggregationspandas / Spark
Orchestration LayerCoordinates, schedules, and monitors execution dependencies across the entire pipeline as Directed Acyclic Graphs (DAGs)Apache Airflow
Serving LayerStores processed, business-ready data in specialized engines optimized for applicationsSnowflake
Storage Layer中央儲存(Data Warehouse / Data Lake)—
💡 直覺理解:點解係 DAG?

Pipeline 每一步有依賴:「download 價格」→「clean」→「計 daily average」→「更新 dashboard」。用 graph 表示,箭咀有方向 (directed),而且唔可以兜返轉頭 (acyclic),否則永遠行唔完。Airflow 就係按 DAG 次序定時執行、監察失敗。

9. Data Warehouse / Data Lake / Lakehouse

Data Warehouse / Data Lake 都係:

  • A central repository
  • A copy / snapshot of your data from the original source
  • Require synchronization strategy(原始資料變咗,copy 點樣跟住更新?)
⭐ 考試重點:Warehouse vs Lake vs Lakehouse
Data WarehouseData LakeLakehouse
DataStructured dataUnstructured data(including structured data!)建喺 Data Lake 之上
特點有 schema、適合 SQL 分析、一致性好乜都可以掟入去、scalable、平Implements a metadata and transaction layer directly on top of open object storage (Data Lake);Maps unstructured / semi-structured data into structured, queryable schemas without physical data movement
一句總結整齊的倉庫乜都有的湖Unifies Data Lake scalability with Data Warehouse features e.g., consistency
🖼️ 圖片內容

Slide 26、27 各有一張示意圖,文字擷取不到;請對照原 slide。

10. Working with Data:Where does the time go?

ExamData scientists spend 80% of their time cleaning data——幾十年來唔同行業的調查結果都差唔多。所以 Veracity / data cleaning 係 big data 工作的大部分。

🖼️ 圖片內容

Slide 28、29 的圖表(時間分佈調查)係圖片,文字擷取不到;請對照原 slide。

Big Data is not always successful:Google Flu Trends

Google 最初的 paper 聲稱 Google Flu Trends(用搜尋關鍵字預測流感)同 CDC 數據比較有 97% accurate;但 2012/2013 季節,佢預測的求診人數係 CDC 最終記錄的兩倍。教訓:資料量大唔代表準確;data quality、模型假設、搜尋行為改變(concept drift)都會令結果出錯。

自我測驗 Self-test

Q1. 列出 File-Based Data Management 的優點同五個缺點。

Pros:Convenient — minimal effort in coding。Cons:(1) Inefficiency — 小改動都要重寫成個 file;(2) Data Redundancy & Inconsistency — 同一 entity 散落多個 file;(3) No Concurrency Control — 同時寫會損壞或 block 成個系統;(4) Lack of Atomic Transactions — 寫到一半失敗令系統 inconsistent;(5) Data Isolation & Security — 難做 fine-grained access control。

Q2. 一間公司把 database server 由 16GB RAM 升到 128GB,另一間就由 1 部 server 加到 10 部。分別係咩 scaling?後者有咩挑戰?

前者 = Scale Up (Vertical Scaling);後者 = Scale Out (Horizontal Scaling)。Scale out very challenging:其中一部機 fail 點算?兩部機同時處理同一個 data record 點算(一致性)?加上 network 速度影響 performance(1990s distributed DB 表現差的原因)。

Q3. 將以下資料分類為 structured / semi-structured / unstructured:(a) Excel 成績表 (b) API 回傳的 JSON (c) 錄音 mp3 (d) XML config (e) 掃描的 PDF 合約

(a) Structured;(b) Semi-structured;(c) Unstructured;(d) Semi-structured;(e) Unstructured。

Q4. 說明 4 V's,並各舉一個 crypto 相關例子。

Volume:多年 Twitter 討論 bitcoin 的 archive(2GB/day 的 sample)。Variety:tweet 有多語言文字、圖片、影片,follow 關係係 graph。Veracity:付費 API 的價格錯 10 倍、LUNA 崩盤後 sentiment 仍顯示 positive。Velocity:Binance 交易隊列不斷更新,來源唔會保留晒俾你之後下載。

Q5. 如果每日收集 2GB tweets,連續收 10 年需要幾多儲存空間?如果收全量(100 倍)呢?

2GB × 365 × 10 ≈ 7,300 GB ≈ 7.3 TB。全量約 100 倍 ≈ 730 TB(接近 1 PB)。說明 Volume 問題:單機難以處理,要考慮 scale out / distributed storage。

Q6. 將 slide 19 的 BTC / ETH / DOGE MongoDB documents 放入一個 relational table 會有咩問題?

Table 需要 fixed schema,columns 要包括所有 document 的 keys 聯集;ETH、DOGE 大部分欄位會係 NULL(sparse、浪費),而新增指標要改 schema。Document store(NoSQL)容許每個 document 有不同欄位,更適合。

Q7. Data pipeline 中,負責「按 DAG 排程、監察各步驟依賴」的係邊個 layer?舉一個工具。Serving layer 呢?

Orchestration Layer,例如 Apache Airflow。Serving Layer 儲存 business-ready data 喺為 application 優化的引擎,例如 Snowflake。

Q8. Data Warehouse、Data Lake、Lakehouse 有咩分別?

三者都係 central repository(原始資料的 copy/snapshot,需要 synchronization strategy)。Warehouse 存 structured data;Lake 存 unstructured(包括 structured)data;Lakehouse 喺 data lake 之上加 metadata + transaction layer,將 unstructured/semi-structured data map 成可 query 的 schema 而唔使搬資料,結合 lake 的 scalability 同 warehouse 的 consistency。

Q9. 咩係 GIGO?列出五種 data quality concerns。

Garbage in, garbage out:輸入資料差,分析結果亦差。五種:Missing, Duplicated, Ambiguous, Outdated, Inconsistent data。

一頁總結 Cheat sheet

⭐ 考前速記
  • File-based:Pro = convenient;Cons = Inefficiency / Redundancy & Inconsistency / No Concurrency Control / No Atomic Transactions / Isolation & Security
  • DBMS = decouple storage & access from application logic;traditional = centralized + relational model (Codd 1970) + SQL
  • Scale Up = 升級單機 (CPU/RAM);Scale Out = 加機器,難在 machine failure 同 concurrent update;distributed DB 1990s 已有,late 2000s 流行
  • Big Data = too large or complex for traditional software
  • 4 V's:Volume / Variety / Veracity / Velocity
  • Structured (fixed schema) / Semi-structured (JSON, XML, YAML) / Unstructured (text, audio, image, video, PDF)
  • GIGO;quality concerns:missing, duplicated, ambiguous, outdated, inconsistent
  • Streaming algorithms:what to keep? exact or approximate? error bounds?
  • NoSQL = Not Only SQL:graph DB / key-value store / document store (MongoDB);RDBMS 仍然最多人用
  • Analytics tools:data cleaning, ETL, ML/DM/AI, OLAP;Beer & Diapers = market basket analysis
  • Pipeline layers:Ingestion → Processing → Orchestration (DAG, Airflow) → Serving (Snowflake) + Storage
  • Warehouse (structured) / Lake (unstructured incl. structured) / Lakehouse (metadata + transaction layer on lake)
  • 80% time on data cleaning;Google Flu Trends 高估 2 倍 → Big Data 唔一定成功