What the pattern is trying to achieve
Coordinate request handling, business processing, and view rendering as distinct steps in one web flow.
Service to Worker separates request handling, business execution, and rendering so the web layer stays coordinated without collapsing into controller-centric business logic.
Checkout, returns, and order placement flows often need validation, business orchestration, and then a rendered success or failure screen. Service to Worker gives that flow a clean shape.
Coordinate request handling, business processing, and view rendering as distinct steps in one web flow.
Controllers often mix parameter parsing, business orchestration, and rendering decisions in one place.
Use the controller to receive the request, invoke application services, populate the model, and forward to a dedicated view.
This remains the dominant shape of many Spring MVC web flows and server-rendered business applications.
package org.javaomnibus.ecommerce.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public final class CheckoutController {
private final CheckoutApplicationService checkoutApplicationService;
public CheckoutController(CheckoutApplicationService checkoutApplicationService) {
this.checkoutApplicationService = checkoutApplicationService;
}
@PostMapping("/checkout")
public String checkout(CheckoutForm form, Model model) {
CheckoutReceipt receipt = checkoutApplicationService.checkout(form.toCommand());
model.addAttribute("receipt", receipt);
return "checkout-success";
}
}
Service to Worker is stronger than Dispatcher View when meaningful business processing occurs before rendering. Dispatcher View is lighter when the controller mostly prepares a model and forwards.