In this code, the 'switchIfEmpty()' method always calls createWebSession(). If this is unintentional, it needs to be fix.
return Mono.defer(() -> retrieveSession(exchange)
.switchIfEmpty(createWebSession())
.doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session))));
Please review and let me know if I misunderstood.