Decoupling Temporal Services with Nexus and the Java SDK
Source: Dev.to

Your Temporal services share a blast radius. A bug in Compliance at 3 AM crashes Payments, too, because they share the same Worker. The obvious fix is separate services with HTTP calls between them – but then you’re managing HTTP clients, routing, error mapping, and callback infrastructure yourself.
We published a hands‑on tutorial on learn.temporal.io where you take a monolithic banking payment system and split it into two independently deployable services connected through Temporal Nexus.
What you’ll learn
- Nexus Endpoints, Services, and Operations from scratch
- Two handler patterns for different use cases
- How to swap an Activity call for a durable cross‑namespace Nexus call
Code comparison
The caller‑side change is minimal – the method call stays the same:
// BEFORE (monolith – direct activity call):
ComplianceResult compliance = complianceActivity.checkCompliance(compReq);
// AFTER (Nexus – durable cross‑team call):
ComplianceResult compliance = complianceService.checkCompliance(compReq);Same method name. Same input. Same output. Behind that swap: a shared service contract, a Nexus handler, an endpoint registration, and a Worker configuration change.
Nexus handler implementation
The Nexus handler backs the operation with a long‑running workflow so retries reuse the existing workflow instead of creating duplicates:
@OperationImpl
public OperationHandler checkCompliance() {
return WorkflowRunOperation.fromWorkflowHandle((ctx, details, input) -> {
WorkflowClient client = Nexus.getOperationContext().getWorkflowClient();
ComplianceWorkflow wf = client.newWorkflowStub(
ComplianceWorkflow.class,
WorkflowOptions.newBuilder()
.setTaskQueue("compliance-risk")
.setWorkflowId("compliance-" + input.getTransactionId())
.build());
return WorkflowHandle.fromWorkflowMethod(wf::run, input);
});
}Durability checkpoint
The tutorial includes a durability checkpoint: you kill the Compliance Worker mid‑transaction, restart it, and watch the payment resume exactly where it left off. No retry logic, no data loss across the namespace boundary. The Java SDK runs entirely on Temporal’s dev server.