Performance, Scale and Capacity

Quantifying workload before optimizing: average versus peak throughput, consumer capacity, end-to-end latency and percentiles, storage growth, and availability and recovery objectives.

  • Intermediate to advanced
  • About 23 minutes
  • Includes an exercise and a knowledge check

The concept Quantify the workload first

A customer says: The system works, but it cannot keep up with our volume. Quantify the workload before recommending optimization or a new architecture. Ask how many transactions a day, the average and peak rates, whether traffic is even or spiky, the processing window, acceptable end-to-end latency, how much history must be kept, and how fast the system must recover after an outage.

A workload and performance dashboard with placeholders instead of invented numbers. A workload curve over a day shows a quiet night and a sharp morning peak that rises above the processing capacity line, while the average rate sits far below. Latency percentiles p50, p95 and p99 rise from the median to the slow tail. An end-to-end timeline for one payment shows provider delivery, API, queue wait, consumer, database and downstream segments, with the longest segment waiting for the reconciliation schedule. Storage grows in layers: raw records per day, times days per year, times retention years, plus indexes, replicas and backups.
Measure the peak, not the average. The real values come from the customer's own measurements.

Worked example Average versus peak

StepCalculationResult
Daily volumeGiven by Apex (example)120,000 payment events a day
Average rate120,000 ÷ 86,400 secondsabout 1.39 events a second
Observed peakGiven by Apex (example)20 events a second
One consumer's capacityMeasured in a representative test (example)10 events a second
Gap at the peak20 needed, 10 availableOne consumer is not enough at the peak

Latency Percentiles beat averages

End-to-end latency for a payment includes provider delivery, API processing, queue waiting, consumer work, database work, downstream delay and the reconciliation schedule. Measure the whole journey as well as each part. Use percentiles:

PercentileMeaning
p50The median: half of requests are faster
p9595% of requests finish within this time
p9999% finish within this time: the slow tail

A low average can hide a serious tail. If 1 payment in 100 takes 30 seconds, the average barely moves, but every morning hundreds of payments are late.

Calculate percentiles from the raw timings, not from averages of averages. Here are 1,000 end-to-end timings from one fictional morning. The query sorts them and reads the value at each rank (the nearest-rank method: p95 is the value at position 950 of 1,000):

sqlAverage versus percentiles on 1,000 payment timings

WITH ranked AS (
    SELECT
        latency_ms,
        ROW_NUMBER() OVER (ORDER BY latency_ms) AS position,
        COUNT(*) OVER () AS n
    FROM payment_latency
)
SELECT
    MAX(n) AS payments,
    ROUND(AVG(latency_ms)) AS avg_ms,
    MAX(CASE WHEN position = (n * 50 + 99) / 100 THEN latency_ms END) AS p50_ms,
    MAX(CASE WHEN position = (n * 95 + 99) / 100 THEN latency_ms END) AS p95_ms,
    MAX(CASE WHEN position = (n * 99 + 99) / 100 THEN latency_ms END) AS p99_ms,
    SUM(latency_ms > 10000) AS over_10_s
FROM ranked;

Result on the sample

payments  avg_ms  p50_ms  p95_ms  p99_ms  over_10_s
--------  ------  ------  ------  ------  ---------
    1000  1924.0    1525    2339   26962         15

Real output from SQLite 3.54 on 1,000 fictional timings generated by tools/fde/apex_latency.sql, November 22, 2026.

Read it the way a customer will feel it. The average is under 2 seconds and p95 is 2.3 seconds, so a dashboard of averages says all is well. But p99 is 27 seconds, and 15 payments in 1,000 took over 10 seconds. If the sample's rate held at Apex, the morning window would hold about 720 slow payments: 15 ÷ 1,000 × 48,000 = 720, where 48,000 is the events between 8:00 and 10:00 a.m. (40% of 120,000, from the exercise below). That is an estimate from a fictional sample, not a measurement; measure the real tail before quoting it. That tail is where the investigation starts: which step were those 15 payments waiting on?

Storage Estimate storage growth

StepCalculationResult
Daily raw data120,000 events × 2 KBabout 240 MB a day
Yearly raw data240 MB × 365about 87.6 GB a year
Units usedDecimal: 1 KB = 1,000 bytes, 1 MB = 1,000 KB, 1 GB = 1,000 MB

The 2 KB is the average event payload as received, measured from a sample (an assumption to confirm with Apex). It does not include database row overhead, indexes or processing metadata such as event IDs and timestamps added on the way. So this is raw data only. Real storage grows with indexes, metadata, replicas, retention periods, compression and backups, so treat it as a starting estimate.

Commitments Availability and recovery

TermMeaning
AvailabilityHow much of the time the service must be usable
RTO (recovery time objective)How quickly service must be restored after an outage
RPO (recovery point objective)How much data, measured in time, may be lost
Backup and restoreHow data is copied and how long restoring takes
FallbackThe manual procedure when the system is down

Practice Size the morning peak

Practical exercise

Can the current setup cope?

Apex tells you 40% of the 120,000 daily events arrive between 8:00 and 10:00 a.m., and the busiest minute inside that window reaches the observed peak of 20 events a second from the table above. Two consumers each handle 10 events a second, sharing one database that handles 15 writes a second.

  1. Work out the average rate in that two-hour window.
  2. Find the limiting component.
  3. Say what you would measure next.
Show the worked answer
  • Events in the window: 120,000 × 40% = 48,000. Over 7,200 seconds that is about 6.7 events a second. That is the average across the two hours, not the peak.
  • The peak is a separate number: 20 events a second in the busiest minute, observed by Apex. Averages over a long window always hide the busiest minute, so ask for both.
  • Consumers: 2 × 10 = 20 a second; the database: 15 a second. The 6.7 average fits easily, but at the 20-a-second peak the database falls behind by about 5 writes a second, so the database is the limit. How long the peak lasts decides how big the backlog grows.
  • Measure next: the real peak minute, database write latency and lock waits at the peak, and queue depth from 8:00 to 10:00.

3 questions

Check your understanding

1. A system averages 2 requests a second but peaks at 30. Which matters for capacity planning?
2. What does p99 latency tell you?
3. What does RPO describe?
Answer every question to submit.

What you can do now

  • Calculate average and peak throughput.
  • Find the limiting component in a processing chain.
  • Use percentiles to describe latency.
  • Estimate storage growth and ask for availability and recovery objectives.