Cloud building blocks
Part of the free LogicWiz Data Engineering course, Module 14: Cloud data platforms. The SQL and Python run in the app, on real Postgres and real Python in the browser.
It is 10:20 on Monday, a month after SwiftKart moved its pipeline into the cloud. Tess opens the first invoice for the data lake: $5,400. She had budgeted $1,150, the price of storing 50 TB. Nothing failed. Nora reads it too: "Find out what each dollar bought. Then tell me who can read the customer file."
You'll learn to
- Name the four building blocks every cloud sells
- Price storage, requests and small files on a real bill
- Decide a request the way a cloud does: deny, guardrails, allows
- Price moving data between zones, regions and the internet
Learn
A $5,400 bill for $1,150 of storage
Tess expected one line: 50 TB stored, at about two cents a GB a month, is $1,150.
Every line on a cloud invoice belongs to one of four things. Azure, AWS and Google Cloud sell the same four under different names:
- Object storage: files, called objects, in buckets or containers. Cheap, durable, practically unlimited. Your data lake lives here.
- Compute: machines that run code (virtual machines, managed Spark, serverless functions, warehouses). You pay while it runs.
- Identity and access: who may read, write or delete what.
- Regions and network: where it all runs, and what moving data costs.
The $5,400 invoice, line by line
A bar splits a monthly bill of 5,400 dollars into storage, write requests, read requests, cross-region reads and NAT gateway processing, with the two data-movement parts bracketed as 3,900 dollars.
Read it left to right: three teal blocks for storing and asking, two red blocks for moving bytes.
A bucket is not a folder
Open the lake and you see folders: bronze/orders/, silver/orders/. They are not real.
Object storage is a giant key-value store, like a coat check: the ticket is the only way back to the coat. The key bronze/orders/2025-06-01.csv is the object's whole name, and its slashes are ordinary characters. So:
- Listing a folder means asking for every key that starts with a prefix.
- Renaming a folder means copying every object to a new key and deleting the old one, one at a time.
- Objects are written whole. You cannot append a line: you write a new object.
Rename a folder of three files
Three objects whose keys start with bronze/orders/ are copied one by one to keys starting with bronze/orders_v1/ and then deleted one by one, six requests in all.
Before. Three objects have keys starting with
bronze/orders/. No folder exists: only three names that share a beginning.Copy, three times. Each object is copied to a key starting with
bronze/orders_v1/: three requests. Every file now exists twice.Delete, three times. Each old key is deleted: six requests in all. If the job dies halfway, the files are split between two names.
Read each step left to right: old names, new names, request counter.
Run it: a rename is copies and deletes
store = { # key -> object size in bytes
'bronze/orders/2025-06-01.csv': 410,
'bronze/orders/2025-06-02.csv': 530,
'bronze/orders/2025-06-03.csv': 470,
'bronze/payments/2025-06-01.jsonl': 1200,
'silver/orders/part-00000.parquet': 2700,
}
def list_prefix(store, prefix):
return sorted(k for k in store if k.startswith(prefix))
def rename_prefix(store, old, new):
"""What 'renaming a folder' really costs: a copy and a delete per object."""
ops = 0
for key in list_prefix(store, old):
store[new + key[len(old):]] = store.pop(key) # copy, then delete
ops += 2
return ops
print(list_prefix(store, 'bronze/orders/'))
print('operations to rename:', rename_prefix(store, 'bronze/orders/', 'bronze/orders_v1/'))
print(list_prefix(store, 'bronze/'))
Three objects cost six operations. Two million cost four million requests, each billed and each able to fail. That is why lake tables are many immutable files plus a log, as Delta does. (ADLS Gen2 adds real directories: Lesson 14.2.)
Every request is billed, big or small
The invoice's next lines are requests. Every write, read or listing of an object is one request, and each is charged.
On S3 Standard in us-east-1, storing costs $0.023 per GB-month (first 50 TB). Writing costs $0.005 per 1,000 PUT, COPY, POST or LIST requests. Reading costs $0.0004 per 1,000 GETs.
The catch: a request costs the same for 1 KB as for 1 GB. So this part of the bill follows the number of objects, not their size.
There is a speed limit too, per prefix. Push past it and S3 answers 503 Slow Down while it scales up; the client waits and retries.
The small-files bill: 1 TB two ways
TB = 10 ** 12
PUT, GET, LIST = 0.005 / 1000, 0.0004 / 1000, 0.005 / 1000 # S3 Standard, us-east-1, per request
GETS_PER_SECOND = 11_000 # per partitioned prefix
for label, size in [('100 KB files', 100 * 10 ** 3), ('128 MB files', 128 * 10 ** 6)]:
files = -(-TB // size) # ceiling division
lists = -(-files // 1000) # a LIST returns up to 1,000 keys
print(f'{label}: {files:>10,} files write ${files * PUT:6.2f} read once ${files * GET + lists * LIST:5.2f}'
f' at least {files / GETS_PER_SECOND:6.1f} s of GETs on one prefix')
Ten million 100 KB objects cost $50 to write, $4.05 to read once and at least 15 minutes of GETs on one prefix. 7,813 objects of 128 MB cost cents. Small files cost twice: in requests and in time.
Old data moves to a cheaper shelf
Back to the first line: storage. Last year's raw files are opened perhaps once a year, yet they sit on the dearest shelf.
Clouds sell tiers: the shelf by the till, the stockroom, a warehouse across town. The further away, the cheaper the rent and the dearer the trip.
- Hot: dearest to store, cheap to read. For data used every day.
- Cool: cheaper to store, a fee per GB read, a minimum storage period.
- Archive: very cheap to store, costly to read back, and for some, hours before you can.
Lifecycle rules move objects down the tiers as they age, for example bronze files after 30 days.
Which tier is cheapest?
# Illustrative prices only, chosen to show the trade-off. Real prices change and
# differ by cloud and region: always check the current price list.
TIERS = { # tier: ($ per GB stored per month, $ per GB read back)
'hot': (0.020, 0.000),
'cool': (0.010, 0.010),
'archive': (0.002, 0.050),
}
def monthly_cost(tier, stored_gb, read_gb):
store, read = TIERS[tier]
return round(stored_gb * store + read_gb * read, 2)
for read_gb in [0, 500, 5000]: # 2,000 GB stored; how much is read back each month?
costs = {t: monthly_cost(t, 2000, read_gb) for t in TIERS}
print(read_gb, costs, '->', min(costs, key=costs.get))
Storing is billed per GB per month; reading per request and, in colder tiers, per GB read back. The prices are made up to show the rule: unread data in archive, data read now and then in cool, daily data in hot.
Who may read the customer data?
Now Nora's question: who can open the customer file under pii/?
Every request to a cloud is made by a principal: a person, a group, or a program with its own identity (a managed identity on Azure, a role on AWS, a service account on Google Cloud). A policy lists which actions (such as s3:GetObject) a principal may take on which resources.
Three rules decide each request:
- Default deny: nothing is allowed unless something allows it.
- An allow that matches the action and the resource grants it.
- An explicit deny that matches wins over any allow.
Give each pipeline its own identity with only what it needs: least privilege.
Decide four requests like the cloud does
from fnmatch import fnmatch
def is_allowed(policy, action, resource):
def matches(s):
return (any(fnmatch(action, a) for a in s['actions'])
and any(fnmatch(resource, r) for r in s['resources']))
if any(s['effect'] == 'Deny' and matches(s) for s in policy):
return False # an explicit deny always wins
return any(s['effect'] == 'Allow' and matches(s) for s in policy) # default deny
policy = [ # AWS-style statements, simplified: effect, actions, resources (* is a wildcard)
{'effect': 'Allow', 'actions': ['s3:GetObject', 's3:ListBucket'], 'resources': ['swiftkart-lake/*']},
{'effect': 'Allow', 'actions': ['s3:PutObject'], 'resources': ['swiftkart-lake/bronze/*']},
{'effect': 'Deny', 'actions': ['s3:*'], 'resources': ['swiftkart-lake/pii/*']},
]
for action, key in [
('s3:GetObject', 'silver/orders/part-00000.parquet'),
('s3:PutObject', 'silver/orders/part-00000.parquet'),
('s3:PutObject', 'bronze/orders/2025-06-08.csv'),
('s3:GetObject', 'pii/customers.csv'),
]:
print(action, key, '->', is_allowed(policy, action, 'swiftkart-lake/' + key))
Look at the last line: reading pii/customers.csv is refused, although the first statement allows every read in the bucket. Real AWS policies name resources as ARNs such as arn:aws:s3:::swiftkart-lake/bronze/*; Azure grants roles at scopes (Lesson 14.2).
One request, five gates
Those three rules are the core. A real cloud stacks several kinds of policy on top, and a request passes them in order, like the gates at an airport.
On AWS the organisation sets guardrails over every account: resource control policies (RCPs, added in November 2024) and service control policies (SCPs). They grant nothing; they only limit what may be granted.
Follow one request through the five gates. Azure and Google Cloud use the same idea: their order is in the table at the end.
How AWS decides one request
One write request passes five gates in order: no explicit deny, resource control policies, service control policies, an allow from a resource-based or identity-based policy, then boundaries and session policies; a second request for the customer file stops at the first gate.
Gate 1: any explicit Deny? The nightly load asks to write
bronze/orders/2025-06-08.csv. No policy that applies denies it, so it goes on. One matching Deny would end it here.Gates 2 and 3: the guardrails. The RCPs, then the SCPs, must each allow the action. They do.
Gate 4: who grants it? The role's own policy (identity-based) allows
s3:PutObjectonbronze/*. In one account that, or a bucket policy (resource-based), is enough. From another account, both must allow.Gate 5: the limits. A permissions boundary and a session policy only narrow what was granted, so they must allow it too. They do: the file is written.
A second request: read
pii/customers.csv. The role may read the whole bucket, but a Deny onpii/*matches at gate 1. The answer is Deny, and no later gate is looked at.
Read it top to bottom: with no allow, a request stops as an implicit deny at the first gate that needs one.
Remember: nothing is allowed until something allows it, and one matching explicit deny beats every allow. Statement order never matters.
The region you pick sticks
One word on the invoice needs explaining: region. A region is a group of data centres in one area, such as us-east-1 or West Europe. Inside it are availability zones: separate data centres, each with its own power, cooling and network.
You pick a region for latency, law and price, and the choice sticks:
- An S3 bucket's region cannot change, and objects "never leave the Region unless you explicitly transfer or replicate them".
- A BigQuery dataset's location cannot be changed after creation (you copy or replicate it), and a query runs where its data is.
Residency laws apply to every copy: replicas, backups, logs, even a copy job's staging bucket.
Where SwiftKart's bytes pay on AWS
A graph from an S3 bucket in us-east-1 through four paths: a gateway endpoint, free, to the ETL cluster; a NAT gateway at 0.045 dollars per GB to a private cluster; inter-region transfer at 0.02 dollars per GB to a cluster in Ireland; the internet at 0.09 dollars per GB to a partner; and shuffle traffic between zones at 0.01 dollars each way.
Start at the bucket and follow each arrow out: green is free, amber costs cents per GB, red is where the money goes.
Moving bytes is the expensive part
Data coming in from the internet is free. Data moving out, or between places, is billed per GB, by path. That charge is egress. The pattern on every cloud: same region free, nearby cheap, far and public dear. Two prices need a word:
- Between availability zones AWS charges $0.01 per GB each way: $0.02 per GB moved.
- A NAT gateway (a private network's door out) adds $0.045 per GB. An S3 gateway endpoint has no additional charge.
Spark turns the zone rule into a bill. With executors over three zones, about two thirds of a shuffle crosses a zone: a 600 GB shuffle moves about 400 GB. 400 x $0.02 = $8 a run, $240 a month for a daily job.
Ask the bill who spent it
SELECT COALESCE(team, 'untagged') AS team,
service,
SUM(cost_usd) AS total_usd
FROM cloud_costs
GROUP BY 1, 2
ORDER BY total_usd DESC, team, service;
The forgotten VM and the cross-region traffic cost more than the whole pipeline, and neither has a team tag. Real teams tag every resource (team, env, project), set budgets with alerts and review the bill weekly: that is FinOps.
Four classic cloud mistakes. A public bucket. Access keys pasted into code, where they end up in Git. Compute left running over the weekend. Compute in one region reading storage in another, paying egress on every read. Run pipelines as roles or managed identities, never with personal accounts or long-lived keys.
Numbers to remember
| What | The number or the rule |
|---|---|
| S3 request rate | per partitioned prefix, at least 3,500 writes (PUT, COPY, POST, DELETE) and 11,000 reads (GET, HEAD) a second (older pages say 5,500 GETs); one LIST returns at most 1,000 keys |
| S3 consistency | strong for reads and listings right after a write since December 2020; since August 2024 a PUT can carry If-None-Match (create only if absent), which table formats can build commits on |
| Azure Storage | 40,000 requests a second per storage account in large regions, 20,000 elsewhere; 3,000 per block blob |
| Google Cloud Storage | a bucket starts near 1,000 writes and 5,000 reads a second; about one write a second to one object name |
| Tier names | S3 Standard-IA and Glacier Deep Archive; GCS Nearline and Archive; Azure Cool and Archive |
| AWS egress | from us-east-1, list prices of November 2026. Internet: 100 GB free a month across all services and regions, then $0.09 per GB for the first 10 TB; Oregon or Ireland $0.02, Ohio $0.01; a NAT gateway also costs $0.045 an hour |
| Azure egress | from North America or Europe: between zones free; another region on the same continent $0.02, another continent $0.05; internet $0.087 per GB for the first 10 TB, after 100 GB free |
| Google Cloud egress | from us-central1: between zones billed (check the list); same continent $0.02 per GiB; Europe $0.05, Asia $0.08; internet $0.12 per GiB (first TiB, to North America) |
| Azure order | deny assignments, then role assignments at the scope (management Actions, data DataActions), then conditions; on ADLS Gen2, roles before folder ACLs (Lesson 14.2) |
| Google Cloud order | deny policies before allow policies; allow policies are inherited from the organisation down to the resource |
| AWS boundaries | a resource-based policy that names a role session directly is not limited by that session's boundary; one that names the role is |
| Microsoft EU Data Boundary | completed for its cloud services in February 2025 |
What changed at SwiftKart
The two red blocks have names now. A cluster in Ireland read 2 TB a day across regions: $1,200. The nightly load read 2 TB a day through a NAT gateway: $2,700.
You move the cluster next to the bucket and put an S3 gateway endpoint in front of the load. No Spark code changes, and the invoice drops from $5,400 to $1,500.
The rest is housekeeping: a lifecycle rule for old bronze files, one least-privilege role per pipeline, an explicit deny on pii/, nothing public, a team tag on every resource. Interviewers ask for exactly this list: "how would you secure the lake?", "why is the bill high?".
Next, Lesson 14.2 puts the four blocks together on one cloud: Azure.
In one line
Every cloud sells object storage, compute, identity and regions: you pay for what you store, what you ask for and what you move, and nothing is allowed until a policy allows it.
Interview corner
How is object storage different from a file system?
It is a flat key-value store: a key like bronze/orders/a.csv is the whole name, and folders are only shared prefixes. Listing is a prefix query, renaming a folder means copying and deleting every object, and objects are written whole, never appended. That is why lake tables are immutable files plus a metadata log. ADLS Gen2 adds a real hierarchical namespace on top.
How would you control access to a data lake?
One identity per pipeline or team (roles, managed identities, service accounts), each with least privilege on the prefixes or containers it needs. Default deny, explicit denies for sensitive areas such as PII, public access blocked, no long-lived keys in code, and secrets in a secret store. Access is reviewed and logged.
How do you keep cloud storage costs down?
Use tiers: hot for active data, cool or archive for old raw files, moved automatically by lifecycle rules. Store data compressed in columnar formats in files of a healthy size (requests are billed per call: $0.005 per 1,000 PUTs on S3 Standard), delete what you do not need, keep compute in the same region to avoid egress, and tag everything so each team sees its own share of the bill.
The AWS bill doubled but the Spark clusters did not change. Where do you look?
At data transfer, which hides under EC2 and VPC lines rather than under Spark. Group the cost and usage report by usage type: inter-region transfer ($0.02 per GB from us-east-1 to Oregon or Ireland) means compute is reading a bucket in another region; NAT gateway bytes ($0.045 per GB processed) mean private clusters reach S3 without a gateway endpoint, which costs nothing; inter-zone transfer ($0.01 per GB each way) grows with shuffles spread across zones. Then fix the placement: compute next to the data, a gateway endpoint, and zone-aware clusters for shuffle-heavy jobs.