How Durable Execution Works
In part 2 of the series "Building Reliable Distributed Systems in Node.js", we explore how Temporal can provide durable execution. A function that is fail-safe, long-lasting and doesn't require database storage? It sounds like magic but it's just JavaScript running on any server capable of running Node.js. The process involves three parts: the Client, Server, and Worker. The Client initiates commands such as "start the order() durable function", "send a delivered Signal" or "terminate the function". The Worker is a long-running Node.js process that contains our code and polls the Server for tasks. Tasks look like "run the order() durable function" or "run the normal sendPushNotification() function". After the Worker runs the code, it reports the result back to the Server. In production, web apps and their serverless functions are deployed to Vercel, the long-running Worker process is deployed to Render, and they both talk to a Server instance hosted by Temporal Cloud. In development, we can run all three parts locally using the Temporal CLI. The Event History is the core of what enables durable execution: a log of everything important that the Workflow does and gets sent. It allows us to Ctrl-C our Worker process, start it again, open up the UI, select our completed order Workflow, go to the Queries tab of the UI, and send the getStatus Query. We examined how durable code works under the hood: we can write functions that can't fail to complete executing (since when the Worker process dies, the next Worker to pick up the task will get the function's Event History and use the events to re-run the code until it's in the same state). We can also retry the functions that might have transient failures.
Company
Temporal
Date published
March 16, 2023
Author(s)
Loren Sands-Ramshaw
Word count
1908
Hacker News points
None found.
Language
English