← Math
Math

Distributions and long tails

Do long jobs need their own pool?

Compare how often long jobs occur with how much work they consume.

Outcome

Summarize grouped observations, tell a tail’s share of the count from its share of the total, and see which cohort the tail comes from.

Terminology (6)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Distribution
How often each value occurs. A histogram groups values and counts each group.
Long tail
A few values far larger than the typical one. They can dominate totals while barely affecting counts.
Grouped data
Values recorded as (value, count) pairs instead of one entry per observation.
Share of count
What fraction of observations fall in a range.
Share of total
What fraction of the summed quantity, such as compute minutes, those observations carry.
Cohort
A subgroup such as a team, region or client version whose contribution you want to see separately.

Why this matters

Job durations, request sizes, customer spend and file sizes are usually long-tailed: most values are small and a few are huge. Capacity is consumed by totals, so the few can decide the bill and the queue while barely registering in counts or medians. Systems also store these values as histograms, so the arithmetic has to work on grouped data.

This lesson assumes means, medians and percentiles from the previous lesson.

What a distribution preserves

A distribution describes how observations are spread across values. A histogram groups them and records how many fall in each group. The examples here group exact durations; ordinary interval buckets would leave each job’s precise duration unknown. A long tail contains relatively few large values that can contribute much of the total.

The means, medians and percentiles from the previous lesson summarize different parts of that distribution. To discuss capacity, also name the resource unit: under this lesson’s one-identical-worker-per-job assumption, duration times job count gives worker-minutes. A share of jobs uses a count denominator; a share of work uses a resource denominator. Neither share alone determines how many workers are needed.

01Read a histogram

Read a histogram

Only 5% of yesterday’s batch jobs ran 10 minutes or longer, so a separate pool for them sounds wasteful. Those jobs used 64% of all compute minutes, and nearly all of that came from one team.

The pool investigation needs worker occupancy, not just a count of requests. Assume each job holds one identical worker for its whole duration; job minutes then add as worker-minutes. These groups record exact durations, rather than intervals with unknown values inside. Yesterday’s batch jobs, grouped by duration: 950 took 2 minutes, 40 took 10 and 10 took 300. That is 1,000 jobs and 5,300 minutes. Predict the three lines this program prints.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// [minutes, jobs] for one day of batch jobs
const groups: [number, number][] = [
  [2, 950],
  [10, 40],
  [300, 10]
];

const jobs = groups.reduce((sum, [, count]) => sum + count, 0);
const minutes = groups.reduce((sum, [value, count]) => sum + value * count, 0);
const longMinutes = groups.reduce(
  (sum, [value, count]) => (value >= 10 ? sum + value * count : sum),
  0
);

console.log((minutes / jobs).toFixed(2)); // mean
const longJobs = groups.reduce(
  (sum, [value, count]) => (value >= 10 ? sum + count : sum),
  0
);

console.log((longJobs / jobs).toFixed(4)); // share of jobs taking 10 minutes or more
console.log((longMinutes / minutes).toFixed(4)); // share of minutes they use
What is the median job duration?

Grouped data fits in an array of [value, count] tuples. Sort with a comparator on the value, (a, b) => a[0] - b[0], before walking it for a median.

02Count share and time share

Count share and time share

The 50 jobs of 10 minutes or more are 5% of the jobs and use 3,400 of the 5,300 minutes, 64.2%. The work concentrated in the tail makes a separate pool worth investigating. The share alone does not determine a worker count: arrival timing, concurrency and resource requirements still matter. An alert on the share of slow jobs watches the first number. If jobs use different worker sizes, weight by their resource use as well.

Yesterday’s jobs
Minutes eachJobsShare of jobsShare of minutes
295095.0%35.8%
10404.0%7.5%
300101.0%56.6%

03Same mean, different shape

Same mean, different shape

Another day had 1,000 jobs that each took 5.3 minutes. How does it compare?

A mean describes the total, not the shape. Report the median and a tail measure beside it, or show the histogram.

04Split by cohort

Split by cohort

Two teams sent the jobs. Search sent 900 jobs of 2 minutes and the 10 of 300; Ads sent 50 of 2 minutes and the 40 of 10. The long jobs used 3,400 minutes in total: 3,000 from Search (88.2%) and 400 from Ads (11.8%).

Ads spends 80% of its own minutes on long jobs; Search 62.5%. Which team contributes most of the observed long-job work?

05Empty windows

Empty windows

06Size the long-job pool

Size the long-job pool

The platform team needs to know whether the long-job work is concentrated enough to investigate a separate pool. Repair its grouped summary, separate job counts from worker-minutes, then attribute the pooled tail to teams. A correct per-team tail percentage can still answer the wrong capacity question.

In the frontend Count share and time share in Next.js and Svelte Optional

The buckets partition the window’s jobs; each minutes field is its bucket’s total worker-minutes. A jobs dashboard puts the long bucket’s share of jobs and share of time in one sentence, so nobody reads 5% as the cost. A zero-minute window still has a job share; it has no time share. A missing bucket is a separate unavailable-data state.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Bucket = { label: string; jobs: number; minutes: number };

// The long bucket's share of jobs and its share of compute time, side by side.
export function LongJobs({ buckets, long }: { buckets: Bucket[]; long: string }) {
  const jobs = buckets.reduce((sum, b) => sum + b.jobs, 0);
  const minutes = buckets.reduce((sum, b) => sum + b.minutes, 0);
  const bucket = buckets.find((b) => b.label === long);

  if (jobs === 0) return <p>No jobs in this window.</p>;
  if (!bucket) return <p>Long-job bucket unavailable.</p>;

  return (
    <p>
      Jobs in {long}: {((100 * bucket.jobs) / jobs).toFixed(1)}% of jobs,{" "}
      {minutes === 0
        ? "time share unavailable"
        : `${((100 * bucket.minutes) / minutes).toFixed(1)}% of compute time`}
    </p>
  );
}

Check this idea later
An alert fires when mean request latency exceeds 200 ms. Will it catch 1% of requests slowing from 1 s to 10 s?
1% of customers generate 40% of revenue. What share of customers generate the other 60%?
Sources

Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The batch jobs are a worked model.

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.