Skip to content

title: CloudSlash - Saga Orchestration Reference description: Cloud APIs have no transaction protocol. s.a.u builds one on top of them using sagas: ordered sequences of operations, each paired with a rollback. Terminati...


Saga Orchestration

Cloud APIs have no transaction protocol. s.a.u builds one on top of them using sagas: ordered sequences of operations, each paired with a rollback.


Distributed Transactions

Absence of

Terminating a Kubernetes cluster and dropping its affiliated managed database cluster requires two separate API calls. 2PC fails here: CloudSlash has no authority over the cloud APIs pre-commit phase.

If step one succeeds and step two fails, the topology is broken, with orphaned resources left behind.

Compensation Sequences

We implement sagas. Each mutation (Forward) requires an explicit compensating action (Compensate) assigned before execution.

// pkg/engine/swarm/saga_bridge.go
type Saga struct {
    Steps []Step
}

type Step struct {
    Execute    func(ctx context.Context) error
    Compensate func(ctx context.Context) error
}

If a 5-step sequence fails at step n=3, the engine isolates the parent loop and iterates n-1, n-2, n-3 sequentially, firing the bound Compensate lambdas.

Contextual Detachment

Passing context.TODO() or the HTTP parent context down through the pipeline is standard Go. But if you kill the process mid-saga at step n=3, passing the parent context to Compensate cancels the rollback: leaving state fragmented.

We resolve this by cloning the root context and explicitly severing the cancellation signal for the rollback path.

func (m *SAUEngine) executeRollback(ctx context.Context, s *Saga, failedIndex int) {
    // context.WithoutCancel guarantees the compensating operations
    // execute entirely regardless of subsequent user termination signals.
    unwindCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Minute)
    defer cancel()

    for i := failedIndex - 1; i >= 0; i-- {
        _ = s.Steps[i].Compensate(unwindCtx)
    }
}

The rollback runs to completion even if you kill the process. State integrity beats speed.