Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

System Design (High-Level Design)  Module 2 – Back-of-the-envelope estimation

Estimating traffic: users to requests per second

Turn daily active users and actions per user into average and peak requests per second, split reads from writes and pick a peak factor from the traffic shape.

  • Beginner
  • 15 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0 and quickjs 0.32.0
  • By MySmartCoPilot
Free lesson, Pro answers: 15 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

What you will learn

  • Calculate average and peak requests per second from daily active users and actions per user
  • Separate read traffic from write traffic and justify the ratio you assume
  • Choose a peak factor from the shape of the traffic and the window it applies to
  • Check an estimate against a published total by the share it implies

Before you start

What you’ll learn · Before you start

What you will learn

  • Calculate average and peak requests per second from daily active users and actions per user
  • Separate read traffic from write traffic and justify the ratio you assume
  • Choose a peak factor from the shape of the traffic and the window it applies to
  • Check an estimate against a published total by the share it implies

Before you start

On this page

Fifty million people who each make 120 requests a day send 6 billion requests: 69,444 a second on average, and about 208,000 a second at a peak three times as busy. The first sizing question of almost every design is how much traffic it must carry: how many requests a second, of which kind, at the worst moment. Everything else follows from that answer.

A thousand requests a second fits comfortably on a few servers; a few hundred thousand writes a second needs a partitioned database and a careful write path. This lesson turns the numbers a product team gives you (users and what they do) into the numbers an engineer sizes things with (requests per second), and shows where the peak comes from instead of guessing it.

Users and their requests set the average rate

Start from daily active users (DAU): The number of different people who use a product on a typical day. It can never exceed the monthly active users, and it is the usual starting point of a traffic estimate.: the people who use the product on a typical day. If you are given monthly active users instead, assume what share of them come on a given day and say so, because daily users can never be more than monthly ones. Then count what each of them makes in a day. Count requests to your servers, not taps on a screen: one screen may load with several API calls, and an app may sync in the background.

Daily active users become requests a day, then an average and a peak rate per second, which splits into reads and writes.Daily active usersRequests a dayAveragerequests a secondPeakrequests a secondPeak readsa secondPeak writesa second× requests peruser a day÷ 86,400× peak factorfor a window× read share× write share

From users to requests per second

Text description of the diagram

The diagram is a chain of boxes from top to bottom.

  1. Daily active users, multiplied by the reads and writes each user makes in a day, give the requests a day.
  2. The requests a day, divided by 86,400 seconds, give the average requests a second.
  3. The average, multiplied by a peak factor for a stated window such as the busiest hour or second, gives the peak requests a second.
  4. The peak splits into two boxes: peak reads a second and peak writes a second, each the peak multiplied by its share of the traffic.

In symbols, with the 86,400 seconds of a day from the lesson on units:

average per second=DAU×requests per user per day86400,peak=average×peak factor\text{average per second} = \frac{\text{DAU} \times \text{requests per user per day}}{86400}, \qquad \text{peak} = \text{average} \times \text{peak factor}

Follow one service, chat, down the chain one step at a time, with the assumptions of the program below:

Interactive · step by step One service through the chain, chat Step from chat's daily users to its peak reads and writes a second, one multiplication or division at a time.
One service through the chain, chat, step 7 of 7. Showing 50 million daily users, 6 billion requests a day, 69,444 a second, 208,333 a second, 138,889 reads a second, 69,444 writes a second. In focus: 138,889 reads a second, 69,444 writes a second.× (80 reads + 40 writes)÷ 86,400 seconds× peak factor 3× 80 of 120× 40 of 12050 million daily usersthe chat service6 billion requests a day120 per user a day69,444 a secondthe average208,333 a secondthe peak, factor 3138,889 reads a secondat the peak69,444 writes a secondat the peak

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. The users. Chat starts from its assumed 50 million daily active users, the people who use it on a typical day.
  2. Requests a day. Each user is assumed to make 80 reads and 40 writes a day, counted as requests to the servers. 50 million × 120 is 6 billion requests a day.
  3. The average. Spread evenly over the 86,400 seconds of a day, 6 billion requests are 69,444 a second. That is the average, night included.
  4. The peak. The assumed peak factor of 3 for the busiest window gives 208,333 requests a second, the number the design has to carry.
  5. Reads at the peak. 80 of every 120 requests are reads, 138,889 a second at the peak. Reads can be answered from copies, so caches and read replicas carry them.
  6. Writes at the peak. The other 40 of 120 are writes, 69,444 a second. Every write must reach the copy that owns its data, and a write rate this high pushes towards partitioning.
  7. The same chain, other numbers. The program runs the same chain for the news feed and for payments. The news feed peaks at 289 writes a second against 28,935 reads, so its design is about the read path instead.

This program applies the formula to three services with assumptions you can change, in 14 languages:

One program · 14 languages Average and peak traffic for three services

Python 3.14 · main.py

from typing import NamedTuple

DAY = 86_400  # seconds


class Service(NamedTuple):
    """Daily active users, reads and writes per user a day, and the peak factor."""

    name: str
    dau: int
    reads: float
    writes: float
    peak_factor: float


class Estimate(NamedTuple):
    daily: float
    average: float
    peak: float
    peak_reads: float
    peak_writes: float


SERVICES = [
    Service("chat", 50_000_000, 80, 40, 3),
    Service("news feed", 20_000_000, 50, 0.5, 2.5),
    Service("payments", 30_000_000, 4, 2, 4),
]


def estimate(s: Service) -> Estimate:
    """Average and peak requests a second, the peak split into reads and writes."""
    daily = s.dau * (s.reads + s.writes)
    average = daily / DAY
    return Estimate(
        daily=daily,
        average=average,
        peak=average * s.peak_factor,
        peak_reads=s.dau * s.reads / DAY * s.peak_factor,
        peak_writes=s.dau * s.writes / DAY * s.peak_factor,
    )


print(
    f"{'Service':<11}{'per day':>15}{'average/s':>11}{'peak/s':>10}"
    f"{'reads/s':>10}{'writes/s':>10}{'reads:writes':>14}"
)
for s in SERVICES:
    e = estimate(s)
    print(
        f"{s.name:<11}{e.daily:>15,.0f}{e.average:>11,.0f}{e.peak:>10,.0f}"
        f"{e.peak_reads:>10,.0f}{e.peak_writes:>10,.0f}{s.reads / s.writes:>12,.0f}:1"
    )

In Python: The format spec :>15,.0f rounds to a whole number, puts a comma between each group of three digits and pads to 15 characters in one step; NamedTuple gives each service named fields.

Recorded with CPython 3.14.8 on macOS 26 arm64. It runs in your browser with Pyodide 314.0.7 (CPython 3.14.2). To run it yourself: python3 main.py

JavaScript Node 24 · main.mjs

const DAY = 86_400; // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
const SERVICES = [
  { name: "chat", dau: 50_000_000, reads: 80, writes: 40, peakFactor: 3 },
  { name: "news feed", dau: 20_000_000, reads: 50, writes: 0.5, peakFactor: 2.5 },
  { name: "payments", dau: 30_000_000, reads: 4, writes: 2, peakFactor: 4 },
];

// Average and peak requests a second, the peak split into reads and writes.
function estimate({ dau, reads, writes, peakFactor }) {
  const daily = dau * (reads + writes);
  const average = daily / DAY;
  return {
    daily,
    average,
    peak: average * peakFactor,
    peakReads: ((dau * reads) / DAY) * peakFactor,
    peakWrites: ((dau * writes) / DAY) * peakFactor,
  };
}

// A whole number with a comma between each group of three digits.
const group = (x) =>
  Math.round(x)
    .toString()
    .replace(/\B(?=(\d{3})+(?!\d))/g, ",");

const head = ["per day", "average/s", "peak/s", "reads/s", "writes/s"];
const widths = [15, 11, 10, 10, 10];
const pad = (cells) => cells.map((cell, i) => cell.padStart(widths[i])).join("");
console.log("Service".padEnd(11) + pad(head) + "reads:writes".padStart(14));
for (const s of SERVICES) {
  const e = estimate(s);
  const cells = [e.daily, e.average, e.peak, e.peakReads, e.peakWrites].map(group);
  console.log(s.name.padEnd(11) + pad(cells) + `${group(s.reads / s.writes)}:1`.padStart(14));
}

In JavaScript: No format spec for digit groups works in every runtime, so group rounds with Math.round and inserts the commas with a regular expression; pad lines the cells up from a list of widths.

Recorded with Node.js 24.21.0 LTS (V8 13.6) on macOS 26 arm64. It runs in your browser with QuickJS (quickjs-emscripten 0.32.0). To run it yourself: node main.mjs

Java 25 LTS · Main.java

import java.util.List;
import java.util.Locale;

public class Main {
  static final int DAY = 86_400; // seconds

  /** Daily active users, reads and writes per user a day, and the peak factor. */
  record Service(String name, long dau, double reads, double writes, double peakFactor) {}

  record Estimate(double daily, double average, double peak, double peakReads, double peakWrites) {}

  /** Average and peak requests a second, the peak split into reads and writes. */
  static Estimate estimate(Service s) {
    double daily = s.dau() * (s.reads() + s.writes());
    double average = daily / DAY;
    return new Estimate(
        daily,
        average,
        average * s.peakFactor(),
        s.dau() * s.reads() / DAY * s.peakFactor(),
        s.dau() * s.writes() / DAY * s.peakFactor());
  }

  public static void main(String[] args) {
    Locale.setDefault(Locale.ROOT);
    List<Service> services =
        List.of(
            new Service("chat", 50_000_000, 80, 40, 3),
            new Service("news feed", 20_000_000, 50, 0.5, 2.5),
            new Service("payments", 30_000_000, 4, 2, 4));
    System.out.printf(
        "%-11s%15s%11s%10s%10s%10s%14s%n",
        "Service", "per day", "average/s", "peak/s", "reads/s", "writes/s", "reads:writes");
    for (Service s : services) {
      Estimate e = estimate(s);
      System.out.printf(
          "%-11s%,15.0f%,11.0f%,10.0f%,10.0f%,10.0f%,12.0f:1%n",
          s.name(),
          e.daily(),
          e.average(),
          e.peak(),
          e.peakReads(),
          e.peakWrites(),
          s.reads() / s.writes());
    }
  }
}

In Java: printf's , flag groups the digits of %,15.0f, and Locale.ROOT makes the separator a comma whatever the computer's locale; records hold a service and its estimate.

Recorded with OpenJDK 25.0.4.1 LTS (Eclipse Temurin) on macOS 26 arm64. To run it yourself: java Main.java

C++23 · main.cpp

#include <array>
#include <cstddef>
#include <format>
#include <print>
#include <string>
#include <string_view>

constexpr double day = 86'400; // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
struct Service {
  std::string_view name;
  double dau, reads, writes, peak_factor;
};

struct Estimate {
  double daily, average, peak, peak_reads, peak_writes;
};

// Average and peak requests a second, the peak split into reads and writes.
Estimate estimate(const Service &s) {
  const double daily = s.dau * (s.reads + s.writes);
  const double average = daily / day;
  return {daily, average, average * s.peak_factor,
          s.dau * s.reads / day * s.peak_factor,
          s.dau * s.writes / day * s.peak_factor};
}

// A whole number with a comma between each group of three digits.
std::string group(double x) {
  std::string digits = std::format("{:.0f}", x);
  for (auto i = static_cast<std::ptrdiff_t>(digits.size()) - 3; i > 0; i -= 3) {
    digits.insert(static_cast<std::size_t>(i), ",");
  }
  return digits;
}

int main() {
  constexpr std::array<Service, 3> services{{
      {"chat", 50'000'000, 80, 40, 3},
      {"news feed", 20'000'000, 50, 0.5, 2.5},
      {"payments", 30'000'000, 4, 2, 4},
  }};
  std::println("{:<11}{:>15}{:>11}{:>10}{:>10}{:>10}{:>14}", "Service",
               "per day", "average/s", "peak/s", "reads/s", "writes/s",
               "reads:writes");
  for (const Service &s : services) {
    const Estimate e = estimate(s);
    std::println("{:<11}{:>15}{:>11}{:>10}{:>10}{:>10}{:>12}:1", s.name,
                 group(e.daily), group(e.average), group(e.peak),
                 group(e.peak_reads), group(e.peak_writes),
                 group(s.reads / s.writes));
  }
}

In C++: std::format has no digit grouping without a locale, so group formats the rounded number and inserts a comma before every third digit from the right.

Recorded with Apple clang 21.0.0 (C++23) and GCC 16.2.0 on macOS 26 arm64. It runs in your browser with Clang in WebAssembly (YoWASP) 22.0.0-git20542-10. To run it yourself: clang++ -std=c++23 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined main.cpp -o main && ./main

C# 14 · .NET 10 · app.cs

using System.Globalization;

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

const int Day = 86_400; // seconds

Service[] services =
[
    new("chat", 50_000_000, 80, 40, 3),
    new("news feed", 20_000_000, 50, 0.5, 2.5),
    new("payments", 30_000_000, 4, 2, 4),
];

Console.WriteLine(
    $"{"Service",-11}{"per day",15}{"average/s",11}{"peak/s",10}{"reads/s",10}{"writes/s",10}"
    + $"{"reads:writes",14}");
foreach (Service s in services)
{
    Estimate e = EstimateOf(s);
    Console.WriteLine(
        $"{s.Name,-11}{e.Daily,15:N0}{e.Average,11:N0}{e.Peak,10:N0}{e.PeakReads,10:N0}"
        + $"{e.PeakWrites,10:N0}{s.Reads / s.Writes,12:N0}:1");
}

// Average and peak requests a second, the peak split into reads and writes.
static Estimate EstimateOf(Service s)
{
    double daily = s.Dau * (s.Reads + s.Writes);
    double average = daily / Day;
    return new Estimate(
        daily,
        average,
        average * s.PeakFactor,
        s.Dau * s.Reads / Day * s.PeakFactor,
        s.Dau * s.Writes / Day * s.PeakFactor);
}

// Daily active users, reads and writes per user a day, and the peak factor.
record Service(string Name, long Dau, double Reads, double Writes, double PeakFactor);

record Estimate(double Daily, double Average, double Peak, double PeakReads, double PeakWrites);

In C#: The N0 format rounds to a whole number and groups the digits; with the invariant culture the separator is a comma on every computer. EstimateOf is a static local function.

Recorded with C# 14 on .NET 10.0.12 (SDK 10.0.401) on macOS 26 arm64. It runs in your browser with the .NET runtime for WebAssembly 10.0.12. To run it yourself: dotnet run app.cs

C23 · main.c

#include <stddef.h>
#include <stdio.h>

constexpr double day = 86400; // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
typedef struct {
  const char *name;
  double dau, reads, writes, peak_factor;
} Service;

typedef struct {
  double daily, average, peak, peak_reads, peak_writes;
} Estimate;

// Average and peak requests a second, the peak split into reads and writes.
static Estimate estimate(const Service *s) {
  const double daily = s->dau * (s->reads + s->writes);
  const double average = daily / day;
  return (Estimate){daily, average, average * s->peak_factor,
                    s->dau * s->reads / day * s->peak_factor,
                    s->dau * s->writes / day * s->peak_factor};
}

// A whole number with a comma between each group of three digits.
static void group(double x, char out[static 32]) {
  char digits[24];
  const int n = snprintf(digits, sizeof digits, "%.0f", x);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0 && (n - i) % 3 == 0) {
      out[j++] = ',';
    }
    out[j++] = digits[i];
  }
  out[j] = '\0';
}

int main(void) {
  static const Service services[] = {
      {"chat", 50000000, 80, 40, 3},
      {"news feed", 20000000, 50, 0.5, 2.5},
      {"payments", 30000000, 4, 2, 4},
  };
  printf("%-11s%15s%11s%10s%10s%10s%14s\n", "Service", "per day", "average/s",
         "peak/s", "reads/s", "writes/s", "reads:writes");
  for (size_t i = 0; i < sizeof services / sizeof services[0]; i++) {
    const Service *s = &services[i];
    const Estimate e = estimate(s);
    const double values[] = {e.daily,      e.average,     e.peak,
                             e.peak_reads, e.peak_writes, s->reads / s->writes};
    const int widths[] = {15, 11, 10, 10, 10, 12};
    printf("%-11s", s->name);
    for (size_t k = 0; k < sizeof values / sizeof values[0]; k++) {
      char text[32];
      group(values[k], text);
      printf("%*s", widths[k], text);
    }
    puts(":1");
  }
  return 0;
}

In C: printf's ' flag for digit groups is POSIX and follows the locale, so group builds the grouped text itself; the widths of the six columns sit in an array beside the values.

Recorded with Apple clang 21.0.0 (C23) and GCC 16.2.0 on macOS 26 arm64. It runs in your browser with Clang in WebAssembly (YoWASP) 22.0.0-git20542-10. To run it yourself: clang -std=c23 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined main.c -o main && ./main

PHP 8.5 · main.php

<?php

declare(strict_types=1);

const DAY = 86_400; // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
final readonly class Service
{
    public function __construct(
        public string $name,
        public int $dau,
        public float $reads,
        public float $writes,
        public float $peakFactor,
    ) {}
}

/**
 * Average and peak requests a second, the peak split into reads and writes.
 *
 * @return array{daily: float, average: float, peak: float, peakReads: float, peakWrites: float}
 */
function estimate(Service $s): array
{
    $daily = $s->dau * ($s->reads + $s->writes);
    $average = $daily / DAY;
    return [
        'daily' => $daily,
        'average' => $average,
        'peak' => $average * $s->peakFactor,
        'peakReads' => $s->dau * $s->reads / DAY * $s->peakFactor,
        'peakWrites' => $s->dau * $s->writes / DAY * $s->peakFactor,
    ];
}

$services = [
    new Service('chat', 50_000_000, 80, 40, 3),
    new Service('news feed', 20_000_000, 50, 0.5, 2.5),
    new Service('payments', 30_000_000, 4, 2, 4),
];

$head = ['Service', 'per day', 'average/s', 'peak/s', 'reads/s', 'writes/s', 'reads:writes'];
printf("%-11s%15s%11s%10s%10s%10s%14s\n", ...$head);
foreach ($services as $s) {
    $cells = array_map(number_format(...), [...array_values(estimate($s)), $s->reads / $s->writes]);
    printf("%-11s%15s%11s%10s%10s%10s%12s:1\n", $s->name, ...$cells);
}

In PHP: number_format rounds to a whole number and groups the digits with commas by default, and the spread operator passes the list of cells to printf.

Recorded with PHP 8.5.11 (CLI) on macOS 26 arm64. It runs in your browser with php-wasm 0.2.0 (PHP 8.5.2). To run it yourself: php main.php

Rust 1.99 · main.rs

const DAY: f64 = 86_400.0; // seconds

/// Daily active users, reads and writes per user a day, and the peak factor.
struct Service {
    name: &'static str,
    dau: f64,
    reads: f64,
    writes: f64,
    peak_factor: f64,
}

struct Estimate {
    daily: f64,
    average: f64,
    peak: f64,
    peak_reads: f64,
    peak_writes: f64,
}

impl Service {
    const fn new(name: &'static str, dau: f64, reads: f64, writes: f64, peak_factor: f64) -> Self {
        Self {
            name,
            dau,
            reads,
            writes,
            peak_factor,
        }
    }

    /// Average and peak requests a second, the peak split into reads and writes.
    fn estimate(&self) -> Estimate {
        let daily = self.dau * (self.reads + self.writes);
        let average = daily / DAY;
        Estimate {
            daily,
            average,
            peak: average * self.peak_factor,
            peak_reads: self.dau * self.reads / DAY * self.peak_factor,
            peak_writes: self.dau * self.writes / DAY * self.peak_factor,
        }
    }
}

const SERVICES: [Service; 3] = [
    Service::new("chat", 50_000_000.0, 80.0, 40.0, 3.0),
    Service::new("news feed", 20_000_000.0, 50.0, 0.5, 2.5),
    Service::new("payments", 30_000_000.0, 4.0, 2.0, 4.0),
];

/// A whole number with a comma between each group of three digits.
fn group(x: f64) -> String {
    let digits = format!("{x:.0}");
    let mut out = String::new();
    for (i, digit) in digits.chars().enumerate() {
        if i > 0 && (digits.len() - i) % 3 == 0 {
            out.push(',');
        }
        out.push(digit);
    }
    out
}

fn main() {
    println!(
        "{:<11}{:>15}{:>11}{:>10}{:>10}{:>10}{:>14}",
        "Service", "per day", "average/s", "peak/s", "reads/s", "writes/s", "reads:writes"
    );
    for s in &SERVICES {
        let e = s.estimate();
        let [daily, average, peak, reads, writes] =
            [e.daily, e.average, e.peak, e.peak_reads, e.peak_writes].map(group);
        let (name, ratio) = (s.name, group(s.reads / s.writes));
        println!(
            "{name:<11}{daily:>15}{average:>11}{peak:>10}{reads:>10}{writes:>10}{ratio:>12}:1"
        );
    }
}

In Rust: Rust's format strings have no digit grouping, so group walks the digits and pushes a comma before every third one from the right; estimate is a method of Service.

Recorded with rustc 1.99.0 (edition 2024) on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: rustc --edition 2024 -O main.rs && ./main

TypeScript 6.0 · main.ts

const DAY = 86_400; // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
interface Service {
  readonly name: string;
  readonly dau: number;
  readonly reads: number;
  readonly writes: number;
  readonly peakFactor: number;
}

const SERVICES: readonly Service[] = [
  { name: "chat", dau: 50_000_000, reads: 80, writes: 40, peakFactor: 3 },
  { name: "news feed", dau: 20_000_000, reads: 50, writes: 0.5, peakFactor: 2.5 },
  { name: "payments", dau: 30_000_000, reads: 4, writes: 2, peakFactor: 4 },
];

// Average and peak requests a second, the peak split into reads and writes.
function estimate({ dau, reads, writes, peakFactor }: Service) {
  const daily = dau * (reads + writes);
  const average = daily / DAY;
  return {
    daily,
    average,
    peak: average * peakFactor,
    peakReads: ((dau * reads) / DAY) * peakFactor,
    peakWrites: ((dau * writes) / DAY) * peakFactor,
  };
}

// A whole number with a comma between each group of three digits.
const group = (x: number): string =>
  Math.round(x)
    .toString()
    .replace(/\B(?=(\d{3})+(?!\d))/g, ",");

const head = ["per day", "average/s", "peak/s", "reads/s", "writes/s"];
const widths = [15, 11, 10, 10, 10];
const pad = (cells: string[]): string => cells.map((cell, i) => cell.padStart(widths[i])).join("");
console.log("Service".padEnd(11) + pad(head) + "reads:writes".padStart(14));
for (const s of SERVICES) {
  const e = estimate(s);
  const cells = [e.daily, e.average, e.peak, e.peakReads, e.peakWrites].map(group);
  console.log(s.name.padEnd(11) + pad(cells) + `${group(s.reads / s.writes)}:1`.padStart(14));
}

In TypeScript: An interface types a service and the return type of estimate is inferred; destructuring the parameter reads the four numbers of a service in one line.

Recorded with TypeScript 6.0.3 (strict), run by Node.js 24.21.0 on macOS 26 arm64. It runs in your browser with QuickJS (quickjs-emscripten 0.32.0) after Sucrase 3.35.1. To run it yourself: npx -p typescript@6.0.3 tsc --noEmit --strict main.ts && node main.ts

Go 1.27 · main.go

package main

import (
	"fmt"
	"strconv"
	"strings"
)

const day = 86_400 // seconds

// service holds the daily active users, the reads and writes per user a day, and the peak factor.
type service struct {
	name                           string
	dau, reads, writes, peakFactor float64
}

type estimate struct {
	daily, average, peak, peakReads, peakWrites float64
}

// estimateOf gives average and peak requests a second, the peak split into reads and writes.
func estimateOf(s service) estimate {
	daily := s.dau * (s.reads + s.writes)
	average := daily / day
	return estimate{
		daily:      daily,
		average:    average,
		peak:       average * s.peakFactor,
		peakReads:  s.dau * s.reads / day * s.peakFactor,
		peakWrites: s.dau * s.writes / day * s.peakFactor,
	}
}

// group writes a whole number with a comma between each group of three digits.
func group(x float64) string {
	digits := strconv.FormatFloat(x, 'f', 0, 64)
	var b strings.Builder
	for i, d := range digits {
		if i > 0 && (len(digits)-i)%3 == 0 {
			b.WriteByte(',')
		}
		b.WriteRune(d)
	}
	return b.String()
}

func main() {
	services := []service{
		{"chat", 50_000_000, 80, 40, 3},
		{"news feed", 20_000_000, 50, 0.5, 2.5},
		{"payments", 30_000_000, 4, 2, 4},
	}
	fmt.Printf("%-11s%15s%11s%10s%10s%10s%14s\n",
		"Service", "per day", "average/s", "peak/s", "reads/s", "writes/s", "reads:writes")
	for _, s := range services {
		e := estimateOf(s)
		fmt.Printf("%-11s%15s%11s%10s%10s%10s%12s:1\n", s.name, group(e.daily), group(e.average),
			group(e.peak), group(e.peakReads), group(e.peakWrites), group(s.reads/s.writes))
	}
}

In Go: fmt has no digit grouping, so group formats with strconv.FormatFloat and builds the text in a strings.Builder.

Recorded with Go 1.27.1 on macOS 26 arm64. It runs in your browser with the Go compiler in WebAssembly 1.27.1. To run it yourself: go run main.go

Swift 6.4 · main.swift

let day = 86_400.0  // seconds

/// Daily active users, reads and writes per user a day, and the peak factor.
struct Service {
  let name: String
  let dau: Double
  let reads: Double
  let writes: Double
  let peakFactor: Double
}

struct Estimate {
  let daily: Double
  let average: Double
  let peak: Double
  let peakReads: Double
  let peakWrites: Double
}

let services = [
  Service(name: "chat", dau: 50_000_000, reads: 80, writes: 40, peakFactor: 3),
  Service(name: "news feed", dau: 20_000_000, reads: 50, writes: 0.5, peakFactor: 2.5),
  Service(name: "payments", dau: 30_000_000, reads: 4, writes: 2, peakFactor: 4),
]

/// Average and peak requests a second, the peak split into reads and writes.
func estimate(_ s: Service) -> Estimate {
  let daily = s.dau * (s.reads + s.writes)
  let average = daily / day
  return Estimate(
    daily: daily, average: average, peak: average * s.peakFactor,
    peakReads: s.dau * s.reads / day * s.peakFactor,
    peakWrites: s.dau * s.writes / day * s.peakFactor)
}

func pad(_ text: String, _ width: Int, left: Bool = true) -> String {
  let spaces = String(repeating: " ", count: max(0, width - text.count))
  return left ? spaces + text : text + spaces
}

/// A whole number with a comma between each group of three digits.
func group(_ x: Double) -> String {
  let digits = Array(String(Int64(x.rounded())))
  var out = ""
  for (i, digit) in digits.enumerated() {
    if i > 0 && (digits.count - i) % 3 == 0 {
      out.append(",")
    }
    out.append(digit)
  }
  return out
}

let widths = [15, 11, 10, 10, 10]
func row(_ cells: [String]) -> String { zip(cells, widths).map { pad($0, $1) }.joined() }

let head = ["per day", "average/s", "peak/s", "reads/s", "writes/s"]
print(pad("Service", 11, left: false) + row(head) + pad("reads:writes", 14))
for s in services {
  let e = estimate(s)
  let cells = [e.daily, e.average, e.peak, e.peakReads, e.peakWrites].map(group)
  print(pad(s.name, 11, left: false) + row(cells) + pad(group(s.reads / s.writes) + ":1", 14))
}

In Swift: Without Foundation there is no number formatter, so group rounds to an Int64 and inserts the commas by hand; Int64 holds 6,000,000,000, which Int cannot in the WebAssembly build, where it has 32 bits.

Recorded with Apple Swift 6.4 on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: swiftc -O main.swift -o main && ./main

Ruby 4.0 · main.rb

# frozen_string_literal: true

DAY = 86_400.0 # seconds

# Daily active users, reads and writes per user a day, and the peak factor. Each estimate is a
# method: average and peak requests a second, the peak split into reads and writes.
Service = Data.define(:name, :dau, :reads, :writes, :peak_factor) do
  def daily = dau * (reads + writes)
  def average = daily / DAY
  def peak = average * peak_factor
  def peak_reads = dau * reads / DAY * peak_factor
  def peak_writes = dau * writes / DAY * peak_factor
end

SERVICES = [
  Service.new('chat', 50_000_000, 80, 40, 3),
  Service.new('news feed', 20_000_000, 50, 0.5, 2.5),
  Service.new('payments', 30_000_000, 4, 2, 4)
].freeze
WIDTHS = [15, 11, 10, 10, 10].freeze

# A whole number with a comma between each group of three digits.
def group(value) = value.round.to_s.gsub(/\B(?=(\d{3})+$)/, ',')

def row(cells) = cells.zip(WIDTHS).map { |cell, width| cell.rjust(width) }.join

head = ['per day', 'average/s', 'peak/s', 'reads/s', 'writes/s']
puts 'Service'.ljust(11) + row(head) + 'reads:writes'.rjust(14)
SERVICES.each do |s|
  cells = [s.daily, s.average, s.peak, s.peak_reads, s.peak_writes].map { |value| group(value) }
  puts s.name.ljust(11) + row(cells) + "#{group(s.reads.fdiv(s.writes))}:1".rjust(14)
end

In Ruby: Each estimate is a method of the Data class, and gsub with a lookahead inserts the commas; fdiv divides as floating point even when both counts are integers.

Recorded with CRuby 4.0.7 on macOS 26 arm64. It runs in your browser with ruby.wasm 2.10.1 (Ruby 4.0.0). To run it yourself: ruby main.rb

Kotlin 2.4 · Main.kt

import kotlin.math.roundToLong

const val DAY = 86_400.0 // seconds

// Daily active users, reads and writes per user a day, and the peak factor.
data class Service(
    val name: String,
    val dau: Double,
    val reads: Double,
    val writes: Double,
    val peakFactor: Double,
)

data class Estimate(
    val daily: Double,
    val average: Double,
    val peak: Double,
    val peakReads: Double,
    val peakWrites: Double,
)

// Average and peak requests a second, the peak split into reads and writes.
fun Service.estimate(): Estimate {
    val daily = dau * (reads + writes)
    val average = daily / DAY
    return Estimate(
        daily = daily,
        average = average,
        peak = average * peakFactor,
        peakReads = dau * reads / DAY * peakFactor,
        peakWrites = dau * writes / DAY * peakFactor,
    )
}

// A whole number with a comma between each group of three digits.
fun Double.group() =
    roundToLong()
        .toString()
        .reversed()
        .chunked(3)
        .joinToString(",")
        .reversed()

val widths = intArrayOf(15, 11, 10, 10, 10)

fun row(cells: List<String>) = cells.mapIndexed { i, c -> c.padStart(widths[i]) }.joinToString("")

fun main() {
    val services =
        listOf(
            Service("chat", 50_000_000.0, 80.0, 40.0, 3.0),
            Service("news feed", 20_000_000.0, 50.0, 0.5, 2.5),
            Service("payments", 30_000_000.0, 4.0, 2.0, 4.0),
        )
    val head = listOf("per day", "average/s", "peak/s", "reads/s", "writes/s")
    println("Service".padEnd(11) + row(head) + "reads:writes".padStart(14))
    for (s in services) {
        val e = s.estimate()
        val cells = listOf(e.daily, e.average, e.peak, e.peakReads, e.peakWrites).map { it.group() }
        println(s.name.padEnd(11) + row(cells) + "${(s.reads / s.writes).group()}:1".padStart(14))
    }
}

In Kotlin: group reverses the digits, cuts them into chunks of three and joins them with commas; estimate is an extension function on Service.

Recorded with Kotlin 2.4.20 on Java 25.0.4.1 on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: kotlinc Main.kt -include-runtime -d main.jar && java -jar main.jar

Dart 3.13 · main.dart

const day = 86400.0; // seconds

/// Daily active users, reads and writes per user a day, and the peak factor.
typedef Service = ({
  String name,
  double dau,
  double reads,
  double writes,
  double peakFactor,
});

typedef Estimate = ({
  double daily,
  double average,
  double peak,
  double peakReads,
  double peakWrites,
});

const List<Service> services = [
  (name: 'chat', dau: 50000000, reads: 80, writes: 40, peakFactor: 3),
  (name: 'news feed', dau: 20000000, reads: 50, writes: 0.5, peakFactor: 2.5),
  (name: 'payments', dau: 30000000, reads: 4, writes: 2, peakFactor: 4),
];

/// Average and peak requests a second, the peak split into reads and writes.
Estimate estimate(Service s) {
  final daily = s.dau * (s.reads + s.writes);
  final average = daily / day;
  return (
    daily: daily,
    average: average,
    peak: average * s.peakFactor,
    peakReads: s.dau * s.reads / day * s.peakFactor,
    peakWrites: s.dau * s.writes / day * s.peakFactor,
  );
}

/// A whole number with a comma between each group of three digits.
String group(double x) =>
    x.round().toString().replaceAll(RegExp(r'\B(?=(\d{3})+(?!\d))'), ',');

const widths = [15, 11, 10, 10, 10];
String row(List<String> cells) =>
    [for (var i = 0; i < cells.length; i++) cells[i].padLeft(widths[i])].join();

void main() {
  const head = ['per day', 'average/s', 'peak/s', 'reads/s', 'writes/s'];
  print('Service'.padRight(11) + row(head) + 'reads:writes'.padLeft(14));
  for (final s in services) {
    final e = estimate(s);
    final cells = [e.daily, e.average, e.peak, e.peakReads, e.peakWrites];
    final ratio = '${group(s.reads / s.writes)}:1';
    print(
      s.name.padRight(11) + row(cells.map(group).toList()) + ratio.padLeft(14),
    );
  }
}

In Dart: Services are records with named fields typed double, so the whole-number literals in the list become doubles, and replaceAll with a lookahead puts the commas in. Dart's / returns a double even for two ints; ~/ is its integer division.

Recorded with Dart 3.13.5 on macOS 26 arm64. It runs in your browser with a WebAssembly build by dart2wasm 3.13.5. To run it yourself: dart run main.dart

What every language printed

Service            per day  average/s    peak/s   reads/s  writes/s  reads:writes
chat         6,000,000,000     69,444   208,333   138,889    69,444           2:1
news feed    1,010,000,000     11,690    29,225    28,935       289         100:1
payments       180,000,000      2,083     8,333     5,556     2,778           2:1

The three answers differ by more than an order of magnitude, and they point to different designs. That is the purpose of the exercise: not the exact numbers, but which part of the system the numbers say will be under pressure.

Checkpoint

Check: From users to requests per second

  1. Question 1 of 2 An app has 8 million daily active users, and each makes 45 requests to the servers a day. What is the average rate, in requests a second?

    Type a number.

    A hint

    Requests a day, then divide by the seconds in a day.

    Show the answer: Question 1 of 2

    Answer: 4167 requests a second (anything from 4082 to 4252 counts)

    8,000,000 × 45 = 360 million requests a day, and 360,000,000 ÷ 86,400 ≈ 4,167 a second. That is the average over the whole day; the busiest hour brings more.

  2. Question 2 of 2 You are told the product has 60 million monthly active users and nothing about daily use. What do you do before estimating traffic?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Assume a share of them that comes on a typical day, say it out loud, and use that as the daily users

    Daily active users are at most the monthly ones. State the share you assume, for example that a third of the monthly users come on a given day, and carry on; the estimate can be redone if the assumption changes.

Reads and writes shape different parts of a system

Split every estimate into reads and writes, because they load different components. Reads can be answered from copies: a cache holds data close to the application to serve repeated reads faster (Cache-Aside pattern), and read replicas spread reads over several databases. Writes must reach the copy that owns the data, so heavy write traffic pushes towards partitioning, because a single server has finite storage, computing power and network bandwidth (Sharding pattern).

The ratio should come from how the product is used, not from habit:

  • A news feed is read far more than it is written: a post is written once and read by many followers, and people scroll more than they post. The program assumes 100 reads per write, so the design is about the read path.
  • Chat writes every message once and reads it once per recipient, so reads and writes stay within a small factor of each other, and both paths need attention.
  • Payments have few reads per write compared with a feed, and every write must be durable and recorded exactly once. Their peak write rate, not their read rate, sets the hardest requirement.

Here are the program’s peaks again, side by side, with the part of the design that each service’s read-to-write ratio: The number of reads a system serves for every write. A high ratio points a design at caches and read replicas; a low one at the write path and partitioning. puts under pressure:

Service Peak reads a second Peak writes a second Under pressure
Chat, 2 reads a write 138,889 69,444 Both paths, the write path most
News feed, 100 reads a write 28,935 289 The read path: caches and replicas
Payments, 2 reads a write 5,556 2,778 Durable, exactly-once writes

Key idea

Split the peak into reads and writes before you draw anything: reads can be served from copies, while every write must reach the copy that owns its data.

Checkpoint

Check: Reads and writes

  1. One question In the program's payments service, each user makes 4 reads and 2 writes a day. Which requirement is the hardest one in its design?

    Choose one answer.

    Show the answer: One question

    Answer: The peak write rate, because every payment must be durable and recorded exactly once

    The program prints 5,556 reads and 2,778 writes a second at the peak. Reads can come from caches and replicas; every write must reach the copy that owns the data, durably and exactly once, so the write path sets the hardest requirement.

A peak factor comes from the traffic’s shape

Traffic that people generate follows their days: low at night and higher while they are awake, with the busiest hours depending on the product. If you have real request counts, the peak factor: The rate in the busiest window divided by the average rate, for a stated window such as an hour or a second. Shorter windows and smaller services give larger factors. is simply the busiest window divided by the average window. Without them, assume a daily shape, say why, and derive the factor from it. The window matters as much as the shape: the busiest second is busier than the busiest minute, which is busier than the busiest hour.

Here is the shape the program below assumes, the share of a day’s requests in each hour, with an evening peak:

Bars for the 24 hours of the assumed day: low at night, about 5 % an hour by day, highest from 8 to 9 pm at 8.2 %.0 %3 %6 %9 %8.2 %0:006:0012:0018:00the busiest hour, 8 to 9 pm: 8.2 %an average hour: 4.2 %

The day the peak-factor program assumes, hour by hour

Text description of the diagram

The chart has one bar for each hour of the day, from midnight on the left to 11 pm on the right. Each bar is the share of the day's requests that arrives in that hour, on a scale from 0 % to 9 %. A dashed line marks an average hour, 100 % ÷ 24 = 4.2 %.

  • Midnight to 6 am, the night: 1.5 %, 1.0 %, 0.7 %, 0.6 %, 0.6 % and 0.9 %.
  • 6 am to noon, the morning rise: 1.8 %, 3.2 %, 4.5 %, 5.0 %, 5.2 % and 5.3 %.
  • Noon to 6 pm, the working day: 5.3 %, 5.2 %, 5.1 %, 5.0 %, 5.2 % and 5.4 %.
  • 6 pm to midnight, the evening: 6.4 %, 7.4 %, 8.2 %, 7.9 %, 5.6 % and 3.0 %.

The busiest hour, from 8 to 9 pm, is drawn darker. It carries 8.2 % of the day's requests, 1.97 times an average hour, which is the hourly peak factor of this assumed day.

The script below assumes that daily curve, then simulates the busiest hour with requests that arrive at random, independently of each other and at a steady average rate (a Poisson process: A model of arrivals that come at random and independently of each other, at a steady average rate. The number arriving in any one second then varies around that average., Gallager). Its random numbers come from Python’s random module, seeded with a fixed number, so any one Python version prints identical output on every run (Python documentation):

Peak factors over an hour, a minute and a second Python · peaks/peak_factor.py
# How big is the peak? It depends on the window you measure it over, and on how big the service is.
# An assumed day: the share of daily requests that arrives in each hour (a quiet night, an evening peak).
import random

HOURLY_SHARE = [  # percent of the day's requests, midnight to midnight
    1.5, 1.0, 0.7, 0.6, 0.6, 0.9, 1.8, 3.2, 4.5, 5.0, 5.2, 5.3,
    5.3, 5.2, 5.1, 5.0, 5.2, 5.4, 6.4, 7.4, 8.2, 7.9, 5.6, 3.0,
]
assert round(sum(HOURLY_SHARE), 6) == 100

busiest = max(HOURLY_SHARE)
print(f"Busiest hour: {busiest}% of the day, {busiest / (100 / 24):.2f} times an average hour")


def busiest_windows(daily_requests, seed):
    """Simulate the busiest hour with requests arriving at random (a Poisson process) and return the peak
    factors over that hour, its busiest minute and its busiest second, each relative to the day's average."""
    rng = random.Random(seed)
    day_average = daily_requests / 86_400
    rate = daily_requests * busiest / 100 / 3_600  # requests per second during the busiest hour
    per_second = [0] * 3_600
    t = rng.expovariate(rate)
    while t < 3_600:
        per_second[int(t)] += 1
        t += rng.expovariate(rate)
    per_minute = [sum(per_second[m * 60:(m + 1) * 60]) / 60 for m in range(60)]
    return day_average, rate / day_average, max(per_minute) / day_average, max(per_second) / day_average


print()
print(f"{'Requests a day':>15}{'average/s':>11}{'peak hour':>11}{'peak minute':>13}{'peak second':>13}")
for daily in [20_000_000, 2_000_000, 200_000]:
    average, hour, minute, second = busiest_windows(daily, seed=7)
    print(f"{daily:>15,}{average:>11,.1f}{hour:>10.2f}x{minute:>12.2f}x{second:>12.2f}x")

Output

Busiest hour: 8.2% of the day, 1.97 times an average hour

 Requests a day  average/s  peak hour  peak minute  peak second
     20,000,000      231.5      1.97x        2.00x        2.31x
      2,000,000       23.1      1.97x        2.05x        3.11x
        200,000        2.3      1.97x        2.23x        6.91x

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 peak_factor.py

Three results are worth carrying into every estimate:

  • The daily shape sets the hourly factor. With this curve, the busiest hour carries about twice the traffic of an average hour, whatever the size of the service.
  • Shorter windows have higher peaks. Within that hour, the busiest minute and the busiest second are higher again, because random arrivals bunch together.
  • Small services are spikier. For the service with 200,000 requests a day, the busiest second was about seven times the daily average; for the one with 20 million, about 2.3 times. Bunching that adds a few requests is a large share of a small average.

Real traffic can be much burstier than this model, because people do not always act independently: a push notification, a goal in a match or the opening minute of a sale makes thousands act at once, and retries after an outage add more. Google’s SRE book asks capacity plans to cover both kinds of demand: the steady growth that comes from people adopting a product, and the jumps that launches, marketing pushes and other business events cause (SRE book, introduction). For a known event, estimate its peak on its own from the people expected and the time over which they arrive.

SQLite Online (SQL Playground) Import an exported request log as a CSV file and count requests per hour or per minute with SQL, to measure a real peak factor. Line Graph Maker Plot hourly request counts to see the shape of a day before you choose a factor.

Checkpoint

Check: Where a peak factor comes from

  1. Question 1 of 2 In the program's output, the service with 200,000 requests a day averages 2.3 requests a second, and its busiest second was 6.91 times that. About how many requests arrived in that second?

    Type a number.

    A hint

    Multiply the average by the factor.

    Show the answer: Question 1 of 2

    Answer: 16 requests (anything from 15 to 17 counts)

    200,000 ÷ 86,400 ≈ 2.31 a second, and 2.31 × 6.91 ≈ 16 requests in one second. A handful of requests bunching together is a large share of a small average, which is why small services are spikier.

  2. Question 2 of 2 A teammate says "assume a peak factor of 3". What must they add for the number to mean something?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: The window it applies to, such as the busiest hour or the busiest second

    In the program, the same service had factors of 1.97 for the busiest hour and up to 6.91 for the busiest second. A factor without its window can be off by several times.

Check the share an estimate implies

When a public total exists for the whole market, compare your estimate with it. The question is not whether the numbers match, because they should not, but whether the share your estimate implies is believable for the product you are designing.

Checking a payments estimate against published volumes

The Reserve Bank of India’s Payment System Indicators give the monthly volume of each payment system, UPI included, in lakh. One edition’s UPI row reads 2,45,089.58 lakh for a 31-day month. Spread over that month, it is the average rate of the whole network, and the payments estimate above can be set against it:

A payments estimate as a share of the whole network Python · share/sanity_check.py
# Compare an estimate with a published total: is the share it implies believable?
LAKH = 10**5
DAY = 86_400

published = 2_45_089.58 * LAKH  # a month's volume as the payment tables print it, in lakh
network = published / (31 * DAY)  # spread over a 31-day month
ours = 30_000_000 * 2 / DAY  # the payments estimate above: 30 million users, 2 payments each a day

print(f"Whole network: {network:,.0f} payments a second on average")
print(f"Our estimate:  {ours:,.0f} payments a second on average, {ours / network:.1%} of the network")

Output

Whole network: 9,151 payments a second on average
Our estimate:  694 payments a second on average, 7.6% of the network

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 sanity_check.py

For a new product, handling about one payment in every thirteen made across the whole country is far too high a share, so the number of daily users is the assumption to revisit. Festival sales and big cricket matches are the kind of known events that deserve their own peak estimate, made from the expected audience and the minutes in which it arrives.

Checkpoint

Check: Checking an estimate against a total

  1. One question A published total works out at 9,151 payments a second across a whole network, and your estimate for a new app is 300 a second. What share of the network does the estimate imply, in per cent?

    Type a number.

    Show the answer: One question

    Answer: 3.3 % (anything from 3.1 to 3.5 counts)

    300 ÷ 9,151 ≈ 0.033, about 3.3 %. Whether that is believable depends on the product: for a new app, one payment in thirty across a whole country is a bold assumption about its daily users.

Four slips that skew a traffic estimate

Each slip below moves the result by a factor you can name, so check for all four before you size anything:

Slip What it does to the estimate
Monthly users counted as daily users That inflates every rate by the ratio between them.
Taps counted instead of requests One action can be several requests, and background sync adds more.
A peak factor without a window “3 times” means little until you say whether it is the busiest hour or the busiest second.
The average used for capacity The average is the lowest load your busiest hour will bring, not a target to size for.

Checkpoint

Check: Slips in a traffic estimate

  1. One question An estimate reads: "40 million users × 20 requests ÷ 86,400 ≈ 9,300 a second", and the 40 million comes from a slide titled "monthly active users". What do you check?

    Choose one answer.

    Show the answer: One question

    Answer: That 40 million is used as monthly, not daily, users; with a third of them active on a day the rate is about 3,100

    Daily users can never be more than monthly ones. With 40 million monthly users and an assumed third of them active on a typical day, 13.3 million × 20 ÷ 86,400 ≈ 3,100 a second.

Practise: users to peak requests

Write the two functions of a traffic estimate: average and peak requests a second from users and their requests, split into reads and writes, and a peak factor measured from counts per window. Its five sample tests run here:

Exercise · Easy · Python

Turn users into average and peak requests per second

Write the two functions of a traffic estimate in estimate.py.

estimate(dau, reads_per_user, writes_per_user, peak_factor) returns a dictionary with four rates, all in requests per second:

  • "average": the day's requests, dau × (reads_per_user + writes_per_user), spread evenly over 86,400 seconds;
  • "peak": the average multiplied by peak_factor;
  • "peak_reads" and "peak_writes": the peak split in the same proportion as reads and writes, so that the two add up to the peak.

For example, 1 million users who each make 8 reads and 2 writes a day, with a peak factor of 3, give an average of about 115.7 requests a second and a peak of about 347.2, of which 277.8 are reads.

peak_factor(counts) measures a peak factor from data: given a list of request counts, one per window (per hour, say), it returns the busiest window's count divided by the average count. An empty list raises ValueError.

Starter code · estimate.py

DAY = 86_400


def estimate(dau, reads_per_user, writes_per_user, peak_factor):
    """Return {"average", "peak", "peak_reads", "peak_writes"} in requests per second."""
    # Replace this line with your code.
    return {}


def peak_factor(counts):
    """Return the busiest window's count divided by the average count; raise ValueError for an empty list."""
    # Replace this line with your code.
    return 0
The sample tests · test_estimate.py
import math

from estimate import estimate, peak_factor


def raises_value_error(function, *args):
    """True when function(*args) raises ValueError."""
    try:
        function(*args)
    except ValueError:
        return True
    return False


def test_average():
    """spreads the day's requests over 86,400 seconds"""
    result = estimate(1_000_000, 8, 2, 3)
    assert math.isclose(result["average"], 115.740741, rel_tol=1e-6)


def test_peak():
    """multiplies the average by the peak factor"""
    result = estimate(1_000_000, 8, 2, 3)
    assert math.isclose(result["peak"], 347.222222, rel_tol=1e-6)
    assert math.isclose(estimate(86_400, 1, 0.5, 2)["peak"], 3, rel_tol=1e-9)


def test_split():
    """splits the peak into reads and writes that add up to it"""
    result = estimate(1_000_000, 8, 2, 3)
    assert math.isclose(result["peak_reads"], 277.777778, rel_tol=1e-6)
    assert math.isclose(result["peak_writes"], 69.444444, rel_tol=1e-6)
    assert math.isclose(result["peak_reads"] + result["peak_writes"], result["peak"], rel_tol=1e-9)


def test_peak_factor():
    """divides the busiest window by the average window"""
    assert peak_factor([10, 10, 10, 10]) == 1
    assert peak_factor([5, 15]) == 1.5
    assert peak_factor([0, 0, 6]) == 3


def test_empty_counts():
    """refuses an empty list of counts"""
    assert raises_value_error(peak_factor, [])
A hint

Compute the daily total once, dau * (reads_per_user + writes_per_user), and divide by DAY for the average. For the split, the reads' share of the traffic is reads_per_user / (reads_per_user + writes_per_user). For the peak factor, max(counts) divided by sum(counts) / len(counts) is the whole calculation.

The sample tests run on this device, in your browser (Pyodide): nothing is sent to mysmartcopilot.com. The first run downloads Python (about 13.5 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.

Finish with practice on fresh numbers. A wrong answer brings an easier question on the same idea, and a right one a harder question:

Practice that adapts to you

Practise this lesson

14 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 14 Which of these should you state as assumptions when you estimate traffic?

    Choose every answer that is right.

    Show the answer: Question 1 of 14

    Answer:

    • The peak factor and the window it describes
    • The reads and writes each user makes a day
    • The number of daily active users

    Users, actions per user and the peak factor decide the numbers, and each is a judgement someone may question, so say them out loud. The colour scheme changes nothing in the estimate.

  2. Question 2 of 14 A service has 10 million daily active users, and each makes 30 requests a day. What is the average number of requests per second?

    Type a number.

    Show the answer: Question 2 of 14

    Answer: 3472.2 requests per second (anything from 3125.2 to 3819.2 counts)

    10,000,000 × 30 = 300 million requests a day, and 300,000,000 / 86,400 ≈ 3,472 a second. Any answer within 10% shows the method; the exact value does not matter more than that.

  3. Question 3 of 14 That service's busiest hour brings 3 times the average rate. What peak rate should the design carry, in requests per second?

    Type a number.

    Show the answer: Question 3 of 14

    Answer: 10417 requests per second (anything from 9375 to 11459 counts)

    3,472 × 3 ≈ 10,400 requests a second. Say which window the factor describes: the busiest second inside that hour is higher still.

  4. Question 4 of 14 An app has 2 million daily active users. Each opens it 6 times a day, each open makes 8 calls to the servers, and background sync adds 24 calls per user a day. What is the average rate, in requests a second?

    Type a number.

    A hint

    Count requests to the servers per user first, opens and sync together.

    Show the answer: Question 4 of 14

    Answer: 1667 requests a second (anything from 1632 to 1702 counts)

    Each user makes 6 × 8 + 24 = 72 requests a day, so 2,000,000 × 72 = 144 million a day, and 144,000,000 ÷ 86,400 ≈ 1,667 a second. Counting opens instead of requests would have given 139 a second, twelve times too few.

  5. Question 5 of 14 A service makes 100 reads for every write. Which parts of a design does its traffic mostly shape?

    Choose one answer.

    Show the answer: Question 5 of 14

    Answer: The read path, so caches and read replicas

    Almost all of the load is reads, so serving reads cheaply, from a cache or from replicas, removes almost all of the load. A write-heavy service is shaped by its write path instead: partitioning and faster writes.

  6. Question 6 of 14 In a group chat, each message is written once and read once by each recipient. Groups have 5 recipients on average. How many reads are there per write?

    Type a number.

    Show the answer: Question 6 of 14

    Answer: 5 reads per write

    Each write is read once per recipient, so 5 reads per write: within a small factor of each other, which is why both paths of a chat system need attention.

  7. Question 7 of 14 A service peaks at 70,000 writes a second, each of which must be durable, and about as many reads. What does that write rate call for first?

    Choose one answer.

    Show the answer: Question 7 of 14

    Answer: Partitioning the data, so that the writes spread over several machines that each own a part

    Reads can be spread over copies, but every write must reach the copy that owns its data. At tens of thousands of durable writes a second the write path, and partitioning it, shapes the design.

  8. Question 8 of 14 What is a peak factor?

    Choose one answer.

    Show the answer: Question 8 of 14

    Answer: The rate in the busiest window divided by the average rate

    With real request counts, the peak factor is the busiest window divided by the average window. In the program, the busiest hour carries 8.2 % of the day, 1.97 times an average hour's 4.17 %.

  9. Question 9 of 14 In this lesson's simulation, why is the busiest second of a small service so much higher than its average, compared with a big service?

    Choose one answer.

    Show the answer: Question 9 of 14

    Answer: With few requests a second, random arrivals bunch up more relative to the average

    Both services had the same daily curve. At an average of about 2 requests a second, a second that happens to bring 16 is seven times the average; at hundreds a second, random bunching of the same kind adds only a small share. The simulation's output shows the effect: the smaller the service, the larger its per-second peak factor.

  10. Question 10 of 14 An internal tool is used only during a 9-hour working day, in one time zone, at a steady rate. What is its peak factor for the working hours, relative to the daily average?

    Choose one answer.

    Show the answer: Question 10 of 14

    Answer: About 2.7, because the whole day's traffic arrives in 9 of its 24 hours

    Derive the factor from the shape: if all traffic arrives in 9 of 24 hours, the rate during them is 24 ÷ 9 ≈ 2.7 times the daily average, before any bunching inside a minute or a second.

  11. Question 11 of 14 Why compare a traffic estimate with a published total for the whole market?

    Choose one answer.

    Show the answer: Question 11 of 14

    Answer: To see whether the share of the market it implies is believable for the product

    The question is not whether the numbers match, but whether the share your estimate implies is plausible. If it is not, revisit the assumption that drives it, usually the daily users.

  12. Question 12 of 14 Your estimate for a new payments app implies 7.6 % of all payments made across the country. Which assumption do you revisit first?

    Choose one answer.

    Show the answer: Question 12 of 14

    Answer: The number of daily users, which drives every rate in the estimate

    One payment in every thirteen made across a whole country is far too much for a new product, so the daily users, the first link of the chain, are the assumption to revisit.

  13. Question 13 of 14 A designer counts "12 taps per user a day" and the estimate uses 12 requests per user. What is the risk?

    Choose one answer.

    Show the answer: Question 13 of 14

    Answer: One tap can be several requests, and background sync adds more, so the estimate can be several times too low

    Count requests to your servers, not taps on a screen: one screen may load with several API calls, and an app may sync in the background.

  14. Question 14 of 14 A plan sizes a ticket-booking service for "the peak, three times the average", measured as the busiest hour of a normal week. What does it miss?

    Choose one answer.

    Show the answer: Question 14 of 14

    Answer: Known events such as a sale opening, whose peak must be estimated on its own from the people expected and the minutes they arrive in

    A peak factor is only as good as the window and the period it came from. For a known event, estimate its peak separately, as the lesson's SRE reference asks capacity plans to.

Interview questions

Warm-up (fresher): how do you turn daily active users into requests per second, and why is the average rate not the number to size a system for?

Multiply the daily active users by the requests each one makes in a day, counting calls to your servers rather than taps on a screen, and divide by the 86,400 seconds of a day: 10 million users making 30 requests each give 300 million requests a day, about 3,472 a second on average. That average covers the whole day, night included, so the busiest hour brings more: about twice as much with the evening-peaked day of this lesson, and the busiest second within that hour more again. Size for the peak of a stated window, split into reads and writes because they load different parts of the system, and estimate known events such as a sale or a match on their own, from the people expected and the minutes in which they arrive.

Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.

  1. Fresher to mid

    A food-delivery app expects 5 million daily active users. Estimate the average and peak rates of menu browsing and of order placement, state every assumption, and say which number shapes the database design.

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Mid to senior

    Your app's busiest hour brings 2,000 requests a second. Marketing plans a push notification to 4 million users at 8 pm. Estimate the peak it causes and say what you would change before it is sent.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • Average requests per second = DAU × requests per user per day ÷ 86,400; the peak is the average times a peak factor for a stated window.
  • Split reads from writes: read-heavy traffic shapes caches and replicas, write-heavy traffic shapes partitioning and the write path.
  • Derive the peak factor from the traffic’s shape: about 2 for the busiest hour of the daily curve assumed here, more for shorter windows and for small services, and a separate estimate for known events.
  • Sanity-check an estimate by the share of a published total it implies.
  • Before you size anything, check that the users are daily, the requests are requests and the factor has a window.

Terms in this lesson

daily active users (DAU)
The number of different people who use a product on a typical day. It can never exceed the monthly active users, and it is the usual starting point of a traffic estimate.
peak factor
The rate in the busiest window divided by the average rate, for a stated window such as an hour or a second. Shorter windows and smaller services give larger factors.
Poisson process
A model of arrivals that come at random and independently of each other, at a steady average rate. The number arriving in any one second then varies around that average.
read-to-write ratio
The number of reads a system serves for every write. A high ratio points a design at caches and read replicas; a low one at the write path and partitioning.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.