Generic middleware pattern for sequential operations.