The scenario Traffic is not constant
At month-end, finance receives a large settlement batch and the queue grows. The customer asks: Can the platform handle it? The honest answer needs numbers. Apex now gives its own planning assumptions, which replace the illustrative estimate used in Module 06:
| Assumption | Value |
|---|---|
| Payment events a day | 400,000 |
| Settlement records on a busy day | 100,000 |
| Primary business processing window | 10 hours |
| Peak arrival rate | Up to 5 times the average |
400,000 ÷ (10 × 3,600 seconds) ≈ 11.1 events a second; × 5 ≈ 55.6 at peak. That is the payment workload only, and a starting point, not a guarantee. You still need payload sizes, database writes per event, downstream calls, retries, consumer processing time, batch sizes, concurrency, how long the peak lasts and the latency objectives.
The 400,000 payment events and the 100,000 settlement records are two separate workloads with different shapes, and at month-end they hit the same database at the same time. Calculate each, then add them (example per-item figures, to measure in a load test):
| Payment events | Settlement records | |
|---|---|---|
| Shape | A stream through the day, peaking at about 55.6 a second | One file of 100,000 records, due within 15 minutes |
| Rate | 55.6 events a second at peak | 100,000 ÷ 900 s ≈ 111 records a second |
| Database writes | 3 per event: 55.6 × 3 ≈ 167 a second | 4 per record: 111 × 4 ≈ 444 a second |
| Connections busy | 20 ms of database time per event: 55.6 × 0.02 ≈ 1.1 on average | 20 ms per record: 111 × 0.02 ≈ 2.2 on average |
Together at month-end, that is about 611 writes a second and about 3.3 busy connections on average, more in bursts. Busy connections are not the limit that bites; pools are. Each task opens its whole pool. Four API tasks with 20 connections and six workers with 10 open 140 connections before any work arrives. Check that against the database's own limit (for example, 200 on the chosen instance, to confirm), leave room for administration and migrations, and size pools from the busy-connection numbers plus headroom, not from defaults.
The hidden problem Scaling can expose data races
Two workers receive the same settlement event, both read an unmatched payment, both match it. More workers made the system faster and less correct. Business invariants must be enforced by database constraints, transactions and idempotent processing (Module 07, Lesson 05), never by the hope that only one worker runs.
Practice Write a capacity plan
Practical exercise
Exercise 05: the Apex capacity plan
Estimate the workload, then test normal, peak and a burst above peak. Which resource fails first?
- Average and peak ingestion rates, and settlement processing workload.
- Database operations, worker concurrency and connection demand.
- Queue retention, retry requirements and scaling thresholds.
Show sample numbers
- Settlement: 100,000 records; at 4 database writes each that is 400,000 writes. To finish in 15 minutes: 400,000 ÷ 900 s ≈ 444 writes a second.
- Scaling rule: add a worker when the oldest message is older than 2 minutes; at most 6 workers × 10 connections = 60, within the database limit.
2 questions
Check your understanding
What you can do now
- Turn assumptions into throughput estimates.
- Choose the right scaling approach.
- Protect correctness while scaling.
← Lesson 04: Containers, Runtime Configuration and Application Health