Two coroutines, one journal: a Restate restart demo
Both preparation steps had finished when I stopped the Node process. The Restate server stayed running. After I started the service again, the pending invocation returned ["A", "B"] , and the preparation writes were still present only once each. This is the small recovery demo I wanted for Restate's new durable coroutines: two routines with their own steps, an interruption in the middle, and a…
The demonstration of Restate's new durable coroutines involved two separate routines, each with its own steps. An interruption occurred in the middle of the process, and the file was used to ensure the executed effects were easily inspectable. The routines utilized generator-based coroutines provided by Restate, allowing the scheduler to control when the routines advanced. I/O operations could overlap during completion, while the order of completion was recorded for recovery purposes.
The Restate Server version 1.8.1, Node.js 22.22.1, and the corresponding JavaScript packages at version 1.18.2 were used in the demo. The service wrote a short line during preparation, waited on a durable timer, and then wrote a finish line. The value returned by the generator traveled through the local variable and into the final result.
The service was implemented in a file named "service.mjs" using the following dependencies:
```javascript
npm install --save-exact @restatedev/restate-sdk@1.18.2 @restatedev/restate-sdk-gen@1.18.2
```
The service code included the creation of two lane functions (`prepare-a` and `prepare-b`) that returned generators. These generators handled the preparation and finish steps for each routine, writing the corresponding lines to a file named "effects.log". The `sleep` function was used to introduce an 8-second delay between the preparation and finish steps, allowing for an interruption window.
The service was configured in a "restate.toml" file, which specified the Restate server settings, including the binding addresses and memory size. The server was started using Node.js with the service file ("service.mjs") as the entry point.
To invoke the service, a request was made to the server's ingress endpoint at "http://127.0.0.1:18080/CoroutineDemo/run" with a JSON null body. Directly calling the Node.js endpoint would skip the server that owned the journal. After the first invocation finished without interruption, the results were consistent, with each preparation and finish line written once to the file.
For the restart trial, an interruption was introduced in the middle of the process. The service was able to handle the interruption, and the file was used to verify that the executed effects remained intact.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.