Typorithm · medium

15. Bounded concurrency and latency evidence

qatestingplaywrightindependent-practice
Saved on this device
Full lesson · 4 learning steps Open any exercise for focused practice
1

Step 1 of 4 · intro card

15. Bounded concurrency and latency evidence

0%

Concept and contract

Measure the chosen workload without pretending a small lab proves production capacity.

A latency observation needs a defined workload, environment, duration and outcome policy. A small local test can teach measurement and detect a regression, but it cannot establish the capacity of a production service with different data, infrastructure and dependencies.

Keep concurrency bounded before requests begin. Promise.all over thousands of already-started operations is not a rate limit. Responsible testing starts with an authorized target and a modest plan; this lesson uses only local functions and the loopback lab.

Mechanism and worked example

The worked example uses illustrative durations, not measured production data.

The worked example uses illustrative durations, not measured production data. Its nearest-rank p95 is 500 while the average is 68. This shows why a mean can conceal a slow tail. State the percentile definition and sample size before comparing reports.

Real measurements also need error counts and timeouts. A fast failed request is not a successful user experience. Short samples provide limited confidence, so avoid turning one observed percentile into a universal service guarantee.

Complete worked example

typescript

import { test, expect } from "../support/test.js";
import { percentile } from "../support/domain.mjs";
test("illustrative tail differs from mean", () => {
  const samples = [...Array(18).fill(20), 500, 500];
  const mean = samples.reduce((sum, value) => sum + value, 0) / samples.length;
  expect(mean).toBe(68);
  expect(percentile(samples, 0.95)).toBe(500);
});
Reasoning
The sample values are explicitly illustrative and use a stated nearest-rank percentile.

Counterexamples and common mistakes

The weak plan launches an unbounded request array against a real provider and calls a low average sufficient.

The weak plan launches an unbounded request array against a real provider and calls a low average sufficient. It lacks authorization, load control and a meaningful tail or failure observation. Increasing traffic is not a substitute for a well-defined experiment.

Do not tune a performance threshold until every run passes. Investigate the workload and cause, then choose a budget connected to the product risk. Preserve comparable baselines and avoid measuring a warm cache against an unrelated cold workload.

Counterexample: what this check misses

typescript

// Weak plan: launch every request immediately and report only a low average.
// This is neither a concurrency limit nor a production capacity proof.
Reasoning
An unbounded plan and a mean alone cannot support a safe capacity claim.

Independent practice: small task

Run six small task factories through a two-worker helper.

Run six small task factories through a two-worker helper. Record the maximum active count and returned values, then verify the input order is preserved. Begin with two tasks before increasing to six.

Use only local work and do not claim a throughput benchmark. Optional extension: measure a small loopback API workload with explicit error and timeout reporting. A production load run requires its own authorization and plan.

Step 1: Track two local task factories first. Step 2: Run six with a two-worker cap and check ordering.

Practice starter: solve before reading the solution

typescript

import { test, expect } from "../support/test.js";
import { runBounded } from "../support/domain.mjs";
test("two-worker local task cap", async () => {
  // TODO: track active tasks and verify the maximum and returned order.
});
Reasoning
Measure the helper’s active count before discussing any network workload.
  • Hint 1: Do not send a load exercise to external feeds.
  • Hint 2: Label illustrative data and measured data separately.

Solution, tests and trade-offs

The solution uses a provided bounded helper and observes at most two active tasks.

The solution uses a provided bounded helper and observes at most two active tasks. The assertion checks the control mechanism, not server capacity. The separate percentile example is labeled illustrative so readers cannot mistake its numbers for ApplyDjinn measurements.

The verifier executes both cases and checks that an unbounded mutant exceeds the cap. Keep that failure separate from the successful run. Resource limits and honest scope are part of the evidence, not optional reporting details.

Practice solution and acceptance checks

typescript

import { test, expect } from "../support/test.js";
import { runBounded } from "../support/domain.mjs";
test("two-worker local task cap", async () => {
  let active = 0, maximum = 0;
  const tasks = Array.from({length:6}, (_, value) => async () => {
    active++; maximum = Math.max(maximum, active);
    await Promise.resolve(); active--; return value;
  });
  expect(await runBounded(tasks, 2)).toEqual([0,1,2,3,4,5]);
  expect(maximum).toBeLessThanOrEqual(2);
});
Reasoning
The observed cap and order establish a local control property, not production throughput.

Interview reasoning and next step

In interviews, explain workload, concurrency, error rate and a tail metric before quoting a latency number.

In interviews, explain workload, concurrency, error rate and a tail metric before quoting a latency number. Show why an average alone can mislead. Distinguish a local control test from an authorized production performance study.

The final project now combines useful assertions, real local API behavior, browser interaction, account boundaries and a concise evidence report.

Optional stretch — after the core task works: Plan a small authorized loopback workload with error reporting.

Computer practice: download the companion lab at https://applydjinn.com/typorithm/qa-lab-20261105.zip. Read its README, install the pinned tools and run the accepted examples before attempting a starter. The mobile reader preserves your reading and self-check progress; the local lab runs browser tests separately.

Measure the chosen workload without pretending a small lab proves production capacity.