automation2026.05.299 min read
Building idempotent automation loops with n8n and Go
The hardest part of automation is not making it run — it is making it safe to run again. Every loop I ship is idempotent: re-running it converges to the same state instead of duplicating work.
The trick is to separate intent from action. n8n orchestrates the workflow and decides what should be true; a small Go worker enforces it, checking current state before mutating anything. Dedupe keys make retries free.
worker.go
func Apply(ctx context.Context, desired State) error {
current, err := Fetch(ctx, desired.Key)
if err != nil {
return err
}
if current.Equals(desired) {
return nil // already converged
}
return Reconcile(ctx, current, desired)
}Because Apply is a no-op when state already matches, the same loop can fire on a schedule, a webhook, or a manual retry with identical results. Failures become boring — you just run it again.
#n8n#go#automation