Spring Boot + Camunda External Task Pattern (Complete Guide)

 In enterprise workflows, long-running business logic should not execute inside the workflow engine.

Instead, Camunda uses the External Task Pattern — where workers fetch tasks and process them independently.

This is the most scalable way to integrate microservices with BPM.

In this guide you will learn:

  • What External Tasks are

  • Why they are important

  • How to implement using Spring Boot

  • Best practices for production


📌 What is the External Task Pattern?

In Camunda Platform, a Service Task can be executed outside the engine.

Instead of pushing work → the worker pulls the job.

So the engine never blocks.


🖼️ External Task Architecture


🧠 Why External Tasks?

Traditional Service Task:

Engine calls service directly
→ Tight coupling
→ Failures block workflow

External Task:

Worker fetches job
→ Loose coupling
→ Retry possible
→ Highly scalable


🛠 Step 1: Create External Service Task in BPMN

In Modeler:

Service Task → Type = External

Topic name example:

payment-service

Now Camunda waits for a worker.


🛠 Step 2: Add Dependencies in Spring Boot

<dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter-external-task-client</artifactId> </dependency>

🛠 Step 3: Configure Worker

camunda: bpm: client: base-url: http://localhost:8080/engine-rest async-response-timeout: 10000

🛠 Step 4: Implement External Task Worker

@Component @ExternalTaskSubscription("payment-service") public class PaymentWorker implements ExternalTaskHandler { @Override public void execute(ExternalTask task, ExternalTaskService service) { String orderId = task.getVariable("orderId"); System.out.println("Processing payment for " + orderId); service.complete(task); } }

Worker automatically polls tasks.


🖼️ Worker Execution Flow


🔁 Retry & Failure Handling

If service fails:

service.handleFailure( task, "Payment failed", "Gateway timeout", 3, 60000 );

Camunda retries automatically.


🔐 Lock Duration

Worker locks job while processing.

Prevents multiple workers executing same task.

Example:

lockDuration = 10000 ms

🧪 Complete Flow

  1. Process reaches service task

  2. Engine creates external task

  3. Worker fetches task

  4. Worker executes logic

  5. Worker completes task

  6. Process continues


⚠️ Common Mistakes

❌ Short lock duration
❌ No retries configured
❌ Business logic inside engine
❌ Blocking API calls


🏆 Production Best Practices

✔ Use multiple workers
✔ Idempotent services
✔ Configure retries
✔ Separate microservices
✔ Monitor failures


🎯 When to Use External Tasks

Use for:

  • Microservices

  • Remote APIs

  • Long processing

  • Payment gateways

  • Third-party integrations

Avoid for:

  • Simple Java logic

  • Short execution


🎯 Conclusion

External Task Pattern makes Camunda:

  • Scalable

  • Resilient

  • Microservice-friendly

It is the recommended approach for enterprise integration.


Recommended Reading


💼 Need Help with Camunda, Jira, or Enterprise Workflows?

I help teams solve real production issues and build scalable systems.

Services I offer:
• Camunda & BPMN workflow design and debugging  
• Jira / Confluence setup and optimization  
• Java, Spring Boot & microservices architecture  
• Production issue troubleshooting  


📩 Email: ishikhanirankari@gmail.com | info@realtechnologiesindia.com

✔ Available for quick consulting calls and project-based support
✔ Response within 24 hours


🎥 Learn IT with Shikha on YouTube

Prefer learning through videos? Watch practical tutorials on Kafka, Camunda, Alfresco, Java, Spring Boot, Microservices and Enterprise Architecture.

▶ Subscribe to Learn IT with Shikha on YouTube

Comments

Popular posts from this blog

Top 50 Camunda BPM Interview Questions and Answers for Developers (2026 Guide)

10 BPMN Best Practices Every Camunda Developer Should Know

OOPs Concepts in Java | English | Object Oriented Programming Explained