Data science and big data
Foundations of data science and big data: definitions, distributed storage and processing (HDFS, MapReduce, Spark), key laws (Amdahl, Little), formulas and exam-style examples for engineers.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Big data and data science let engineers handle, process and analyse very large data sets that do not fit on a single machine. An engineer uses these ideas when designing data pipelines, choosing storage/processing frameworks (Hadoop, Spark), and estimating cost, performance and reliability for real systems.
Key ideas
Distributed file system (HDFS) — a file system that stores files across many machines. Define: block — the fixed-size unit of storage (typical default: 128 MiB); replication factor — number of copies of each block (typical default: 3). HDFS has a central NameNode (stores metadata) and many DataNodes (store blocks). Assumptions: network is reliable enough for replication, NameNode is a single point of metadata (except high-availability configurations).
What to draw for HDFS in an exam: draw a large rectangle labelled "Cluster". Inside, draw one box labelled "NameNode (metadata)" and 3–6 boxes labelled "DataNode A/B/C...". For one file, draw it split into blocks B0, B1, B2 across DataNodes; draw arrows from NameNode to DataNodes to show placement and arrows from client to DataNode for read. Label block size and replication factor on the drawing.
MapReduce — a programming model for distributed processing. Define map — function applied independently to input records producing (key, value) pairs; shuffle — grouping by key (and sorting by key) to send all values for a key to one reducer; reduce — function that processes all values for a key to produce final output. Assumptions: map tasks are embarrassingly parallel; reduce tasks require grouping by key; network costs occur during shuffle.
Exact MapReduce flow to write in an answer: input split → map tasks → local combine (optional) → partition → shuffle and sort → reduce tasks → write output.
Apache Spark — a distributed processing engine that supports in-memory computation and higher-level APIs (RDDs, DataFrames). Define RDD (Resilient Distributed Dataset) — an immutable distributed collection of objects with lineage for recomputation on failure. Spark assumes more memory available and trades off between recomputation and storage; it excels for iterative algorithms. Spark uses lazy evaluation: transformations build a DAG and actions trigger execution; DataFrame queries are optimized by the Catalyst optimizer.
Batch vs Stream processing — batch processes finite, stored data sets (jobs run on demand or schedule); stream processes unbounded, continuously arriving data with low latency. Define latency — time between event arrival and result; throughput — events processed per second. Choose batch when latency tolerance is high; choose streams for real-time needs.
Amdahl's law (for parallel speedup) — if fraction P of a program is parallelisable and (1−P) is serial, the maximum speedup with N parallel workers is S = 1 / ((1−P) + P/N). Assumes perfect parallelisation of P, no overheads, and constant workload. Complement: Gustafson's law (scaled speedup) — for problem sizes that grow with N, S_scaled = N − (1−P)(N−1).
Little's law (for queues) — in any stable system, average number in system L = λ · W, where λ is arrival rate and W is average time in system. Assumes system is stable and averages over long time.
CAP theorem (distributed systems) — a distributed data store can provide at most two of: Consistency (reads see latest writes), Availability (every request receives a response), Partition tolerance (system continues despite network partitions). State assumption: network partitions can occur so systems choose trade-offs between consistency and availability.
Reliability and replication trade-offs — extra replicas improve availability and read throughput but increase storage and write cost. Show the simple storage calculation: Storage_used = data_size × replication_factor.
Formulas
S = 1 / ((1 - P) + P / N)
S = speedup (dimensionless). P = fraction of program parallelisable (0..1). N = number of parallel workers (dimensionless). Applies when computing theoretical parallel speedup (Amdahl's law), assuming no overheads.
L = λ · W
L = average number in system (items), λ = arrival rate (items·s⁻¹), W = average time in system (s). Applies to stable queueing systems (Little's law).
Storage_used = Data_size × Replication_factor
Storage_used = total physical storage used (bytes), Data_size = logical data size (bytes), Replication_factor = number of replicas (dimensionless). Applies to replicated storage systems like HDFS.
Blocks = ceil(Data_size / Block_size)
Blocks = number of blocks (integer), Data_size = bytes, Block_size = bytes. Applies when computing HDFS block counts.
Throughput = Tasks_completed / Time_elapsed
Throughput = rate (tasks·s⁻¹), Tasks_completed = count (dimensionless), Time_elapsed = s. Applies as a basic performance measure.
Worked examples
HDFS storage and blocks (numerical)
- Given: a file of size 10 TB (10 × 10¹² bytes), HDFS block size = 128 MiB (128 × 2²⁰ bytes), replication factor = 3. Find number of blocks and total storage used.
- Step 1: Blocks = ceil(Data_size / Block_size).
- Data_size = 10 × 10¹² bytes.
- Block_size = 128 × 2²⁰ = 134,217,728 bytes.
- Blocks = ceil(10 × 10¹² / 134,217,728) = ceil(74,505.805...) = 74,506 blocks.
- Step 2: Storage_used = Data_size × Replication_factor = 10 × 10¹² × 3 = 30 × 10¹² bytes = 30 TB.
- Final answers: Blocks = 74,506 blocks, Storage used = 30 TB.
- Note: convert units carefully (verify whether TB used as 10¹² bytes or 2⁴⁰ bytes depending on question).
Parallel speedup using Amdahl's law (numerical)
- Given: a job where P = 0.80 (80% parallelisable), N = 4 cores. Find theoretical speedup S and parallel efficiency E.
- Formula: S = 1 / ((1 - P) + P / N).
- Compute: S = 1 / ((1 - 0.8) + 0.8 / 4) = 1 / (0.2 + 0.2) = 1 / 0.4 = 2.5.
- Parallel efficiency E = S / N = 2.5 / 4 = 0.625 (62.5%).
- Final answers: Speedup = 2.5, Efficiency = 62.5%.
Model-answer (theory) — Explain why MapReduce reduces network cost using combiner.
- Start by defining Map, Shuffle, Reduce. Explain that shuffle moves intermediate (key, value) pairs across network to reducers. Show math: if each mapper emits M intermediate pairs and a combiner locally aggregates them by key reducing to M' pairs (M' < M), then network traffic is reduced from O(M) to O(M'). Give an exam diagram: input splits → mappers (local combine) → shuffle arrows (smaller width) → reducers. Conclude that combiners are effective when map-side aggregation reduces intermediate volume (e.g., local word counts). Mention limitation: combiners must be associative and commutative for correctness; combiners are hints and are not guaranteed to run or to run exactly once.
Common mistakes
- Applying Amdahl's law without accounting for overheads (scheduling, communication); students quote S > N or forget the serial part.
- Drawing HDFS with NameNode storing block data (NameNode stores metadata only; DataNodes store actual blocks).
- Saying Spark always beats MapReduce — must state trade-offs: memory, workload type, fault semantics.
- Misstating CAP theorem as a limit at all times; clarify it applies under partitions and is about trade-offs.
For your exam
Quick check
- What are the three V's of big data?
- State Amdahl's law formula in words.
- In HDFS, which component holds metadata and which holds data blocks? Answers: 1. Volume, Velocity, Variety. 2. Maximum speedup S = 1 / ((1−P) + P/N) where P is parallel fraction and N is number of workers. 3. NameNode holds metadata; DataNodes hold data blocks.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?