Tech News
← Back to articles

Dbos: Durable Workflow Orchestration with Go and PostgreSQL

read original related products more articles

What is DBOS?

DBOS provides lightweight durable workflow orchestration on top of Postgres. Instead of managing your own workflow orchestrator or task queue system, you can use DBOS to add durable workflows and queues to your program in just a few lines of code.

When Should I Use DBOS?

You should consider using DBOS if your application needs to reliably handle failures. For example, you might be building a payments service that must reliably process transactions even if servers crash mid-operation, or a long-running data pipeline that needs to resume seamlessly from checkpoints rather than restart from the beginning when interrupted.

Handling failures is costly and complicated, requiring complex state management and recovery logic as well as heavyweight tools like external orchestration services. DBOS makes it simpler: annotate your code to checkpoint it in Postgres and automatically recover from any failure. DBOS also provides powerful Postgres-backed primitives that makes it easier to write and operate reliable code, including durable queues, notifications, scheduling, event processing, and programmatic workflow management.

Features

💾 Durable Workflows DBOS workflows make your program durable by checkpointing its state in Postgres. If your program ever fails, when it restarts all your workflows will automatically resume from the last completed step. You add durable workflows to your existing Golang program by registering ordinary functions as workflows or running them as steps: package main import ( "context" "fmt" "os" "time" "github.com/dbos-inc/dbos-transact-golang/dbos" ) func workflow ( dbosCtx dbos. DBOSContext , _ string ) ( string , error ) { _ , err := dbos . RunAsStep ( dbosCtx , stepOne ) if err != nil { return "" , err } return dbos . RunAsStep ( dbosCtx , stepTwo ) } func stepOne ( ctx context. Context ) ( string , error ) { fmt . Println ( "Step one completed!" ) return "Step 1 completed" , nil } func stepTwo ( ctx context. Context ) ( string , error ) { fmt . Println ( "Step two completed!" ) return "Step 2 completed - Workflow finished successfully" , nil } func main () { // Initialize a DBOS context ctx , err := dbos . NewDBOSContext ( context . Background (), dbos. Config { DatabaseURL : os . Getenv ( "DBOS_SYSTEM_DATABASE_URL" ), AppName : "myapp" , }) if err != nil { panic ( err ) } // Register a workflow dbos . RegisterWorkflow ( ctx , workflow ) // Launch DBOS err = dbos . Launch ( ctx ) if err != nil { panic ( err ) } defer dbos . Shutdown ( ctx , 2 * time . Second ) // Run a durable workflow and get its result handle , err := dbos . RunWorkflow ( ctx , workflow , "" ) if err != nil { panic ( err ) } res , err := handle . GetResult () if err != nil { panic ( err ) } fmt . Println ( "Workflow result:" , res ) } Workflows are particularly useful for Orchestrating business processes so they seamlessly recover from any failure.

Building observable and fault-tolerant data pipelines.

Operating an AI agent, or any application that relies on unreliable or non-deterministic APIs.

📒 Durable Queues DBOS queues help you durably run tasks in the background. When you enqueue a workflow, one of your processes will pick it up for execution. DBOS manages the execution of your tasks: it guarantees that tasks complete, and that their callers get their results without needing to resubmit them, even if your application is interrupted. Queues also provide flow control, so you can limit the concurrency of your tasks on a per-queue or per-process basis. You can also set timeouts for tasks, rate limit how often queued tasks are executed, deduplicate tasks, or prioritize tasks. You can add queues to your workflows in just a couple lines of code. They don't require a separate queueing service or message broker—just Postgres. package main import ( "context" "fmt" "os" "time" "github.com/dbos-inc/dbos-transact-golang/dbos" ) func task ( ctx dbos. DBOSContext , i int ) ( int , error ) { dbos . Sleep ( ctx , 5 * time . Second ) fmt . Printf ( "Task %d completed

... continue reading