Northwind Logistics · Engineering guides · Start here

The order journeyv1.0

A declined card

Make the bank slow, watch the first payment time out, and see the retry turn it into a paid order.

At 21:03 the real order #4711 was declined: the bank's fraud check timed out during its nightly batch. Here you make the fake bank just as slow.

Time 15 minutes
You need The lab running, a fresh order (run Reset the lab first if #4711 is already paid)

1Make the bank slow#

Shell
curl -X POST localhost:8081/admin/latency -d '{"ms": 25000}'

The fake bank now takes 25 seconds to answer, longer than the 15 seconds the payment service waits.

2Read the retry#

This is the part of the payment service that saves the order, in the three languages the lab ships. Pick yours; the choice sticks on every page.

JavaJava
var key = order.id();
var result = bank.authorize(card, amount, key);
if (result.isTimeout()) {
    Thread.sleep(Duration.ofSeconds(30));
    result = bank.authorize(card, amount, key);
}
return result;
  1. The order id is the idempotency key, the same on both calls.
  2. One retry only, thirty seconds later.
  3. A second timeout is returned as it is: the customer sees "still checking".

The same key goes with both calls, so the bank cannot charge the card twice.

3Pay and wait#

Shell
time curl -X POST localhost:8082/orders/4711/pay
text
{"order": 4711, "status": "paid", "attempts": 2, "elapsed_ms": 30412}
real    0m30.4s

The tracking page showed Still checking your payment for thirty seconds, then turned the payment tile green.

This is how the talk tells the same moment:

From The order journey, in three slides, slides 2–3. Click the slides, then use the arrow keys.

Warning

Set the bank back to normal before the next page: curl -X POST localhost:8081/admin/latency -d '{"ms": 200}'.

Edit this page

Questions about this guide go to #order-journey on chat. The lab runs on your laptop and never touches production.