Activities

This page covers the practical patterns for building activities. For the underlying model (atomicity, retries, replay semantics), see Core Concepts > Activities.

An activity is a unit of work that performs computations, API calls, file I/O, LLM calls, or anything else with side effects. Key characteristics:

  • Safe to re-execute: a retry after a partial failure leaves the system in a consistent state. Side effects converge to the same observable outcome (the precise notion of idempotency; outputs need not be byte-identical).
  • Isolated execution: each activity runs in its own process, with automatic retries on failure.
  • JSON-serializable I/O: inputs and outputs accept any JSON-serializable types, such as str, int, dict, or list.
  • Per-call limit: 2MB of input or output per call. For larger payloads, see Payload offloading.
Topics

Topics

  • Basics: defining activities, configuring timeouts and retries, heartbeats, granularity, nesting. Start here.
  • Local activities: run sub-second activities directly in the workflow worker to skip scheduling overhead.
  • Sticky worker sessions: pin a sequence of activities to the same worker to share an in-memory resource (for example, a loaded ML model or a database connection).
Choosing an activity flavor

Choosing an activity flavor

ModeRouting overheadWorker isolationResource sharingBest for
Regular activityStandardYesNoAPI calls, complex logic, anything with retries
Sticky sessionStandardYesYes (in-memory)Reusing a loaded model or database connection
Local activityNoneNoN/ASub-second pure computations and lookups