Introduction to Big Data
Understand how companies process massive datasets that cannot fit on one machine. Learn the fundamentals of distributed computing and why tools like Spark exist.
When one computer is not enough, you use many. Big data processing is divide and conquer at scale—splitting work across hundreds of machines to get answers faster.
EXERCISE
1When One Machine Is Not Enough
Understand the fundamental problem: some computations are too big, too slow, or impossible on a single machine.
The Word Frequency Problem
Task: Count how many times each word appears in a dataset.
Dataset size: 1 TB of text.
Simple approach:
Read file character by character
When you hit a space:
Extract word
hashmap[word]++
Time complexity: O(N) where N = number of characters.
This works. You read the file once, build a hashmap, done.
Making It Faster: Threads
Question: Can we parallelize this?
Answer: Yes! Split the file.
Example: 10 threads, each processes 100 GB.
Thread 1: Reads bytes 0-100GB
Thread 2: Reads bytes 100GB-200GB
...
Thread 10: Reads bytes 900GB-1TB
Each builds its own hashmap
Merge all hashmaps at the end
Result: 10× faster (assuming 10 CPU cores).
This works on one machine if you have enough CPUs and RAM.
The Real Problem: Beyond One Machine
Scenario 1: Dataset is 10 TB. Cannot fit on one machine.
Scenario 2: Dataset is 1 TB but computation per record is expensive ( lookups, calls).
Scenario 3: Need results in 5 minutes, not 5 hours.
Solution: Use multiple machines.
10 machines × 10 CPUs each = 100 CPUs working simultaneously.
This is distributed computing.
The Challenge of Distribution
Without tools, you must handle:
1. Splitting data: Divide 10 TB into chunks. Send each chunk to a machine.
2. Coordinating work: Tell each machine what to do.
3. Collecting results: Gather all hashmaps, merge them.
4. Handling failures: Machine crashes mid-computation. Who retries?
5. Ensuring completion: How do you know all machines finished?
6. Cleanup: Remove temporary files after job completes.
This is complex. Writing this logic for every job is impractical.
The Big Data Solution
Big data tools (Spark, Flink, Hadoop) handle all the complexity for you.
You write: Business logic (what to compute).
Tool handles: Distribution, failures, coordination, cleanup.
Example flow:
You: "Count word frequency in this 10 TB file"
Spark: Splits file into 100 partitions
Spark: Assigns each partition to a worker machine
Workers: Compute word frequency for their partition
Spark: Merges results from all workers
Spark: Returns final result to you
You write maybe 10 lines of code. Spark does the rest.
Real-World Scale
Netflix: Processes petabytes of viewing data daily to train recommendation models.
Facebook: Analyzes trillions of events (clicks, likes, shares) to optimize feeds.
Uber: Processes billions of ride events to optimize pricing and routing.
All use distributed computing. One machine cannot handle this scale.
The Core Insight
Big data is not about algorithms. Counting words is trivial.
Big data is about infrastructure. Running that count across 1,000 machines reliably.
Tools exist so you focus on logic, not infrastructure.
EXERCISE
2Divide and Conquer at Scale
Learn the mechanics: coordinators, workers, partitions, and how results get merged.
The Basic Pattern
Step 1: Split
Divide data into partitions.
Example: 10 TB file → 100 partitions of 100 GB each.
Step 2: Distribute
Send each partition to a worker machine.
Example: 100 workers, each gets 1 partition.
Step 3: Process
Each worker processes its partition independently.
Example: Each computes word frequency for its 100 GB chunk.
Step 4: Merge
Combine results from all workers.
Example: Merge 100 hashmaps into one final hashmap.
Step 5: Return
Send final result back to user.
The Coordinator Role
One machine acts as coordinator (also called master or driver).
Responsibilities:
Job submission: User submits job to coordinator.
Partition assignment: Coordinator assigns partitions to workers.
Progress tracking: Monitors which workers finished, which are still working.
Failure handling: If worker crashes, reassigns its partition to another worker.
Result collection: Gathers results from all workers, merges them.
Completion notification: Tells user job is done.
The coordinator does NOT process data. It only coordinates.
Example: 4 Machines
Setup:
- Machine 1: Coordinator
- Machine 2, 3, 4: Workers
User submits job: "Count word frequency in data.txt"
Coordinator actions:
- Splits data.txt into 3 partitions (one per worker)
- Sends partition 1 → Worker 2
- Sends partition 2 → Worker 3
- Sends partition 3 → Worker 4
- Waits for all workers to finish
- Collects hashmaps from workers 2, 3, 4
- Merges hashmaps into final result
- Returns result to user
Total time: Minutes instead of hours (compared to single machine).
Failure Scenarios
Scenario 1: Worker crashes before starting
Coordinator notices no response. Assigns partition to different worker.
Scenario 2: Worker crashes mid-computation
Coordinator detects failure (via heartbeat or timeout). Reassigns partition to another worker.
Scenario 3: Worker finishes but result never reaches coordinator
Coordinator times out waiting for result. Asks worker to resend or reassigns task.
Scenario 4: Coordinator crashes
This is catastrophic. Entire job fails. (Advanced systems have coordinator failover, but that is complex.)
Why This Is Hard Without Tools
Challenge 1: Fault tolerance
Must detect failures, retry intelligently, avoid duplicate work.
Challenge 2: Data transfer
Moving 10 TB across network is slow. Must minimize transfers.
Challenge 3: Resource management
100 machines. Some fast, some slow. How to balance load?
Challenge 4: Cleanup
Temporary files accumulate. Must clean up after every job.
Challenge 5: Monitoring
Which workers are done? Which are stuck? Need real-time visibility.
Writing this logic for every job is not practical.
This is why big data tools exist.
What Big Data Tools Provide
Automatic partitioning: You give it a file. It splits intelligently.
Fault tolerance: Worker dies? Tool retries automatically.
Load balancing: Distributes work evenly across workers.
Monitoring: Dashboards showing job progress, worker status.
Cleanup: Removes temporary files after job completes.
Optimization: Tools know tricks to minimize network transfer, optimize computation order.
You write business logic. Tool handles everything else.
EXERCISE
3Spark: The Most Popular Big Data Tool
Understand what Spark does, why companies choose it, and how it simplifies distributed processing.
What Is Spark?
Apache Spark: Open-source distributed computing framework.
Purpose: Process massive datasets using commodity hardware.
Commodity hardware: Regular servers you rent from AWS, GCP, Azure. Not specialized supercomputers.
Most popular big data tool used by Netflix, Uber, Airbnb, Pinterest, and thousands more.
Spark Architecture
One master node: Coordinates everything.
Many worker nodes: Do the actual computation.
User submits job to master. Master distributes work to workers.
Example:
User → Master: "Count words in 10 TB file"
Master → Worker 1: "Process partition 1"
Master → Worker 2: "Process partition 2"
...
Master → Worker 100: "Process partition 100"
Workers compute results
Workers → Master: Send results
Master: Merges results
Master → User: "Job done. Here are word counts."
Why Spark Wins
Speed: In-memory processing. 100× faster than older tools (Hadoop MapReduce).
Ease of use: Write code in Python, Java, Scala. Looks like normal programming, not weird distributed code.
Connectors: Built-in support for MySQL, Postgres, MongoDB, Kafka, S3, Redshift, Elasticsearch, and 50+ data sources.
Fault tolerance: Automatic retries. Worker crashes? Spark reassigns work.
Scalability: Works on 10 machines or 10,000 machines. Same code.
Real-World Use Case 1: Data Pipeline
Problem: Combine data from 4 databases into data warehouse.
Databases:
- Users: MySQL
- Orders: Postgres
- Payments: MongoDB
- Logistics: Another Postgres
Target: Amazon Redshift (data warehouse for analytics).
Without Spark:
Write custom script. Connect to each database. Fetch data. Transform it. Load into Redshift.
Slow: One machine reading from 4 databases, processing, loading.
Fragile: One database connection fails? Entire script breaks.
With Spark:
users = spark.read.jdbc("mysql://users_db")
orders = spark.read.jdbc("postgres://orders_db")
payments = spark.read.mongo("mongodb://payments_db")
logistics = spark.read.jdbc("postgres://logistics_db")
combined = users.join(orders).join(payments).join(logistics)
combined.write.jdbc("redshift://warehouse")
Fast: Spark uses 100 workers to read, join, load in parallel.
Reliable: Spark handles connection failures, retries automatically.
Simple: 6 lines of code instead of 1000-line script.
Real-World Use Case 2: Event Enrichment
Problem: Events flowing into Kafka. Need to enrich them before storing.
Example event (blog published):
{
"event": "blog_published",
"user_id": 12345,
"blog_id": 67890
}
Enrichment needed:
- Fetch user details from Users database
- Check if user is paid subscriber (Payments database)
- Add this info to event
Enriched event:
{
"event": "blog_published",
"user_id": 12345,
"user_name": "Alice",
"user_email": "alice@example.com",
"is_paid": true,
"blog_id": 67890
}
Without Spark:
Write service that reads Kafka. For each event, query 2 databases. Enrich. Write to Elasticsearch.
Problem: High throughput (10,000 events/sec). One service cannot keep up.
With Spark:
events = spark.readStream.kafka("blog_events")
enriched = events.join(users_db, "user_id")
.join(payments_db, "user_id")
enriched.writeStream.elasticsearch("enriched_events")
Spark distributes this across 50 machines. Each processes 200 events/sec. Total: 10,000 events/sec. No sweat.
What You Write vs What Spark Does
You write:
- Read data from X
- Transform it like Y
- Write result to Z
Spark handles:
- Splitting data into partitions
- Distributing partitions to workers
- Running your transformation on each partition
- Handling worker failures
- Merging results
- Writing output
- Cleaning up temporary files
You focus on logic. Spark handles infrastructure.
Other Big Data Tools
Spark is most popular, but others exist:
Apache Flink: Similar to Spark but optimized for real-time stream processing.
Apache Hadoop: Older tool. Spark is faster. But Hadoop still used in some companies.
Apache Kafka Streams: For processing Kafka streams. Simpler than Spark but less powerful.
DuckDB: Single-machine analytics. Not distributed but extremely fast for moderate data.
Presto / Trino: SQL query engines for big data. Used by Facebook, Uber.
Each tool has niche. Spark is general-purpose workhorse.
The Bottom Line
Big data tools exist because:
- Some datasets cannot fit on one machine
- Some computations are too slow on one machine
- Writing distributed systems logic from scratch is impractical
Spark handles complexity. You write business logic. Spark distributes it across hundreds of machines, handles failures, optimizes execution.
This is why every major tech company uses Spark or similar tools.
EXERCISE
4What Big Data Actually Does
Big data is not just counting and summing. It powers data pipelines, machine learning, real-time analytics, and more.
Beyond Counting: Real Use Cases
Big data is NOT just:
- Counting rows
- Summing numbers
- Finding averages
Big data IS:
- Moving massive datasets between systems
- Enriching data by joining multiple sources
- Training models on billions of records
- Real-time stream processing
- Building data warehouses for analytics
Use Case 1: Building Data Warehouses
Scenario: E-commerce company. Data scattered across many databases.
Sources:
- Users (MySQL)
- Products (Postgres)
- Orders (MongoDB)
- Reviews (Elasticsearch)
- Clickstream (S3 logs)
Goal: Combine everything into Redshift for business intelligence.
Spark job:
- Read from all 5 sources (in parallel)
- Clean data (remove nulls, fix formats)
- Join tables (users + orders + products + reviews)
- Aggregate (calculate metrics like "revenue per user")
- Write to Redshift
Result: Analysts query Redshift with SQL. Get insights like "top 10 products by revenue this month."
Without Spark: Would take days to move and process this data manually. With Spark: Hours.
Use Case 2: Training Machine Learning Models
Scenario: Netflix wants to recommend shows.
Data needed: 10 years of viewing history. Billions of records.
Process:
- Spark reads viewing data from S3 (petabytes)
- Cleans data (remove test accounts, fix missing values)
- Computes (user watch time, genre preferences, time of day patterns)
- Splits into training/test sets
- Feeds data to ML framework (TensorFlow, PyTorch)
Without Spark: Cannot load petabytes into memory. Model training impossible.
With Spark: Distributes feature computation across 1,000 machines. Trains model on distributed data.
Use Case 3: Real-Time Analytics
Scenario: Uber wants to detect fraud in real-time.
Data source: Kafka stream. Millions of ride events per minute.
Each event:
{
"ride_id": 12345,
"user_id": 67890,
"driver_id": 54321,
"pickup_location": "lat,lng",
"dropoff_location": "lat,lng",
"fare": 25.50
}
Fraud checks:
- Is fare unusually high for this distance?
- Has user taken 10 rides in last hour? (impossible)
- Is pickup location in restricted area?
Spark Streaming job:
- Reads events from Kafka (real-time)
- For each event, queries User database (check history)
- Queries Location database (check restrictions)
- Applies fraud rules
- If suspicious, writes to Fraud database for review
- If clean, writes to Analytics database
Throughput: 1 million events/minute. Spark distributes across 200 machines. Each processes 5,000 events/minute.
Latency: Under 1 second from event → fraud decision.
Without Spark: One service cannot handle 1 million/min throughput.
Use Case 4: Log Processing
Scenario: AWS processes billions of logs daily from millions of customers.
Goal: Detect anomalies, generate metrics, send alerts.
Log volume: 10 TB per hour.
Spark job:
- Reads logs from S3 (compressed)
- Parses logs (extract timestamp, service, error code)
- Filters (only errors and warnings)
- Groups by service and error type
- Counts errors per service
- If error count exceeds threshold, sends alert via SNS
- Writes aggregated metrics to CloudWatch
Result: Customers see metrics in CloudWatch dashboard within minutes of logs being generated.
Without Spark: Processing 10 TB/hour on one machine is impossible.
Use Case 5: Data Migration
Scenario: Company migrating from on-premise Oracle database to AWS Aurora.
Database size: 50 TB.
Challenge: Cannot afford long downtime.
Spark approach:
- Spark reads from Oracle in parallel (100 workers)
- Transforms data (Oracle format → Aurora format)
- Writes to Aurora in parallel
- Verifies data integrity (checksums)
Time: 50 TB migrated in 8 hours.
Without Spark: Would take weeks using traditional tools.
Common Thread
All these use cases share:
- Scale: Too much data for one machine
- Speed: Need results fast
- Complexity: Multiple data sources, transformations
- Reliability: Cannot afford failures or data
Spark handles scale, speed, complexity, reliability. You write business logic.
What Spark Does NOT Do
Spark is NOT:
- A database (use Postgres, MySQL for that)
- A message queue (use Kafka, RabbitMQ)
- A web (use , Apache)
- A machine learning framework (use TensorFlow, PyTorch—but Spark can prepare data for them)
Spark IS: A distributed data processing engine. It reads, transforms, writes data at massive scale.
The Modern Data Stack
Typical architecture:
Data Sources (MySQL, Postgres, APIs, Logs)
↓
Ingestion (Kafka, Kinesis, Airbyte)
↓
Processing (Spark, Flink)
↓
Storage (S3, Redshift, Snowflake)
↓
Analytics (Tableau, Looker, PowerBI)
Spark sits in the middle. It processes data flowing from sources to storage.
Without Spark (or similar tool): This pipeline does not work at scale.
