The Illusion of Immortality

Temporal's Magic for Reliable Workflows

Tomasz Nurkiewicz

Software eng. at Monday.com

nurkiewicz.com, @nurkiewicz@fosstodon.org

It's your first day at work...

Implement this

                    
                        sendRegistrationLink(user);
                        sleep(86400);
                        if(!isRegistered(user)) {
                            sendReminderLink(user);
                        }
                    
                

Demo time01

Problems

  • App can crash
  • sleep takes resources
  • Untestable

The illusion of a server running forever

Meet Temporal workflow engine

*Do not confuse with JavaScript Temporal API

Not your grandpas workflow engine

  • Microsoft BizTalk Server
  • BPMN
  • Airflow

Everything is a workflow

Any non-trivial code on the planet

  • Several steps
  • Branches, conditions, loop
  • Long-running
  • Distributed
  • Asynchronous
  • Retryable

Examples - implicit workflows

  • Microservice orchestration
  • Queues
  • Webhooks
  • Cron jobs
  • Periodic processes
  • Work distribution
  • Leader election
  • ...

Resiliency

Demo time02

Problems

  • One, heavy task on a single node
  • ...that can fail
  • ...but no resume/retry mechanism

Supported languages

  • Go
  • Java
  • PHP
  • Python
  • TypeScript
  • .NET

Under the hood

Server vs. worker vs. client

Temporal server

Event log and work queue

  • Database (SQL or Cassandra)
  • Elasticsearch
  • UI

State rehydration

Demo time

Worker node

Polls the server. Does the work

Client

Scalability

                    
                        for(user of getPayingUsers()) {
                            const invoice = prepareInvoice(user);
                            const url = storeOnS3(invoice);
                            sendEmail(user.email, url);
                        }
                    
                

Demo time03

Testing

  • First class support
  • Replaying process locally from event log!

The bad

There's no magic, just leaky abstractions

The server is a single point of failure

Sensitive database

All arguments and return values are stored

Versioning is tricky

Tracking progress is not that easy

Activities should be idempotent

Watch out for non-determinism

new Date() and Math.random() are monkey-patched!

Verdict

Impressive... And scary. But impressive!

Materials

Alternatives

Thank you!

nurkiewicz.com, @nurkiewicz@fosstodon.org


nurkiewicz.com/slides/temporal-workflow