Skip to main content
Latency Waterfall
p50 · p90 · p99 · p99.9 per hop

Task Scheduler: Latency Waterfall

Break down end-to-end latency by hop and percentile. Understand where the p99 tail comes from — DNS, network, cache lookup, database query, serialization. Real requests have wildly different paths depending on cache-hit location.

Back to Task Scheduler

Latency Waterfall

Break down end-to-end latency by hop (network, application, database, cache) and percentile (p50/p90/p99/p99.9). Real requests have wildly different paths depending on cache-hit location — pick a scenario to see the full waterfall.

Amara Google 2009: every 100ms of latency = 1% revenue lost. Understanding WHERE the tail comes from is the difference between random optimization and targeted engineering.

Show percentile:
Aggregate p99: 620.0 ms

Urgent task — payment webhook (~10% of traffic, sub-500ms budget)

Payment webhook received. Retry logic requires processing within 500ms or Stripe retries. High priority queue.

10% of requests
App → Kafka: publish to 'urgent' topic
queue
40.0 ms
p50 5msp90 15msp99 40msp99.9 150ms

Kafka producer, acks=all for durability. Priority topic serves urgent workers.

Kafka broker: durable write + ISR replication
database
40.0 ms
p50 5msp90 15msp99 40msp99.9 150ms

Standard Kafka commit.

Urgent worker: poll + receive task (dedicated worker pool)
queue
100.0 ms
p50 10msp90 30msp99 100msp99.9 300ms

Dedicated worker pool for urgent queue. Poll interval very short (50ms).

Optimize: Urgent workers over-provisioned to keep queue empty. Cost of idle vs cost of late.

Worker: execute task (payment webhook logic)
application
400.0 ms
p50 50msp90 150msp99 400msp99.9 1500ms

Actual task execution.

Worker → Temporal: mark complete
database
40.0 ms
p50 5msp90 15msp99 40msp99.9 150ms

Persist completion for durability.

End-to-end aggregate
p50 75.0 ms
p90 225.0 ms
p99 620.0 ms
p99.9 2250.0 ms
Key insight

Urgent task enqueue-to-complete is **~100-500ms p99**. **Meets Stripe webhook 500ms budget**. Key: dedicated worker pool + short poll + over-provisioning. If urgent queue backs up = SLA breach.

Scenario 1 of 3

Bottleneck summary

Task scheduler latency depends **entirely on queue priority + task type**. Urgent tasks: sub-500ms (dedicated over-provisioned pool). Bulk tasks: hours (throughput-optimized, cost-optimized). Workflows: minutes to hours (multi-step). **The critical architectural insight**: Temporal's durability + workflow semantics + Kafka's priority topics enable different SLAs on same infrastructure. This is why every mature company runs Temporal or similar.

Optimization tips (this architecture)

  • **Dedicated worker pools per priority tier**: Prevents bulk-blocks-urgent.
  • **Over-provision urgent workers**: Empty queue is good — cost of idle < cost of late.
  • **Temporal for workflow semantics**: Durable state + resumption. Non-negotiable for multi-step tasks.
  • **Kafka acks=all for critical tasks**: Data loss unacceptable.
  • **Bulk tasks off-peak**: Reindex at 3am, not 3pm. Save infra cost.
  • **Task token idempotency**: Same task ID = same result. Prevents duplicate processing.
  • **Dead-letter queue**: Failed tasks go to DLQ. Manual review + replay.
  • **Priority queue starvation monitoring**: If bulk queue never drains, investigate.

Where to go next

Now that you can see where latency comes from, trace how the architecture EVOLVES to handle 10x more traffic. Or dive into the masterclass for the full ADR + business exercise + incident narrative.