Welcome to the new Golem Cloud Docs! 👋
Durability

Control durability guarantees

Golem provides a set of functions components can call to control details of the durable execution engine.

General concepts

The library allows controlling four main aspects of the durable execution engine: the current persistence level, the idempotence mode, defining atomic regions and changing retry policies (discussed in the next page).

All these features are regional - they can be changed for a section of the code within a single exported function.

In TypeScript, the SDK provides scoped helpers such as withPersistenceLevel, withIdempotenceMode, and withRetryPolicy. They run a sync or async callback with the requested setting, then restore the previous settings afterwards.

Persistence level

The persistence level can be one of the following:

LevelDescription
PersistNothingTurns off persistence for a section. In case the agent is recovered or restarted, all the side-effecting functions will be reexecuted
PersistRemoteSideEffectsPersists all the side-effects that are affecting the outside world. In case of recovery the side-effects won't be reexecuted and the persisted results will be used.
SmartThe default setting; Let Golem decide what to persist to optimize performance

To change the persistence level for a section of the code, use the withPersistenceLevel function:

import {withPersistenceLevel} from "@golemcloud/golem-ts-sdk"
 
const result: string = withPersistenceLevel({tag: "persist-nothing"}, () => {
  // this closure runs in PersistNothing mode
  return "hello"
})

Idempotence mode

Golem assumes that HTTP requests are idempotent by default. This means that in case of a failure, if the system cannot determine whether the request successfully reached the target or not, it will be retried.

This behavior can be changed using the withIdempotenceMode function:

import {withIdempotenceMode} from "@golemcloud/golem-ts-sdk"
 
const result: string = withIdempotenceMode(false, () => {
  // this closure runs with idempotence mode disabled
  return "hello"
})

With disabled idempotence mode, in case Golem cannot determine if the request was sent or not, it won't retry it, but the agent will fail.

Atomic regions

By default, side effects are persisted and retried one by one. It is possible to group them together into atomic regions, in which case the execution is retried for some reason (the agent failed or interrupted within the region), all the side effects will be reexecuted.

The golem-ts-sdk library exports the atomically function for using atomic regions:

import {atomically} from "@golemcloud/golem-ts-sdk"
 
const result: [string, string] = atomically<[string, string]>(() => {
  const firstResult: string = firstSideEffect()
  const secondResult: string = secondSideEffect(firstResult)
  return [firstResult, secondResult]
})

Commit oplog

Wait until the oplog is replicated to a specified number of replicas before continuing:

import { oplogCommit } from '@golemcloud/golem-ts-sdk';
 
// Ensure oplog is replicated to 3 replicas before proceeding
oplogCommit(3);