Practical System Design

Labs / Chapter 4

Checkout returns while the fraud call is still running

Start with a provider call that fits inside the child deadline. Then slow the provider until work is still running after checkout returns. Pass cancellation with the deadline, then refuse the permit once and compare the deferred path.

The system

The child deadline is 750 ms, capped at 1000 ms. Checkout returns at 80 ms and the provider is not still running.

assessscore

Checkout

80 ms of 800 left

Fraud

Child deadline 750 ms

Provider

80 ms of work

reserve_fraud_call

  1. # remaining_ms = provider_ms =
  2. def reserve_fraud_call(request):
  3. deadline = request.child_deadline(
  4. maximum_ms=1000,
  5. reserve_ms=,
  6. )
  7. if not deadline.can_start_call():
  8. return deadline, None
  9. permit =
  10. def evaluate_risk(assessment, request, permit, deadline):
  11. with permit:
  12. cancellation=
  1. Child deadline750 ms, capped at 1000
  2. Caller80 ms of 800 left
  3. Provider80 ms, inside the child deadline

Caller time and provider work left running

Caller time should stay inside the time checkout has left. The second line is provider work continuing after checkout returns.

Caller 80.0 · Still running 0.0

The chart fills as the lab runs. ms is the vertical unit.

  • Caller
  • Still running
  • ms