Skip to content

Latest commit

 

History

History

README.md

Kotlin SDK API Proposal

This document describes the public API and developer experience for the Temporal Kotlin SDK.

Overview

The Kotlin SDK provides an idiomatic Kotlin experience for building Temporal workflows using coroutines and suspend functions.

Key Features:

  • Coroutine-based workflows with suspend fun
  • Full interoperability with Java SDK
  • Kotlin Duration support (30.seconds)
  • DSL builders for configuration
  • Null safety (no Optional<T>)

Requirements:

  • Minimum Kotlin version: 1.8.x
  • Coroutines library: kotlinx-coroutines-core 1.7.x+

Design Principle

Use idiomatic Kotlin language patterns wherever possible instead of custom APIs.

The Kotlin SDK should feel natural to Kotlin developers by leveraging standard kotlinx.coroutines primitives. Custom APIs should only be introduced when Temporal-specific semantics cannot be achieved through standard patterns.

Pattern Standard Kotlin Temporal Integration
Parallel execution coroutineScope { async { ... } } Works via deterministic dispatcher
Await multiple awaitAll(d1, d2) Standard kotlinx.coroutines
Sleep/delay delay(duration) Intercepted via Delay interface
Deferred results Deferred<T> Standard + Promise<T>.toDeferred()

This approach provides:

  • Familiar patterns: Kotlin developers use patterns they already know
  • IDE support: Full autocomplete and documentation for standard APIs
  • Ecosystem compatibility: Works with existing coroutine libraries and utilities
  • Smaller API surface: Less custom code to learn and maintain

Documentation Structure

Core Concepts

  • Kotlin Idioms - Duration, null safety, property syntax for queries
  • Configuration - KOptions classes, data conversion, interceptors

Building Blocks

Infrastructure

Reference

Quick Start

// Define activity interface - @ActivityMethod is optional
@ActivityInterface
interface GreetingActivities {
    suspend fun composeGreeting(greeting: String, name: String): String
}

// Implement activity
class GreetingActivitiesImpl : GreetingActivities {
    override suspend fun composeGreeting(greeting: String, name: String): String {
        return "$greeting, $name!"
    }
}

// Define workflow interface - @WorkflowMethod is optional
@WorkflowInterface
interface GreetingWorkflow {
    suspend fun getGreeting(name: String): String
}

// Implement workflow
class GreetingWorkflowImpl : GreetingWorkflow {
    override suspend fun getGreeting(name: String): String {
        return KWorkflow.executeActivity(
            GreetingActivities::composeGreeting,
            KActivityOptions(startToCloseTimeout = 10.seconds),
            "Hello", name
        )
    }
}

// Start worker - workflows and activities specified in options
val worker = KWorker(
    client,
    KWorkerOptions(
        taskQueue = "greetings",
        workflows = listOf(GreetingWorkflowImpl::class),
        activities = listOf(GreetingActivitiesImpl())
    )
)
worker.start()

// Execute workflow
val result = client.executeWorkflow(
    GreetingWorkflow::getGreeting,
    KWorkflowOptions(workflowId = "greeting-123", taskQueue = "greetings"),
    "Temporal"
)

Start Review →