TT Lab
Get started
Learn Learning paths Courses

Cost and Architectural Decisions

Find the Top Line of the Bill by Calculation

Continue in TT Lab

Goal

What makes transfer charges frightening is not the amount but that you cannot see where they came from. This lab lays out an architecture's traffic paths as a table, without a cloud account, and you build by hand a calculator that reads that table and a spike detector.

Price table (assumptions for this lab)

Path Unit price
Internet ingress $0 per GB
Internet egress $0.09 per GB
Within the same AZ $0 per GB
Between AZs $0.01 on each side, effectively $0.02 per GB
Between regions $0.02 per GB
NAT gateway $0.045 per GB of throughput, $0.045 per hour standing (730 hours a month)
CDN egress $0.06 per GB

Rates differ by provider and region. What you learn here is not the values but how to get the order of magnitude.

Traffic paths (monthly transfer volume)

Path Type Monthly transfer volume
Internet to the web tier ingress 3,000 GB
Web tier to the internet egress 26,000 GB
App (AZ-a) and DB (AZ-b) cross-az 8,000 GB
App to object storage (via NAT) nat 5,000 GB
Logs to a collector in another region cross-region 1,200 GB
Web and cache (same AZ) same-az 20,000 GB

Of the 26,000 GB of egress, 18,000 GB is API responses averaging 20KB, and the remaining 8,000 GB is images and video that are already compressed.

What you build

File Contents
/root/transfer/paths.csv Transfer volume and charge per path
/root/transfer/02-top3.md The top three charges and the total
/root/transfer/bill.py A calculator that reads the table
/root/transfer/04-gzip.md Savings from compression
/root/transfer/05-cdn.md CDN comparison and break-even hit rate
/root/transfer/daily.csv · spike.py Transfer spike detection
/root/transfer/07-notes.md Summary

Notes

The calculator in step 3 and the detector in step 6 are tested by the grader with a hidden table. Only if they stay correct when the table is swapped can you use them in a design meeting.

Turn the paths into a table

Write the six paths from the instructions to /root/transfer/paths.csv in four columns, 경로,종류,월GB,월요금 (path, type, monthly GB, monthly charge). For free paths, also write the charge as 0.

There are six values for 종류 (type) — ingress, egress, same-az, cross-az, cross-region, nat — and each appears on one line.

For the charge, just multiply by the value in the price table. Cross-AZ is charged on both the sending and the receiving side, for an effective $0.02 per GB — counting only half of it is the most common mistake.

Do not drop free paths from the table. If you cannot see what is free, you cannot decide what to move and where in the next step.

Rank them from the largest charge

Write the three largest charge items in /root/transfer/02-top3.md, and add a line for each saying what to change to reduce it. On the last line, write the monthly total including the NAT standing charge (730 hours × $0.045).

The ranking comes straight from the table in step 1. Look at how much the orders of magnitude of the three items differ.

The ways to reduce are all in the earlier reading. It is one of three: changing the path, changing the placement, or reducing the size.

Separately from the throughput charge, a NAT has an hourly charge that applies just for being up. That does not go away even if you reduce traffic.

A calculator that stays correct when the table is swapped

Create /root/transfer/bill.py. When called as python3 /root/transfer/bill.py <경로CSV>, it must print the charge for each line and print 합계,<숫자> on the last line. The standing charge does not depend on the transfer volume, so do not count it. (The placeholders stand for the path CSV file and the total number.)

Keep the unit prices as constants inside the script. Copy the price table from the instructions as it is.

The 종류 (type) column determines the unit price, and multiplying by 월GB (monthly GB) gives the charge for that line. Ignore the fourth column even if it is present — the calculator is only meaningful if it recalculates.

The grader also runs it with a hidden table. Only if it stays correct when the table is swapped can you use it in a design meeting.

Write the value of compression as an amount

Of the 26,000 GB of egress, 18,000 GB is API responses averaging 20KB. If gzip brings the average to 5KB, write in /root/transfer/04-gzip.md what the transfer volume and the savings are, and what should be excluded from compression.

If 20KB becomes 5KB, the transfer volume becomes one quarter. What does 18,000 GB become, and how much is saved?

Multiply the saved GB by the egress unit price of $0.09 to get the monthly savings.

The remaining 8,000 GB is images and video that are already compressed, so applying gzip does not shrink them and only uses CPU. And do not compress streaming responses — chunks pool in the buffer, and streaming stops being streaming.

Find the point where the CDN becomes cheaper

Put the 8,000 GB of images and video behind a CDN. Write in /root/transfer/05-cdn.md the monthly charge and savings at a 90% hit rate, and the hit rate above which the CDN is cheaper.

Right now the 8,000 GB goes straight out of the origin. At a 90% hit rate, only 10% goes out of the origin, and the CDN sends all 8,000 GB to users. Origin egress is $0.09 and CDN egress is $0.06. The sum of the two amounts is the charge after putting a CDN in place.

For the break-even, let the hit rate be h and solve 8000 × (1 - h) × 0.09 + 8000 × 0.06 = 720. Write it as a percentage.

A mechanism that tells you before the bill does

Create /root/transfer/spike.py. It reads a table in the form 날짜,GB (date, GB), prints one line for each day that is at least 3 times the median of the preceding 7 days, and must exit with code 1 if there is at least one and 0 if there are none. Skip days without the preceding 7 days collected. Create the test sample yourself in /root/transfer/daily.csv.

Billing alerts usually arrive too late. By the time the alert says you have passed half the monthly budget, several days' worth has already gone out.

It is much faster to treat transfer volume itself as a metric and alert when it reaches some multiple of normal. The reason for using the median is that the mean gets pulled toward the spike day itself.

statistics.median is enough. If you set the threshold too low, alerts come every day, and an alert that comes every day ends up being looked at by no one — the grader checks that too.

Summarize three things

Write at least three lines in /root/transfer/07-notes.md: the direction in which charges apply, why charges rise after a multi-AZ setup, and what to manage by instead of charges.

The text must include 이그레스, AZ, and 전송량 (egress, AZ, transfer volume).