newCreateInstanceCommand().withResult() Failed with code 504: 'Gateway Timeout'

I am using camunda-spring-boot-starter.8.8.0-SNAPSHOT.jar
and when trying to create a new process instance with the result as follows:

ProcessInstanceResult result = camundaClient.newCreateInstanceCommand()
.bpmnProcessId(request.getBpmnProcessId()).latestVersion().variables(request.getVariablesMap())
		.withResult().requestTimeout(Duration.ofSeconds(60)).send().join();

I get the following exception:

io.camunda.client.api.command.ProblemException: Failed with code 504: 'Gateway Timeout'. Details: 'class ProblemDetail {
    type: about:blank
    title: DEADLINE_EXCEEDED
    status: 504
    detail: Expected to handle request, but request timed out between gateway and broker
    instance: /v2/process-instances
}'
	at io.camunda.client.impl.http.ApiCallback.handleErrorResponse(ApiCallback.java:133) ~[camunda-client-java-8.8.0-SNAPSHOT.jar:8.8.0-SNAPSHOT]
	at io.camunda.client.impl.http.ApiCallback.completed(ApiCallback.java:72) ~[camunda-client-java-8.8.0-SNAPSHOT.jar:8.8.0-SNAPSHOT]
	at io.camunda.client.impl.http.ApiCallback.completed(ApiCallback.java:32) ~[camunda-client-java-8.8.0-SNAPSHOT.jar:8.8.0-SNAPSHOT]
	at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:148) ~[httpcore5-5.3.5.jar:5.3.5]
	at org.apache.hc.core5.concurrent.ComplexFuture.completed(ComplexFuture.java:72) ~[httpcore5-5.3.5.jar:5.3.5]

Note: when I open operate, I can see that the instance is created.

Hi there! :waving_hand:

I can see you’re experiencing a 504 Gateway Timeout error when using .withResult() with the Camunda Java client. This is a common issue that typically occurs when the client doesn’t receive a response within the expected timeframe.

Classification: Problem

Root Cause Analysis

The error DEADLINE_EXCEEDED with the message “Expected to handle request, but request timed out between gateway and broker” indicates that:

  1. Your process instance IS being created (as confirmed by seeing it in Operate)
  2. The timeout occurs while waiting for the result, not during creation
  3. The .withResult() method waits for process completion, which may take longer than your current timeout

Solutions

1. Increase Client Timeout

Since you’re already setting requestTimeout(Duration.ofSeconds(60)), try increasing it further. You can also configure this globally in your Spring Boot application:

# application.yml
zeebe:
  client:
    request-timeout: 300s  # 5 minutes

2. Check Your Process Model

The .withResult() method waits for the entire process to complete. If your process contains:

  • User tasks
  • Timer events
  • External service calls
  • Long-running activities

Consider whether you really need to wait synchronously for completion.

3. Alternative Approach for Long-Running Processes

For processes that might take longer, consider this asynchronous pattern:

// Start process without waiting for result
ProcessInstanceEvent processInstance = camundaClient
    .newCreateInstanceCommand()
    .bpmnProcessId(request.getBpmnProcessId())
    .latestVersion()
    .variables(request.getVariablesMap())
    .send()
    .join();

// Later, query for results when needed
// or use process instance listeners/webhooks

4. Infrastructure Considerations

If you’re using a reverse proxy (Nginx, load balancer), ensure its timeout settings are higher than your client timeout.

Immediate Action

Try increasing your timeout to 5-10 minutes first:

ProcessInstanceResult result = camundaClient.newCreateInstanceCommand()
    .bpmnProcessId(request.getBpmnProcessId())
    .latestVersion()
    .variables(request.getVariablesMap())
    .withResult()
    .requestTimeout(Duration.ofMinutes(5))  // Increased timeout
    .send()
    .join();

Questions for You

  1. How long does your process typically take to complete?
  2. Does your process contain any user tasks or timer events?
  3. Are you using Camunda SaaS or Self-Managed?

References:

Let me know if increasing the timeout resolves the issue or if you need help with the asynchronous approach!

In my spring application.properties file, I added

zeebe.client.request-timeout: 300s

And still getting same issue

Thanks for the update! Since increasing the client timeout to 300s didn’t resolve the issue, this points to an infrastructure-level timeout problem rather than a client configuration issue.

Root Cause: Infrastructure Timeout

The error message “request timed out between gateway and broker” combined with your client timeout not helping suggests you have a reverse proxy or load balancer (like Nginx, HAProxy, or cloud load balancer) between your application and the Zeebe gateway that has its own timeout settings.

Key Questions

  1. Are you using Camunda SaaS or Self-Managed?
  2. Do you have any reverse proxy/load balancer in front of Zeebe? (Nginx, HAProxy, cloud load balancer, etc.)
  3. What’s your deployment setup? (Kubernetes, Docker, cloud provider)

Most Likely Solutions

If Using Nginx or Similar Proxy

You need to configure the proxy timeout to be higher than your client timeout:

location / {
    grpc_pass grpc://zeebe-gateway:26500;
    grpc_send_timeout 400s;  # Higher than your 300s client timeout
    grpc_read_timeout 400s;
}

If Using Cloud Load Balancer

  • AWS ALB: Check target group settings for timeout
  • GCP Load Balancer: Check backend service timeout
  • Azure Load Balancer: Check probe and timeout settings

If Using Kubernetes Ingress

Check your ingress controller timeout settings:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/grpc-backend: "true"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "400"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "400"

Debugging Steps

1. Test Direct Connection

Try connecting directly to the Zeebe gateway (bypassing any proxy) to confirm if the issue is infrastructure-related:

// Temporarily test with direct connection
ZeebeClient client = ZeebeClient.newClientBuilder()
    .gatewayAddress("your-zeebe-gateway:26500")  // Direct connection
    .usePlaintext()
    .build();

2. Check Your Process Duration

Since the instance is created but .withResult() times out, your process might be taking longer than expected. Can you check:

  • Does your process have user tasks that need manual completion?
  • Are there timer events or external service calls?
  • How long does the process actually take to complete in Operate?

3. Monitor Infrastructure Logs

Check logs from your proxy/load balancer for timeout-related messages around the time of the error.

Alternative Approach

If you can’t immediately fix the infrastructure timeouts, consider this pattern:

// Start process asynchronously
ProcessInstanceEvent processInstance = camundaClient
    .newCreateInstanceCommand()
    .bpmnProcessId(request.getBpmnProcessId())
    .latestVersion()
    .variables(request.getVariablesMap())
    .send()
    .join();

// Poll for completion or use webhooks/listeners
long processInstanceKey = processInstance.getProcessInstanceKey();
// Implement polling logic or use process instance listeners

Next Steps

Please share:

  1. Your deployment architecture (SaaS/Self-Managed, proxy setup)
  2. How long your process typically takes to complete
  3. Any proxy/load balancer configurations you have

This will help me provide more specific guidance!

References: