Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 4 of 6 · Worked example · 30 min · revision 1

Estimating a photo-sharing service end to end

Work through a full estimate: an assumptions table with units and ranges, peak load, storage, bandwidth and cache memory by hand and with a Python estimator, a monthly cost model with its dominant driver and sensitivity, and the points where a measurement must replace a guess.

Contentsand lesson path

What you will learn

  • Estimate peak QPS, storage growth, bandwidth and cache memory from stated user and usage assumptions.
  • Use latency and throughput reference numbers to locate the likely bottleneck before choosing components.
  • Turn a capacity estimate into a monthly cost model (compute, storage, egress, managed services), name the dominant cost driver and show how the total moves when the least certain assumption is halved or doubled.

01. The problem

The prompt: design a photo-sharing app where people upload photos and scroll a feed of photos from accounts they follow. After requirements work as in lessons 1 and 2, the agreed scope is: upload a photo, follow an account, scroll a feed, open a photo at full size. Video, comments and search are non-goals. The product team plans for 5 million daily active users (DAU, people who open the app at least once that day) by the end of year one.

Before choosing components, we want peak requests per second, storage after one and five years, egress (data sent to users over the internet, from our servers or our CDN, billed per GB), cache memory, server count and the monthly bill, with its dominant line and how sure we are of it. The method matters more than the answers: every number comes from a written assumption, carries a unit, and has a range.

02. Step 1: write the assumptions down

Each row of the table is one input with its unit, values for three scenarios where we are unsure, and its basis. Best means the lightest load we consider plausible and worst the heaviest we plan for. A row marked guess is a candidate for measurement later.

Assumptions table · photo-sharing service, year 1
Input                              best    expected  worst   unit       basis
daily active users                 3 M     5 M       8 M     users      forecast
uploads per user per day           0.2     0.3       0.5     photos     guess
feed images viewed per user/day    40      60        100     images     guess
full-size opens per user/day       2       2         2       photos     guess
API calls per user per day         40      40        40      requests   guess
peak hour / daily average          2       3         5       ratio      guess
stored original, feed, thumbnail   2.0, 0.25, 0.025          MB         app resizes
metadata per photo                 1,000                     bytes      schema sketch
photos hot enough to cache         last 7 days               days       guess
cache memory per byte of data      1.5                       ratio      measure later
time per request in the API tier   0.05                      s          target
one API server at the p99 target   500                       req/s      load test later
planned utilisation at peak        60%                       -          headroom policy
resize CPU per photo               0.3                       CPU-s      guess, measure
VM price, 4 vCPU and 16 GiB        0.20                      USD/hour   assumed price
managed database and cache         3,600                     USD/month  assumed price

The peak factor (the busiest hour divided by the daily average) is an assumption, not a law: a single-country app sees a sharp evening peak, a global one a flatter curve. Units: storage and traffic use decimal units (1 MB = 10^6 bytes) and memory uses GiB, as in lesson 3. Headroom: planning servers to run at 60% at peak leaves room for a failed server, a deploy or a burst.

03. Step 2: the expected case by hand

Expected case · hand arithmetic, rounded
API, average    5,000,000 users x 40 req/day / 86,400 s     ~ 2,300 req/s
API, peak       2,300 req/s x 3                             ~ 6,900 req/s
In flight       6,900 req/s x 0.05 s  (Little's law)        ~ 350 requests
Uploads         5,000,000 x 0.3 = 1.5 M photos/day          ~ 17/s, ~52/s at peak
Per photo       2.0 + 0.25 + 0.025 MB                       = 2.275 MB
Storage, 1 year 1.5 M/day x 365 days x 2.275 MB             ~ 1,250 TB
Egress per user 60 x 0.25 MB + 2 x 2.0 MB                   = 19 MB/day
Egress, 30 days 5,000,000 x 19 MB x 30                      ~ 2,850 TB
Egress, peak    95 TB/day / 86,400 s x 3 x 8 bits/byte      ~ 26 Gbit/s
Metadata cache  1.5 M/day x 7 days x 1,000 B x 1.5          ~ 15.75 GB = 14.7 GiB
API servers     6,944 req/s / (500 req/s x 0.6)             = 23.1 -> 24

Two lines need explaining. In flight uses Little's law: in a stable system, the average number of requests inside it equals the arrival rate times the average time each one spends there (L = λ × W). It holds for long-run averages when arrivals and departures balance and you count rate and time at the same boundary. It turns 6,900 requests per second into about 350 requests being served at once, which sizes thread pools and database connections.

The metadata cache is sized from the unique items worth keeping: the metadata rows of photos from the last seven days (the CDN caches the image files), times the bytes per entry, times an overhead factor for keys, pointers and allocator waste. It is not reads per second times bytes times seconds; that counts every repeated read of the same photo and can overstate memory many times over.

04. Step 3: run all three scenarios

Hand arithmetic suits one case; a script repeats it for every scenario and for the cost model. Save it as photo_estimate.py. It needs only Python 3.12 and its standard library.

Python · photo_estimate.py
"""Back-of-the-envelope estimate for a photo-sharing service (Python 3.12)."""
import math

DAY_S = 86_400  # seconds in a day
MB, GB, TB, PB = 10**6, 10**9, 10**12, 10**15  # decimal: storage and traffic
GIB = 2**30  # binary: memory

# Every input is an assumption. Units are in the names.
EXPECTED = {
    "dau": 5_000_000,  # daily active users
    "uploads_per_user": 0.3,  # photos uploaded per user per day
    "feed_views_per_user": 60,  # feed-size images viewed per user per day
    "full_opens_per_user": 2,  # full-size photos opened per user per day
    "api_calls_per_user": 40,  # API requests per user per day (no image bytes)
    "peak_factor": 3.0,  # busiest hour divided by the daily average
    "original_mb": 2.0,  # stored original, after the app resizes it
    "feed_mb": 0.25,  # feed-size copy
    "thumb_mb": 0.025,  # thumbnail
    "meta_bytes": 1_000,  # metadata row per photo
    "hot_days": 7,  # photos younger than this get most views: cache them
    "cache_overhead": 1.5,  # keys, pointers and allocator waste per entry
    "api_s": 0.05,  # average time a request spends in the API tier
    "server_rps": 500,  # requests/s one API server handles at the p99 target
    "target_util": 0.6,  # plan to run servers at 60% at peak (headroom)
}
SCENARIOS = {
    "best": EXPECTED | {"dau": 3_000_000, "uploads_per_user": 0.2,
                        "feed_views_per_user": 40, "peak_factor": 2.0},
    "expected": EXPECTED,
    "worst": EXPECTED | {"dau": 8_000_000, "uploads_per_user": 0.5,
                         "feed_views_per_user": 100, "peak_factor": 5.0},
}


def estimate(a: dict) -> dict:
    api_peak = a["dau"] * a["api_calls_per_user"] / DAY_S * a["peak_factor"]
    uploads_day = a["dau"] * a["uploads_per_user"]
    uploads_peak = uploads_day / DAY_S * a["peak_factor"]
    photo_mb = a["original_mb"] + a["feed_mb"] + a["thumb_mb"]
    user_mb = (a["feed_views_per_user"] * a["feed_mb"]
               + a["full_opens_per_user"] * a["original_mb"])
    egress_day = a["dau"] * user_mb * MB
    return {
        "api_avg": api_peak / a["peak_factor"],
        "api_peak": api_peak,
        "in_flight": api_peak * a["api_s"],  # Little's law: L = lambda x W
        "uploads_peak": uploads_peak,
        "ingress_mbit": uploads_peak * a["original_mb"] * 8,  # MB/s x 8 = Mbit/s
        "egress_gbit": egress_day / DAY_S * a["peak_factor"] * 8 / GB,
        "egress_tb_month": egress_day * 30 / TB,
        "stored_tb_1y": uploads_day * 365 * photo_mb * MB / TB,
        "stored_pb_5y": uploads_day * 5 * 365 * photo_mb * MB / PB,
        "cache_gib": (uploads_day * a["hot_days"] * a["meta_bytes"]
                      * a["cache_overhead"] / GIB),
        "api_servers": math.ceil(api_peak / (a["server_rps"] * a["target_util"])),
    }


ROWS = [
    ("API requests, average", "req/s", "api_avg", ",.0f"),
    ("API requests, peak", "req/s", "api_peak", ",.0f"),
    ("API requests in flight, peak", "requests", "in_flight", ",.0f"),
    ("photo uploads, peak", "photos/s", "uploads_peak", ",.0f"),
    ("upload ingress, peak", "Mbit/s", "ingress_mbit", ",.0f"),
    ("image egress, peak", "Gbit/s", "egress_gbit", ",.1f"),
    ("image egress per 30 days", "TB", "egress_tb_month", ",.0f"),
    ("photo storage after 1 year", "TB", "stored_tb_1y", ",.0f"),
    ("photo storage after 5 years", "PB", "stored_pb_5y", ",.1f"),
    ("metadata cache", "GiB", "cache_gib", ",.1f"),
    ("API servers at peak", "servers", "api_servers", ",d"),
]

if __name__ == "__main__":
    results = {name: estimate(a) for name, a in SCENARIOS.items()}
    print(f"{'quantity (unit)':<40}" + "".join(f"{n:>11}" for n in results))
    for label, unit, key, fmt in ROWS:
        cells = "".join(f"{format(r[key], fmt):>11}" for r in results.values())
        print(f"{label + ' (' + unit + ')':<40}{cells}")
Terminal
python3.12 photo_estimate.py
Expected output
quantity (unit)                                best   expected      worst
API requests, average (req/s)                 1,389      2,315      3,704
API requests, peak (req/s)                    2,778      6,944     18,519
API requests in flight, peak (requests)         139        347        926
photo uploads, peak (photos/s)                   14         52        231
upload ingress, peak (Mbit/s)                   222        833      3,704
image egress, peak (Gbit/s)                     7.8       26.4      107.4
image egress per 30 days (TB)                 1,260      2,850      6,960
photo storage after 1 year (TB)                 498      1,246      3,322
photo storage after 5 years (PB)                2.5        6.2       16.6
metadata cache (GiB)                            5.9       14.7       39.1
API servers at peak (servers)                    10         24         62

Depending on the line, the worst case is 3 to 17 times the best case. The spread is honest and still useful: some decisions hold across all of it. Photo storage after one year is 0.5 to 3.3 PB in every scenario, so photos go to object storage (a service that keeps files as objects under a key, such as Amazon S3), not to disks attached to application servers. The metadata cache is 6 to 39 GiB, which fits in the memory of one or two cache servers. Image egress at peak is 8 to 107 Gbit/s; the expected and worst cases exceed what a few servers can send, and in every case a content delivery network (CDN), a set of caching servers close to users, shortens the distance and takes load off our servers. Others, such as the API server count, depend on where we land.

05. Step 4: check the bottlenecks with reference numbers

Lesson 3's ladder shows where time goes on the two main paths. A feed request needs a few lookups inside one zone at a quarter to half a millisecond each, so the server side takes a few milliseconds, as long as lookups are batched rather than made one per photo. An upload is different: a 2 MB photo over a phone connection that uploads at 10 Mbit/s takes about 1.6 seconds before the server sees the last byte. No server change fixes that, so the design should show the photo locally at once and process it in the background. Resize CPU (0.3 CPU-seconds per photo) is only a guess, and the one most likely to be wrong by a large factor.

06. Step 5: a monthly cost model

These are assumed planning prices, close to public list prices but not a quote. For orientation, AWS price lists published in October and November 2026 gave S3 Standard storage in US East at $0.021 to $0.023 per GB-month (one gigabyte stored for one month) and object writes at $0.005 per 1,000, with CloudFront delivery in the US falling from $0.085 per GB for the first 10 TB a month to $0.02 per GB above 5 PB; at about 2,850 TB a month that blends to roughly $0.03 per GB. Prices vary by provider, region, volume and contract. Save this as photo_cost.py next to the first script.

Python · photo_cost.py
"""Monthly cost model for the photo-sharing estimate, month 12 (Python 3.12)."""
import math

from photo_estimate import EXPECTED, SCENARIOS, estimate

# Assumed planning prices in USD. Replace them with your provider's current prices.
PRICE = {
    "vm_hour": 0.20,  # one 4-vCPU, 16 GiB virtual machine, per hour
    "storage_gb_month": 0.021,  # standard object storage at petabyte volume
    "egress_gb": 0.03,  # CDN delivery to users, blended at petabyte volume
    "put_per_million": 5.00,  # object writes: original, feed size, thumbnail
    "managed_month": 3_600,  # managed database + cache cluster, flat
}
HOURS_PER_MONTH = 730
RESIZE_CORE_S = 0.3  # CPU seconds to make the copies of one photo: measure it!
CORES_PER_VM = 4


def monthly_cost(a: dict) -> dict:
    e = estimate(a)
    workers = math.ceil(e["uploads_peak"] * RESIZE_CORE_S
                        / (CORES_PER_VM * a["target_util"]))
    uploads_month = a["dau"] * a["uploads_per_user"] * 30
    return {
        "compute": (e["api_servers"] + workers) * HOURS_PER_MONTH * PRICE["vm_hour"],
        "storage": e["stored_tb_1y"] * 1000 * PRICE["storage_gb_month"],
        "egress": e["egress_tb_month"] * 1000 * PRICE["egress_gb"],
        "requests": uploads_month * 3 / 1e6 * PRICE["put_per_million"],
        "managed": PRICE["managed_month"],
    }


cost = monthly_cost(EXPECTED)
total = sum(cost.values())
print("Expected case, month 12 (USD per month)")
for item, usd in sorted(cost.items(), key=lambda kv: -kv[1]):
    print(f"   {item:<10}{usd:>10,.0f} USD/month  {usd / total:>4.0%}")
print(f"   {'total':<10}{total:>10,.0f} USD/month")
print(f"   per daily active user: {total / EXPECTED['dau']:.3f} USD/month")

print("Total per scenario (USD per month)")
for name, a in SCENARIOS.items():
    print(f"   {name:<10}{sum(monthly_cost(a).values()):>10,.0f} USD/month")

print("Total when one assumption is halved or doubled (USD per month)")
print(f"   {'assumption':<28}{'x0.5':>10}{'x1':>10}{'x2':>10}")
for key in ("feed_views_per_user", "feed_mb", "dau", "peak_factor", "server_rps"):
    totals = [sum(monthly_cost(EXPECTED | {key: EXPECTED[key] * f}).values())
              for f in (0.5, 1, 2)]
    cells = "".join(f"{t:>10,.0f}" for t in totals)
    print(f"   {key:<28}{cells}  USD/month")
Terminal
python3.12 photo_cost.py
Expected output
Expected case, month 12 (USD per month)
   egress        85,500 USD/month   71%
   storage       26,157 USD/month   22%
   compute        4,526 USD/month    4%
   managed        3,600 USD/month    3%
   requests         675 USD/month    1%
   total        120,458 USD/month
   per daily active user: 0.024 USD/month
Total per scenario (USD per month)
   best          53,885 USD/month
   expected     120,458 USD/month
   worst        297,238 USD/month
Total when one assumption is halved or doubled (USD per month)
   assumption                        x0.5        x1        x2
   feed_views_per_user             86,708   120,458   187,958  USD/month
   feed_mb                         85,271   120,458   190,832  USD/month
   dau                             62,102   120,458   237,170  USD/month
   peak_factor                    118,268   120,458   124,838  USD/month
   server_rps                     123,816   120,458   118,706  USD/month

Egress is the dominant cost driver: 71% of about $120,000 a month, or about 2.4 cents per daily user, while servers are 4%. Storage is second today, but it grows every month while egress follows active users; with these inputs storage overtakes egress after about 40 months, unless old photos move to a cheaper storage class.

Halving and doubling one input at a time, DAU moves the total most, but it is the forecast that everything scales with, so report it as cost per user. Among our own guesses, feed images viewed per user is the least certain (no app data exists yet) and it drives the largest line: halving it gives about $87,000, doubling it about $188,000, and image size behaves the same way. The peak factor and server capacity hardly move the bill, because bytes are billed, not peaks; they still decide server and network capacity for the busiest evening. With scenario totals of about $54,000, $120,000 and $297,000, a review summary reads: roughly $50,000 to $300,000 a month in year one, about $120,000 expected, driven by image egress and most sensitive to views per user.

07. Step 6: where estimates stop and measurements start

Replace a guess with a measurement when a decision depends on it, when its range crosses a decision boundary, or when it drives the dominant cost. Here that gives a short list:

  1. Feed views and image size per user: measure them in a beta before committing to a CDN contract.
  2. Resize cost per photo: time the resize code on real phone photos on the planned instance type.
  3. Requests per second per API server: load-test one server with a realistic request mix until its p99 crosses the target.
  4. Peak factor: count requests per minute over a few weeks of beta traffic.
  5. Cache overhead: load a million real entries into the cache and read its memory statistics.

Each result goes into the table with its date and setup.

08. Check your understanding

Practice check · 3 questions

Estimates that hold up

Three new situations. Use the method of this lesson, not its numbers.

Q1. A teammate sizes a user-session cache as "peak reads per second × 600 bytes per read × 86,400 seconds". What is wrong with this formula?
Q2. In a beta of a single-country app, 60% of each day's requests arrive between 19:00 and 22:00, spread evenly over those three hours. Which peak factor (busiest hour divided by the average hour) belongs in the assumptions table?
Q3. In your cost model, egress is 70% of the total and rests on a guessed number of image views per user. Compute is 5% and rests on a guessed capacity per server. You can measure one of them this week. Which should it be?
Practice only: not graded, not saved, not evidence.

09. Apply it

Add estimates to your three practice pages. Copy photo_estimate.py once per prompt and replace the inputs and rows with your own:

  1. Paste service: pastes per day, paste size, reads per paste (the read/write ratio) and retention give peak read and write QPS, five-year storage and egress.
  2. Ride-hailing location service: drivers online at the busiest hour and the reporting interval give peak position writes per second, memory for the latest position of every driver, and update bandwidth to riders.
  3. Metrics pipeline: servers, measurements per server, interval and bytes per point give points per second at peak, five-year storage under your retention rule, and egress to dashboards.

For each page, write an assumptions table with a basis column, a best/expected/worst range for at least two inputs, a monthly cost with its dominant driver, and the total when the least certain input is halved and doubled.

10. Review prompt

Without looking back, answer in your own words:

  1. What does Little's law say, when does it apply, and what did it tell us here?
  2. How do you size a cache, and why is reads per second the wrong starting point?
  3. Which line dominated the photo service bill, which assumption was least certain, and how did the total move when it was halved and doubled?
  4. Name three estimates in this lesson that should be replaced by measurements, and how you would measure each.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check