Module Introduction
Hello, cloud explorer! 🌤️ In Module 4, we learned how Spark helps us process big data fast. But where do we run Spark? We run it on computers. What if we don't have big computers at home? That's where the cloud comes in!
The cloud is like a giant playground of computers that belong to someone else, but we can rent them whenever we want. It's like borrowing your friend's super-powerful gaming computer to play a big game, but you only pay for the time you use it.
In this module, we will learn how to run Spark on the cloud. We will use services like AWS, Azure, and Google Cloud. We will also learn how to set up clusters, manage resources, and make our Spark jobs run even faster. Let's fly into the cloud! 🚀
Learning Objectives
By the end of this module, you will be able to:
Warm‑up Story – The School Playground
Imagine your school has a small playground with just one slide and one swing. When only a few children play, it's fine. But one day, the whole school wants to play at the same time! The playground is too small.
The principal says, "Don't worry! We can use the big playground at the community centre. It has 10 slides, 20 swings, and lots of space. We can rent it for just one day, and we only pay for that day."
That is exactly what cloud computing is! Instead of buying our own big computers (which are expensive and we may not need them every day), we rent them from cloud providers. We pay only for what we use, and we can get as many computers as we need.
Your small computer (at home)
|
| not enough power
V
Cloud playground (big computers)
+-------------------------------+
| Computer 1 Computer 2 |
| Computer 3 Computer 4 |
| ... (hundreds of computers) |
+-------------------------------+
You rent them for a few hours.
🌟 Mini summary: The cloud is like a playground of computers that we can rent when we need them. We pay only for what we use.
Definition: Cloud computing means using computers, storage, and services over the internet, instead of owning them yourself.
Why it is important: The cloud gives us access to powerful computers without buying them. We can scale up or down easily.
Simple explanation: It's like using a library instead of buying all the books yourself. You borrow what you need and return it when done.
Real-life example: Netflix uses the cloud to stream movies to millions of people.
School example: Your school uses Google Classroom – that's cloud computing!
Home example: You use iCloud or Google Photos to store your pictures.
Nigerian example: Many Nigerian startups use the cloud to run their apps without buying expensive servers.
Traditional: Buy computer → Install software → Run Cloud: Rent computer over internet → Run → Stop paying
📌 Mini summary: Cloud computing means renting computers and services over the internet instead of buying them.
Definition: The three biggest cloud companies are Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP).
Why it is important: These companies have the biggest and most reliable clouds. Most people use one of them.
Simple explanation: They are like the three biggest supermarkets for computers. You can go to any one to buy (rent) computer power.
Real-life example: Spotify uses Google Cloud. Airbnb uses AWS. Many banks use Azure.
School example: Your school might use Microsoft Office 365 (Azure) or Google Workspace (GCP).
Home example: If you use Amazon Prime Video, that's AWS.
Nigerian example: Flutterwave uses AWS for its payment processing.
+----------+ +----------+ +----------+ | AWS | | Azure | | GCP | | (Amazon) | | (Microsoft) | (Google) | +----------+ +----------+ +----------+ All three offer Spark in the cloud!
📌 Mini summary: AWS, Azure, and GCP are the three big cloud providers. They all offer Spark.
Definition: Running Spark in the cloud means you run your Spark jobs on rented computers that are managed by a cloud provider.
Why it is important: You don't need to buy expensive hardware. You can get thousands of computers for a short time.
Simple explanation: It's like having a magic button that gives you more computers when you need them.
Real-life example: A company runs a big sale and needs extra computer power for one day. They rent it from the cloud.
School example: During exam grading, your school rents cloud computers to process all the results quickly.
Home example: If your family wants to store a million photos, they use cloud storage.
Nigerian example: During elections, cloud computers can count voting data from all over the country.
Reasons to use cloud for Spark: 1. No need to buy hardware 💰 2. Scale up or down easily 📈 3. Pay only for what you use ⏱️ 4. Use the latest machines 🆕 5. Focus on your code, not on setup 🧑💻
📌 Mini summary: The cloud makes Spark easy and affordable because you rent computers only when you need them.
Definition: AWS is Amazon's cloud platform. It is the most popular cloud provider in the world.
Why it is important: AWS has many services for big data, including EMR (Elastic MapReduce) which runs Spark.
Simple explanation: AWS is like a huge toy store with many different toys (services). One of the toys is Spark.
Real-life example: Netflix, Airbnb, and many others use AWS.
School example: If your school uses Amazon, they might use AWS for their website.
Home example: Amazon Prime Video runs on AWS.
Nigerian example: Paystack (owned by Stripe) uses AWS for payment processing.
AWS Services for Big Data: +------------------+ | EMR (Spark) | ← we will use this! | S3 (storage) | ← store our data | EC2 (computers) | ← virtual machines | Lambda (serverless) | +------------------+
📌 Mini summary: AWS is Amazon's cloud. We use EMR to run Spark and S3 to store data.
Definition: S3 is a service in AWS that stores files in the cloud. Think of it as a very big online folder.
Why it is important: S3 can store any amount of data. Spark can read data directly from S3.
Simple explanation: It's like Google Drive but made for big data. You can put any file there, and Spark can read it.
Real-life example: Companies store all their customer data in S3.
School example: Your teacher stores all assignments in a shared folder (like S3).
Home example: You save your homework in Google Drive – S3 is similar but more powerful.
Nigerian example: A bank stores all transaction logs in S3.
Data Flow: Your computer → upload to S3 → Spark reads from S3 → results saved to S3
📌 Mini summary: S3 is cloud storage for files. Spark can read and write data to S3.
Definition: EMR is an AWS service that makes it easy to run Spark and other big data tools in the cloud.
Why it is important: EMR sets up all the Spark clusters for you automatically. You just tell it what to do.
Simple explanation: EMR is like a magical machine that creates Spark clusters with a single click. No need to set up anything yourself.
Real-life example: A data scientist uses EMR to run a Spark job on 100 computers in 5 minutes.
School example: The principal clicks a button and suddenly 20 computers are ready for the students.
Home example: Like ordering a pizza – you click, and it arrives ready.
Nigerian example: A startup uses EMR to process customer data every night.
How EMR works: 1. You tell EMR what you need (Spark, number of computers, etc.) 2. EMR creates the cluster automatically 3. You run your Spark job 4. EMR shuts everything down when done (optional)
📌 Mini summary: EMR is a service that creates and manages Spark clusters in the cloud for you.
Definition: Azure has a service called Synapse that can run Spark. Databricks is a company that makes Spark easy on all clouds.
Why it is important: You don't have to use AWS – you can use Azure or Databricks too.
Simple explanation: It's like having different brands of cars – all can take you to the same place (Spark), but each has its own style.
Real-life example: Many companies use Databricks because it has a nice web interface.
School example: Your school might use different software for different subjects.
Home example: You can use different apps to watch movies.
Nigerian example: A Nigerian company might choose Azure because they already use Microsoft products.
Cloud Spark Options:
+----------+ +----------+ +----------+
| AWS EMR | | Azure | | Google |
| | | Synapse | | Dataproc |
+----------+ +----------+ +----------+
| | |
+---------------+---------------+
|
V
+-------------+
| Databricks | (works on all clouds)
+-------------+
📌 Mini summary: You can run Spark on AWS, Azure, or Google Cloud. Databricks is a popular tool that works on all of them.
Definition: A cluster is a group of computers that work together. Setting up a cluster means creating those computers.
Why it is important: Without a cluster, you can't run Spark in parallel. You need many workers.
Simple explanation: It's like forming a team. You need to gather the players before you can play the game.
Real-life example: Before a big project, the manager forms a team of workers.
School example: The teacher divides the class into groups before the activity.
Home example: Before cleaning the house, you ask everyone to help.
Nigerian example: Before the village harvest, the chief calls all the farmers together.
Steps to create an EMR cluster: 1. Go to AWS Management Console 2. Click on EMR 3. Click "Create Cluster" 4. Choose Spark as the application 5. Choose number of nodes (computers) 6. Click "Create" – wait 5 minutes 7. Your cluster is ready! 🎉
📌 Mini summary: Creating a cluster on EMR is easy – you click a few buttons and wait a few minutes.
Definition: Reading data from S3 means your Spark code can load files directly from S3 storage.
Why it is important: Your data is in S3, so Spark needs to read it from there.
Simple explanation: It's like reading a book from the library – you need to go to the library first.
Real-life example: A company stores all sales data in S3. Spark reads it to analyse sales.
School example: The teacher stores all homework in a cloud folder. Students read from there.
Home example: You read recipes from an online cookbook.
Nigerian example: A farmer stores crop data in S3. Spark reads it to predict harvest.
Spark code to read from S3:
df = spark.read.csv("s3://my-bucket/sales_data.csv")
or
df = spark.read.parquet("s3://my-bucket/customers/")
S3 path format: s3://bucket-name/folder/file
📌 Mini summary: Spark can read files from S3 using paths that start with "s3://".
Definition: Writing results to S3 means saving your Spark output to S3 storage.
Why it is important: You want to keep your results for later. S3 is a safe place to store them.
Simple explanation: After you finish your drawing, you put it in your folder so you don't lose it.
Real-life example: After running a report, the company saves it to S3 for other teams to use.
School example: After the class project, the teacher saves it to the school's cloud folder.
Home example: After you finish your homework, you save it to your computer.
Nigerian example: After counting votes, the result is saved to S3 for everyone to see.
Spark code to write to S3:
result_df.write.csv("s3://my-bucket/output/results.csv")
or
result_df.write.parquet("s3://my-bucket/output/")
You can also save as JSON, ORC, etc.
📌 Mini summary: Spark can save results to S3 using the write() method.
Definition: Scaling means using more or fewer computers to do the work.
Why it is important: Sometimes you need more power (more computers) to finish fast. Other times you want fewer computers to save money.
Simple explanation: It's like adding more people to help you move a heavy sofa. More people = faster, but you have to pay them.
Real-life example: During Black Friday, an online store uses 10 times more computers to handle all the orders.
School example: For a big exam, the school uses more teachers to mark papers.
Home example: When cleaning the house, more family members help to finish quickly.
Nigerian example: During elections, INEC uses more computers to count votes quickly.
Scaling options: +------------------+------------------+ | Vertical Scaling | Horizontal Scaling | | (make one bigger) | (add more workers) | +------------------+------------------+ | Use a bigger | Use 10 computers | | computer | instead of 1 | +------------------+------------------+ In the cloud, horizontal scaling is easier!
📌 Mini summary: Scaling means adding or removing computers to match your needs.
Definition: Monitoring means watching your Spark job while it runs to see if everything is going well.
Why it is important: You want to know if your job is making progress, using enough memory, or if it has errors.
Simple explanation: It's like watching the cooker to see if your food is cooking properly.
Real-life example: A driver uses a speedometer to monitor the car's speed.
School example: The teacher walks around the class to monitor students' work.
Home example: Mum checks the oven to see if the cake is ready.
Nigerian example: A bus conductor monitors how many passengers are on the bus.
Monitoring tools: 1. EMR Console (shows cluster status) 2. Spark UI (shows job progress) 3. CloudWatch (shows logs and metrics) 4. Ganglia (shows resource usage) You can see: - How much memory is used - How many tasks are running - If any tasks failed
📌 Mini summary: Monitoring helps you see if your Spark job is running correctly.
Definition: Cost management means using the cloud in a way that doesn't waste money.
Why it is important: Cloud services cost money per hour. If you leave computers running, you pay even if you're not using them.
Simple explanation: It's like leaving all the lights on in your house – you pay for electricity you don't need.
Real-life example: A company shuts down its cloud computers at night to save money.
School example: The teacher turns off the projector when not in use.
Home example: You switch off the TV when no one is watching.
Nigerian example: A small business uses cloud computers only during business hours to save money.
Ways to save money: 1. ✅ Shut down clusters when not in use 2. ✅ Use spot instances (cheaper) 3. ✅ Choose smaller machines if you don't need big ones 4. ✅ Use auto-scaling (add computers only when needed) 5. ❌ Don't leave clusters running overnight (unless you need to)
📌 Mini summary: To save money, turn off cloud computers when you don't need them.
Definition: Serverless means you don't manage servers at all. You just submit your Spark job and it runs somewhere.
Why it is important: It makes Spark even easier. You don't need to create clusters or manage anything.
Simple explanation: It's like using a vending machine – you put in your request (code) and get the result (output). You don't care about how the machine works inside.
Real-life example: AWS Glue is a serverless Spark service. You just write your ETL jobs and they run.
School example: The canteen gives you food – you don't need to know how it's cooked.
Home example: You use a microwave – you don't know how it works inside.
Nigerian example: A payment app like Opay processes transactions – you don't see the servers.
Serverless vs Traditional: Traditional: You manage cluster, software, updates Serverless: You just submit code – the cloud handles everything +------------------+------------------+ | Traditional | Serverless | | (EMR) | (Glue, Databricks) | +------------------+------------------+
📌 Mini summary: Serverless Spark means you don't manage any servers – just submit your code.
Here is how a typical cloud Spark workflow looks:
1. Prepare your data → upload to S3 2. Write your Spark code (Python/Scala) 3. Create an EMR cluster (or use serverless) 4. Submit your job to the cluster 5. Monitor progress via Spark UI 6. Results are saved to S3 7. Shut down the cluster (to save money!) 8. Download results from S3 (if needed)
Let's see a simple example in Python using PySpark on EMR:
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("Cloud Word Count").getOrCreate()
# Read from S3
df = spark.read.text("s3://my-bucket/story.txt")
# Process
words = df.rdd.flatMap(lambda line: line[0].split(" "))
word_counts = words.map(lambda w: (w, 1)).reduceByKey(lambda a,b: a+b)
# Save to S3
word_counts.toDF(["word", "count"]).write.csv("s3://my-bucket/output/")
spark.stop()
📌 Mini summary: Cloud Spark workflow: upload data → write code → create cluster → run → save results → shut down.
How to run a Spark job on EMR:
Step 1: AWS Console → EMR Step 2: Create Cluster Step 3: Add Step (your Spark code) Step 4: Run Job Step 5: Check Output Step 6: Terminate Cluster 💰
Cloud Architecture (simple):
+-------------+
| Your Laptop|
+-------------+
|
| (submit job)
V
+---------------------------------+
| AWS CLOUD |
| +---------------------------+ |
| | EMR Cluster | |
| | +------+ +------+ | |
| | |Master| |Worker| | |
| | +------+ +------+ | |
| | |Worker| |Worker| | |
| | +------+ +------+ | |
| +---------------------------+ |
| +---------------------------+ |
| | S3 Storage | |
| | (data in, data out) | |
| +---------------------------+ |
+---------------------------------+
|
V
Results saved to S3
Scaling Up vs Scaling Out:
Scaling Up (Vertical): [Small computer] → [Bigger computer] (one computer, more powerful) Scaling Out (Horizontal): [1 computer] → [10 computers] (more computers, each does a small part)
Cost vs Time Trade‑off:
+------------------+------------------+ | Number of Nodes | Time to Finish | +------------------+------------------+ | 1 node | 10 hours | | 5 nodes | 2 hours | | 10 nodes | 1 hour | | 20 nodes | 30 minutes | +------------------+------------------+ More nodes = faster, but more expensive.
On‑Premise vs Cloud:
| Feature | On‑Premise | Cloud |
|---|---|---|
| Cost | High upfront | Pay as you go |
| Scaling | Hard and slow | Easy and fast |
| Maintenance | You do it | Provider does it |
| Setup time | Weeks | Minutes |
| Accessibility | On‑site only | From anywhere |
AWS vs Azure vs GCP:
| Feature | AWS | Azure | GCP |
|---|---|---|---|
| Spark service | EMR | Synapse | Dataproc |
| Storage | S3 | Blob | Cloud Storage |
| Popularity | #1 | #2 | #3 |
| Free tier | Yes | Yes | Yes |
| Serverless Spark | Glue | Synapse | Dataproc Serverless |
EMR Instance Types:
| Type | Use case | Cost |
|---|---|---|
| m5.xlarge | General purpose | Medium |
| r5.xlarge | Memory‑intensive | Higher |
| c5.xlarge | Compute‑intensive | Medium |
| spot instances | Non‑critical jobs | Very low |
Congratulations! 🎉 You have completed Module 5 – Spark in the Cloud. Here is what we learned:
You are now ready for Module 6 – Real‑World Spark Projects! 🚀
Match the term with its description:
| Term | Description |
|---|---|
| 1. AWS | A. Amazon's cloud |
| 2. S3 | B. Cloud storage |
| 3. EMR | C. Spark in the cloud |
| 4. Glue | D. Serverless Spark |
| 5. EC2 | E. Virtual machines |
Answers: 1-A, 2-B, 3-C, 4-D, 5-E
Title: Cloud Provider Comparison
Instructions: In groups of 4, research one cloud provider (AWS, Azure, GCP). Prepare a 5‑minute presentation about:
Title: My First S3 Upload
Instructions: If you have AWS access, create an S3 bucket, upload a small CSV file, and read it with Spark (using EMR or Glue). Write down the steps you followed.
Title: Cloud‑Based Sales Analytics
Description: You have sales data for a Nigerian supermarket stored in S3. Use Spark on EMR to:
Deliverable: Spark script and a brief report on how you set up the cluster.
Title: Run Word Count on EMR
Instructions:
Title: Optimise Cloud Costs
Problem: Your company runs a Spark job every day that takes 4 hours on a 10‑node cluster. The cluster costs ₦10,000 per hour. You want to reduce costs by 50%. Suggest two strategies and explain how they would work.
Fill‑in‑the‑Blank Answers: 1. internet, 2. Amazon, 3. storage, 4. MapReduce, 5. servers
True/False Answers: 1. False, 2. False, 3. True, 4. False, 5. True
Multiple Choice Answers: 1-B, 2-C, 3-B, 4-B, 5-A, 6-B, 7-A, 8-B, 9-B, 10-C, 11-B, 12-B, 13-A, 14-B, 15-A
Matching Answers: 1-A, 2-B, 3-C, 4-D, 5-E
In Module 6, we will apply everything we have learned to real‑world projects. We will build an end‑to‑end data pipeline, work with real datasets, and solve actual business problems.
What to bring:
See you in Module 6 – let's build something great! 🏗️