Understand how companies process massive datasets that cannot fit on one machine. Learn the fundamentals of distributed computing and why tools like Spark exist.
Save
Complete lesson & earn 250 PX
EXERCISE
1Understand the fundamental problem: some computations are too big, too slow, or impossible on a single machine.
Save
EXERCISE
2Learn the mechanics: coordinators, workers, partitions, and how results get merged.
Save
EXERCISE
3Understand what Spark does, why companies choose it, and how it simplifies distributed processing.
Save
EXERCISE
4Big data is not just counting and summing. It powers data pipelines, machine learning, real-time analytics, and more.
Save
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.
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.
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.
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.
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.
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.
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.
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.
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.
Setup:
User submits job: "Count word frequency in data.txt"
Coordinator actions:
Total time: Minutes instead of hours (compared to single machine).
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.)
Challenge 1:
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:
Which workers are done? Which are stuck? Need real-time visibility.
Writing this logic for every job is insane.
This is why big data tools exist.
Automatic : You give it a file. It splits intelligently.
Fault tolerance: Worker dies? Tool retries automatically.
: 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.
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.
One master : 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."
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.
: Works on 10 machines or 10,000 machines. Same code.
Problem: Combine data from 4 databases into data warehouse.
Databases:
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.
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:
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.
You write:
Spark handles:
You focus on logic. Spark handles infrastructure.
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.
Big data tools exist because:
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.
Big data is NOT just:
Big data IS:
Scenario: E-commerce company. Data scattered across many databases.
Sources:
Goal: Combine everything into Redshift for business intelligence.
Spark job:
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.
Scenario: Netflix wants to recommend shows.
Data needed: 10 years of viewing history. Billions of records.
Process:
Without Spark: Cannot load petabytes into memory. Model training impossible.
With Spark: Distributes feature computation across 1,000 machines. Trains model on distributed data.
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:
Spark Streaming job:
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.
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:
Result: Customers see metrics in CloudWatch dashboard within minutes of logs being generated.
Without Spark: Processing 10 TB/hour on one machine is impossible.
Scenario: Company migrating from on-premise Oracle database to AWS Aurora.
Database size: 50 TB.
Challenge: Cannot afford long downtime.
Spark approach:
Time: 50 TB migrated in 8 hours.
Without Spark: Would take weeks using traditional tools.
All these use cases share:
Spark handles scale, speed, complexity, reliability. You write business logic.
Spark is NOT:
Spark IS: A distributed data processing engine. It reads, transforms, writes data at massive scale.
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.
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.