What is Cloud Computing?
Cloud computing means renting computers from a company like AWS instead of buying your own. You use them only when you need them, and you pay only for the time you use them. In this lesson you start and stop a server with a few lines of Python, and see why renting saves money for a shop whose visitors go up and down.
What you will be able to do
- Explain cloud computing in one sentence
- Name the five things that make a service "cloud"
- Tell IaaS, PaaS and SaaS apart
- See that renting a server is just an API call
- Compare owning and renting with real numbers
- Avoid the classic cloud bill trap: rented and never returned
The idea, in plain English
For a long time, a company that wanted to run a website bought its own servers: order the machines, wait for delivery, install them in a server room, and pay for power, cooling and staff. Getting a new server took weeks, and you had to buy enough for your busiest day - even if that day comes once a year.
Cloud computing turns this around. A cloud provider like AWS owns huge data centres and rents out pieces of them over the internet. You ask for a server, storage or a database with a click or an API call, it is ready in minutes, and you pay only for the time you use it - by the hour or even by the second. When you are done, you give it back and the bill stops.
In this lesson we rent and return a server with Python, then measure what renting really changes for a shop with a festival sale. We never touch a real AWS account: the API calls go to moto, a library that pretends to be AWS inside your program, and the price is the real one from AWS’s public price list (published 2026-11-14). boto3 1.44.4, moto 5.2.5, Python 3.13.12.
Worked example: An online shop’s month of traffic - quiet nights, busy evenings and a three-day festival sale - served by a fixed fleet and by servers rented hour by hour, priced with the real AWS price for Mumbai.
Words you will see in this lesson
A few cloud words. Each comes back many times in this course.
ServerA computer that runs programs for others - for example a website.Cloud providerA company that rents out computing over the internet: AWS, Microsoft Azure, Google Cloud.InstanceOne rented virtual server. On AWS: an EC2 instance (Lesson 31).On demandReady when you ask for it, with no contract or waiting.Pay as you goYou pay for what you use - per hour, per second, per gigabyte - and nothing when you use nothing.ElasticityGrowing and shrinking capacity as demand goes up and down.APIA way for programs to ask a service to do something - here, to start or stop a server.An everyday example: a car
You need to travel. You can own a car or use a taxi app:
- Owning: you pay a lot at the start, then insurance and repairs - even on days the car stands still. But it is always there.
- A taxi app: no big payment. You ask, it arrives in minutes, you pay for the trip, and you walk away.
- For a big family trip you book a bigger car for that one day. You do not buy a bus for the whole year.
- But if you keep the taxi waiting outside all night, the meter keeps running.
- Cloud computing is the taxi app for computers - including the meter.
What makes something "cloud"
The usual definition (from the US standards institute, NIST) lists five things. A real cloud service has all five:
- On-demand self-service - you get resources yourself, from a website or an API, without calling anyone.
- Broad network access - you use it over the internet, from anywhere.
- Resource pooling - many customers share the provider’s huge data centres; you do not know or care which exact machine you get.
- Rapid elasticity - you can get more, or give back, in minutes.
- Measured service - every hour, gigabyte and request is counted, and you pay for what was counted.
Three ways to rent: IaaS, PaaS, SaaS
Cloud services differ in how much the provider does for you:
- IaaS - Infrastructure as a Service: you rent the raw machine (server, disk, network) and manage everything on it - the operating system, updates, your app. Example: an EC2 server.
- PaaS - Platform as a Service: you bring your code; the provider runs the servers and the platform. Example: AWS Elastic Beanstalk, or AWS Lambda for single functions.
- SaaS - Software as a Service: you just use finished software in the browser. Example: Gmail, or a hosted shop system.
- The more the provider does, the less you manage - and the less you can change.
- Who is responsible for what in each case is the Shared Responsibility Model (Lesson 10).
Example 1 - renting a server is an API call
rent_a_server.py rents one server in Mumbai, looks at it, and gives it back - with boto3, the Python library for AWS:
- @mock_aws sends every AWS call to moto, a fake AWS inside the program. Nothing is created on a real account and nothing is billed. The fake credentials make sure of it.
- boto3.client("ec2", region_name="ap-south-1") connects to EC2, the AWS server service, in the Mumbai region.
- run_instances(...) is the whole "order": which disk image to start from, which size (t3.medium: 2 virtual CPUs, 4 GiB of memory), how many, and a name tag.
- describe_instances(...) asks for the server’s current details.
- terminate_instances(...) gives it back. On real AWS, this is the moment the bill for the server stops.
import os
import boto3
from moto import mock_aws
# Fake credentials: everything below talks to moto, never to a real AWS account
os.environ.update(AWS_ACCESS_KEY_ID="testing", AWS_SECRET_ACCESS_KEY="testing")
@mock_aws
def main():
ec2 = boto3.client("ec2", region_name="ap-south-1") # Mumbai
# 1. Ask for a server: one API call
image = ec2.describe_images(Owners=["amazon"])["Images"][0]["ImageId"]
reply = ec2.run_instances(
ImageId=image,
InstanceType="t3.medium", # 2 vCPU, 4 GiB
MinCount=1, MaxCount=1,
TagSpecifications=[{"ResourceType": "instance",
"Tags": [{"Key": "Name", "Value": "shop-server-1"}]}],
)
server = reply["Instances"][0]
server_id = server["InstanceId"]
print("asked for: ", server["InstanceType"], "in", server["Placement"]["AvailabilityZone"])
print("server id: ", server_id)
print("state at once: ", server["State"]["Name"])
# 2. Look at it a moment later
found = ec2.describe_instances(InstanceIds=[server_id])["Reservations"][0]["Instances"][0]
print("state later: ", found["State"]["Name"])
print("private IP: ", found["PrivateIpAddress"])
# 3. Give it back: the bill for this server stops here
ec2.terminate_instances(InstanceIds=[server_id])
gone = ec2.describe_instances(InstanceIds=[server_id])["Reservations"][0]["Instances"][0]
print("after terminate:", gone["State"]["Name"])
main()asked for: t3.medium in ap-south-1a
server id: i-f3a38e51fd92aae3f
state at once: pending
state later: running
private IP: 10.33.97.224
after terminate: terminatedReading the output
- The server got an ID (i-...) and a place: zone ap-south-1a, one of the data centres in the Mumbai region (zones are Lesson 5).
- It started as pending - being prepared - and was running when we looked again. On real AWS this usually takes a minute or two, not weeks.
- It got a private IP address inside AWS’s network.
- After terminate it was terminated: given back for good.
- Compare this with buying a server: choosing a model, waiting for delivery, installing it in a room. Here it was four API calls - and the same code can rent 1 server or 100.
Example 2 - owning vs renting, measured
plans.py serves one month (720 hours) of an online shop’s traffic in different ways and prices each one:
- The price is real: it reads t3.medium in Mumbai from AWS’s public price list - $0.0448 per hour. No account is needed to download it (the curl line is in the code).
- traffic(hour) gives the requests per second for each hour: about 40 at 2 am, 340 at 8 pm, and four times more during a three-day festival sale. The shape is made up, but fixed, so every run gives the same numbers.
- One assumption: one t3.medium handles 100 requests per second. Real apps differ - you measure your own with metrics (Lesson 133).
- report() counts server-hours, cost, how busy the servers were, and how many requests could not be served because there were too few servers.
- Plan A: a fixed fleet sized for an average hour. Plan B: a fixed fleet sized for the busiest hour - like owning servers. Plan C: renting, hour by hour, exactly what that hour needs.
import json
import math
# The real on-demand price, from AWS's public price list (no account needed):
# curl --compressed -o mumbai.json "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Mumbai)/Linux/index.json"
prices = json.load(open("mumbai.json"))["regions"]["Asia Pacific (Mumbai)"]
PRICE = float(next(p["price"] for p in prices.values() if p["Instance Type"] == "t3.medium"))
CAPACITY = 100 # we assume one t3.medium handles 100 requests per second
HOURS = 30 * 24 # one month, hour by hour
def traffic(hour):
"""Requests per second for one hour: quiet at night, busy in the evening, a 3-day sale."""
day, clock = divmod(hour, 24)
daily = 190 - 150 * math.cos((clock - 8) / 24 * 2 * math.pi) # 40 at 2 am, 340 at 8 pm
sale = 4 if 24 <= day <= 26 else 1 # festival sale: days 25 to 27
return daily * sale
demand = [traffic(h) for h in range(HOURS)]
total_requests = sum(demand) * 3600
print(f"price: t3.medium in Mumbai = ${PRICE} per hour")
print(f"traffic: average {sum(demand) / HOURS:.0f} req/s, busiest hour {max(demand):.0f} req/s")
print()
def report(name, fleet):
"""fleet = how many servers run in each hour"""
server_hours = sum(fleet)
dropped = sum(max(0, d - n * CAPACITY) for d, n in zip(demand, fleet)) * 3600
overloaded = sum(1 for d, n in zip(demand, fleet) if d > n * CAPACITY)
used = (total_requests - dropped) / (server_hours * CAPACITY * 3600)
print(f"{name:<26} servers {min(fleet):>2}-{max(fleet):<2} server-hours {server_hours:>5} "
f"cost ${server_hours * PRICE:>7.2f} busy {used:>4.0%} "
f"overloaded hours {overloaded:>2} lost requests {dropped / 1e6:>5.1f} million")
average_fleet = math.ceil(sum(demand) / HOURS / CAPACITY)
peak_fleet = math.ceil(max(demand) / CAPACITY)
report("A. fixed, sized for avg", [average_fleet] * HOURS)
report("B. fixed, sized for peak", [peak_fleet] * HOURS)
report("C. rented hour by hour", [max(1, math.ceil(d / CAPACITY)) for d in demand])Reading the result: three plans
The first three lines of the output (D comes in Trap 1):
- A - sized for the average: 3 servers, $96.77. Cheap - but during the sale they were overloaded for 192 hours and 139.2 million requests were lost. Lost requests are lost customers.
- B - sized for the peak: 14 servers all month, $451.58. Nothing was lost, but the servers were busy only 18% of the time. This is what owning looks like: you pay every day for your busiest day.
- C - rented hour by hour: between 1 and 14 servers, $95.02, busy 84%, nothing lost. Cheaper than A and safer than B.
- This is the core promise of the cloud: capacity that follows demand, so you stop paying for servers that wait.
- In real life, adding servers takes a few minutes, so you keep a little spare capacity. AWS does the hour-by-hour work for you with Auto Scaling (Lesson 40).
price: t3.medium in Mumbai = $0.0448 per hour
traffic: average 247 req/s, busiest hour 1360 req/s
A. fixed, sized for avg servers 3-3 server-hours 2160 cost $ 96.77 busy 64% overloaded hours 192 lost requests 139.2 million
B. fixed, sized for peak servers 14-14 server-hours 10080 cost $ 451.58 busy 18% overloaded hours 0 lost requests 0.0 million
C. rented hour by hour servers 1-14 server-hours 2121 cost $ 95.02 busy 84% overloaded hours 0 lost requests 0.0 million
D. rented, never returned servers 3-14 server-hours 4248 cost $ 190.31 busy 42% overloaded hours 0 lost requests 0.0 million
forgotten test server: m5.large at $0.101/hour x 720 hours = $72.72Trap 1: rented, never returned
The same meter that makes renting cheap keeps running when you forget to stop it. Plan D rents servers for the sale - and nobody scales back down:
- The fleet only grows: it reached 14 servers during the sale and stayed there for the rest of the month.
- Result (line D above): $190.31 - double plan C for exactly the same traffic, with the servers busy only 42%.
- In a company with many teams, this happens all the time: test servers, demo environments, a big database for one experiment.
- Fix: scale down automatically (Auto Scaling, Lesson 40), give every resource an owner tag, and set a budget alarm. Cost habits are Lesson 175.
# Trap: scaled up for the sale - and nobody scaled back down
grown, fleet = 1, []
for d in demand:
grown = max(grown, math.ceil(d / CAPACITY)) # only ever goes up
fleet.append(grown)
report("D. rented, never returned", fleet)
# Trap: one test server, started "for a quick try" and forgotten for a month
M5 = float(next(p["price"] for p in prices.values() if p["Instance Type"] == "m5.large"))
print(f"\nforgotten test server: m5.large at ${M5}/hour x {HOURS} hours = ${M5 * HOURS:.2f}")Trap 2: the forgotten test server
The last line of the output prices one bigger server (m5.large, 2 vCPU, 8 GiB) started "for a quick try" and forgotten:
- $0.101 per hour x 720 hours = $72.72 for a month in which it did nothing.
- Small hourly prices hide big monthly ones: multiply by 720 in your head.
- Before you start anything, know how you will stop it. Lesson 11 covers the Free Tier and how to stay inside it while you learn.
Watch out: Terminate is final: the server and its local disk are deleted. Stop is different - the server pauses and you pay only for its disk (Lesson 32). Use stop for "back tomorrow", terminate for "done".
When the cloud is not cheaper
Renting wins when demand moves. It is not automatically cheaper:
- A steady load that runs 24 hours a day all year: on-demand prices can cost more than owning. AWS offers big discounts for committing to steady use (Reserved Instances and Savings Plans, Lessons 191-192).
- Moving data OUT of the cloud costs money per gigabyte - a surprise on many first bills.
- Many small managed services add up. Every service has its own meter.
- What you really buy is speed and flexibility: a new idea can run today, and a failed idea costs a few dollars instead of a server room.
Cloud computing at a glance
CloudRent computing over the internet, pay per use.
on demand, by the hour or second
Rent a serverOne API call.
ec2.run_instances(ImageId=..., InstanceType="t3.medium", MinCount=1, MaxCount=1)
Give it backThe bill stops.
ec2.terminate_instances(InstanceIds=[server_id])
IaaS / PaaS / SaaSMachine / platform / finished app.
EC2 / Elastic Beanstalk, Lambda / Gmail
Monthly costHourly price x 720.
$0.0448 x 720 = $32.26 per t3.medium
Try it yourself
The code does not change. Swap the content string and the program does something else entirely.
“Change the sale multiplier from 4 to 8 in traffic(). What happens to plans A, B and C?”
“Make traffic() return 300 every hour. Is renting hour by hour still cheaper than a fixed fleet?”
“Download the price list for "US East (N. Virginia)" and compare the t3.medium price with Mumbai.”
“In rent_a_server.py, set MinCount=3, MaxCount=3. How many server IDs come back?”
What usually goes wrong
Plan B: 14 servers, 18% busy, $451.58.
Plan A looked cheap and lost 139.2 million requests during the sale.
Plan D doubled the bill: $190.31 instead of $95.02.
One m5.large for a month: $72.72 for nothing.
Multiply by 720 for a month before you start anything.
Best practices
- Know how you will stop a resource before you start it.
- Let capacity follow demand - automatically when you can (Auto Scaling, Lesson 40).
- Tag every resource with an owner and a purpose.
- Set a budget alarm on day one, even for a learning account.
- Practise against a stand-in like moto before you spend real money.
Practice
Write these yourself before opening anything. Getting them wrong first is most of how this sticks.
Add plan E to plans.py: rent hour by hour, but always keep one spare server (needed + 1), because real scaling takes a few minutes. Print its line and compare its cost with plan C. How much does the safety margin cost per month?
Show hintHide hint
The fleet is [max(1, math.ceil(d / CAPACITY)) + 1 for d in demand]. Reuse report().
A cost alarm for forgotten servers
Write a small script that, given a list of servers (name, type, hours running, hours busy), prints the monthly cost of each at the Mumbai prices and flags the ones that waste money.
- Read the prices from mumbai.json - no prices typed into the code.
- Monthly cost = hourly price x 720.
- Flag a server as WASTE when it was busy less than 10% of its running hours.
- Print a total for all servers and a total for the WASTE ones.
- Test it with the forgotten m5.large from this lesson: it should cost $72.72 and be flagged.
Key points
- Cloud computing = renting servers, storage and networks over the internet, on demand, paying per use.
- The five signs: self-service, network access, shared pools, elasticity, measured use.
- IaaS rents the machine, PaaS runs your code, SaaS is finished software.
- Renting a server is an API call, and so is giving it back.
- Measured: owning for the peak cost $451.58 at 18% busy; renting hour by hour cost $95.02 with nothing lost.
- You pay until you give it back: never scaling down doubled the bill.
Quick check before you move on
Interview questions
What is cloud computing?
On-demand access to computing resources - servers, storage, databases, networking - over the internet from a provider, with self-service provisioning, rapid elasticity and pay-as-you-go pricing.
What are the main benefits and risks of moving to the cloud?
Benefits: no upfront hardware cost, fast provisioning, elasticity, global reach, managed services. Risks: cost surprises (idle resources, data transfer), vendor lock-in, the need for new security and cost-control skills.
Explain IaaS, PaaS and SaaS with examples.
IaaS: raw infrastructure you manage (EC2). PaaS: a platform that runs your code (Elastic Beanstalk, Lambda). SaaS: complete software you use (Gmail, Salesforce).
Quiz
- 1.
Why did renting cost less than a fixed fleet sized for the peak?
- 2.
Is the cloud always cheaper than owning servers?
- 3.
What is the difference between IaaS and PaaS?
- 4.
Why did plan D cost twice as much as plan C?
Comments
Sign in to leave a comment. Your name and photo come from Google; nothing else is shared.
Loading comments...