The Native Durable Execution Engine is a lightweight Java-based system that enables durable, resumable workflow execution using plain Java code. The engine guarantees that each logical step in a workflow is executed at most once, even in the presence of process crashes or restarts.
Long-running workflows often fail due to crashes, restarts, or partial execution. Re-running such workflows from scratch can:
- Re-trigger already executed side effects
- Corrupt system state
- Cause duplicate external actions
The goal of this assignment is to build a durable execution primitive that ensures:
A step that has completed successfully is never executed again.
- Durable step execution using persistent storage
- At-most-once semantics per workflow step
- Automatic resume on restart
- Support for parallel execution
- Minimal API surface (single
step()primitive) - Native Java implementation (no DSLs, no frameworks)
Application Code
│
▼
DurableEngine.step(id, fn)
│
▼
SQLite Database (steps table)
│
├── If DONE → return cached output
└── If NOT DONE → execute & persist result
Each workflow step is identified by a logical step ID combined with a sequence number, ensuring correctness across loops and conditionals.
| Component | Technology |
|---|---|
| Language | Java 21 |
| Concurrency | Virtual Threads + CompletableFuture |
| Persistence | SQLite |
| Serialization | Jackson |
| Build Tool | Maven |
durable-engine/
├── pom.xml
├── README.md
└── src/main/java
├── com/example/durable
│ ├── DurableEngine.java
│ └── MainApp.java
└── examples/onboarding
└── EmployeeOnboardingWorkflow.java
<T> T step(String id, Callable<T> fn)- Executes the provided function only if the step has not already completed
- Persists the result upon successful execution
- Returns cached output on subsequent runs
To support loops and repeated step names, the engine internally generates a sequence number:
step-key = stepId + sequenceNumber
This mimics the logical clock used by production workflow engines.
- Start workflow
- Some steps complete and are persisted
- Process crashes or is killed
- Application restarts
- Engine skips completed steps and resumes execution
The engine supports parallel steps using standard Java concurrency:
CompletableFutureExecutors.newVirtualThreadPerTaskExecutor()
Thread safety is ensured via synchronized access to the durable step method.
- Java 21+
- Maven 3.8+
- IntelliJ IDEA (recommended)
- Open the project in IntelliJ IDEA
- Ensure Project SDK is set to Java 21
- Run
MainApp.java - Kill the process midway
- Re-run to observe durable resume behavior
This project demonstrates how durable execution semantics can be built natively in Java with minimal infrastructure. While simple, the engine captures the core ideas behind production workflow systems and serves as a strong foundation for further extension.