Middleware sees the answer come back. A plain handler can't
transcript
You want an audit log of every payment. Even the ones a later check declines.
Ravi pays 25,000. The audit link logs it going in. Then it calls next. The limit check declines, and never calls next, so the bank is never reached. The verdict comes back through the audit link. It logs the verdict coming out, and passes it on.
A plain handler returns a verdict, or nothing. It never sees the answer come back. Middleware calls next itself. So it acts before, and after. That is how timing, audit and retries are written. Web frameworks use this shape for their middleware.
Three payments are sent, and one of them is over the limit. Audit first sees all 3. Even the declined one. Audit after the limit check sees only 2. The declined payment never reaches it.
An audit link goes first. Position decides what it sees.
Full breakdown in the lecture.