Show contents
Chapter 6 of 7 · 25 min
Project: the architecture of an exam platform
By the end of this chapter, you'll be able to
- Turn needs into numerical criteria
- Estimate an architecture's monthly cost from prices
- Compute two options' availability and how they handle the peak
- Write a reasoned recommendation for a decision-maker
The needs
- at most 300 requests per second normally, 3,000 during exam week;
- target availability: at least 99.9%, especially during exams;
- subjects and materials in PDF, about 2 TB downloaded per month;
- a budget to stick to, and student data stored in the region where the schools are.
All the prices below are example prices, invented for the exercise.
Two architectures
- Option A, the simple one: 2 fixed virtual machines in a single zone, a single database, PDFs served straight from object storage;
- Option B, the resilient one: servers spread over 2 zones with autoscaling, a managed database with a replica in the other zone, and a CDN in front of the PDFs.
import math
PRICES = {"vm_h": 0.08, "db": 150, "db_replica": 150, "egress_gb": 0.09, "cdn_gb": 0.03}
VM_CAPACITY, TARGET = 200, 0.6
HOURS_MONTH, EXAM_HOURS = 730, 7 * 24
def vms(requests_per_s):
return max(2, math.ceil(requests_per_s / (VM_CAPACITY * TARGET)))
def cost_a():
compute = 2 * HOURS_MONTH * PRICES["vm_h"]
return compute + PRICES["db"] + 2000 * PRICES["egress_gb"]
def cost_b():
normal = vms(300) * (HOURS_MONTH - EXAM_HOURS) * PRICES["vm_h"]
peak = vms(3000) * EXAM_HOURS * PRICES["vm_h"]
return normal + peak + PRICES["db"] + PRICES["db_replica"] + 2000 * PRICES["cdn_gb"]
capacity_a = 2 * VM_CAPACITY
print(f"A: {cost_a():.0f} $/month, capacity {capacity_a} req/s → handles the peak: {capacity_a >= 3000}")
print(f"B: {cost_b():.0f} $ in the exam month, {vms(300)} VMs normally, {vms(3000)} during exams")
A: 447 $/month, capacity 400 req/s → handles the peak: False
B: 831 $ in the exam month, 3 VMs normally, 25 during exams
Option A costs less… but it simply cannot absorb exam week: 400 requests per second at best, against 3,000 required. Option B adjusts its servers (3 normally, 25 at the peak) and serves PDFs through the CDN, which reduces egress fees.
Availability
def series(*a):
total = 1.0
for x in a:
total *= x
return total
def parallel(*a):
down = 1.0
for x in a:
down *= 1 - x
return 1 - down
ZONE, VM, DB = 0.999, 0.99, 0.9995
option_a = series(ZONE, parallel(VM, VM), DB)
option_b = series(parallel(ZONE, ZONE), parallel(VM, VM, VM), parallel(DB, DB))
for name, a in (("A", option_a), ("B", option_b)):
print(f"{name}: {a:.4%}, i.e. {8760 * 60 * (1 - a):.0f} min of downtime per year")
A: 99.8401%, i.e. 841 min of downtime per year
B: 99.9998%, i.e. 1 min of downtime per year
In option A, the single zone and the single database are two single points of failure. Option B has none left, provided failures in the two zones are truly independent, and the database failover is tested.
The extra cost buys the only option that meets the needs: explain it in one page.
Text description of the animation
- Start with numerical criteria, agreed with management.
- Compare realistic options, not a single imposed solution.
- B costs more, especially in the exam month.
- A misses the objective and cannot handle the peak; B exceeds the objective.
- The extra cost buys the only option that meets the needs: explain it in one page.
The recommendation
A decision-maker expects a clear conclusion, honest about the assumptions:
Recommendation: option B. It is the only one that handles the exam peak (3,000 requests per second) and exceeds the 99.9% objective. It costs about 1,350 $ more per year than option A (more in June, the exam month), and option A does not meet the needs. Assumptions: example prices to be replaced by the chosen provider's, peak traffic estimated from last year, database failover to be tested before the exam period.
Mini-lab: what if traffic doubled?Python 3.13
Output
Click “Run”: Python will load in your browser (about 10 MB the first time).Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor
Your turn
Worked exercise
Worked exercise: the cost per student
The network has 12,000 students. Management wants to know each option's monthly cost per student, and option B's extra annual cost (over 12 months, with an exam week only in June: for the other 11 months, option B has no peak). Use the study's costs: A costs 447 $ per month all year; B costs 831 $ in June and 535 $ in the other months.
Hint 1
Hint 2
Show the solution and common mistakes
students = 12_000
annual_a = 12 * 447
annual_b = 831 + 11 * 535
for name, annual in (("A", annual_a), ("B", annual_b)):
print(f"{name}: {annual} $/year, i.e. {annual / 12 / students * 100:.2f} cents per student per month")
print(f"B's extra cost: {annual_b - annual_a} $ per year")
A: 5364 $/year, i.e. 3.72 cents per student per month
B: 6716 $/year, i.e. 4.66 cents per student per month
B's extra cost: 1352 $ per year
About one cent per student per month separates the two options: presented this way, choosing reliability becomes obvious to management. Bringing a cost down to a unit that speaks to the decision-maker (per student, per order, per user) often helps decide.
Common mistakes:
- Counting the exam peak twelve times a year: B's cost would be overestimated.
- Dividing the annual cost by the number of students without bringing it down to the month: you then compare different quantities.
Summary
- 1An architecture study starts from numerical needs: peak load, availability, budget, data constraints.
- 2Cost is estimated item by item: compute (including at the peak), database, transfers.
- 3Availability is computed in series and in parallel; every single point of failure limits it.
- 4First eliminate the options that do not meet the needs, then compare costs.
- 5The recommendation fits in one page: conclusion, key figures and assumptions to check.
Your progress is saved on this device. Create a free account to keep your progress on all your devices.