Skip to content

Choosing a runtime

DigitalOcean gives you several places to run code. They differ in what starts your program, how long it lives, and how much of the machine underneath is yours to look after. App Platform and Functions run the same kind of Alchemy program and take the same bindings. Kubernetes and Droplets run what you put on them.

Functionper request
App serviceon requests
App jobon a schedule
KubernetesDOKS
Dropleta VM
your program
you
you
you
you
you
image
DigitalOcean
you
you
you
you
scaling
DigitalOcean
you
you
you
you
orchestration
DigitalOcean
DigitalOcean
DigitalOcean
you
you
OS & patching
DigitalOcean
DigitalOcean
DigitalOcean
DigitalOcean
you
hardware
DigitalOcean
DigitalOcean
DigitalOcean
DigitalOcean
DigitalOcean
From left to right, DigitalOcean manages less and you decide more. Only a Droplet leaves the operating system to you.

The same program on App Platform and Functions

Section titled “The same program on App Platform and Functions”

You declare either one with an id, its configuration and an Effect. Construction binds what the program uses, and it returns a fetch handler:

src/api.ts
import * as DigitalOcean from "@alchemy.run/digitalocean";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { Uploads } from "./resources.ts";
export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url, region: "nyc" },
Effect.gen(function* () {
const getObject = yield* DigitalOcean.Spaces.GetObject(Uploads);
return {
fetch: Effect.gen(function* () {
const object = yield* getObject({ Key: "hello.txt" });
return HttpServerResponse.text(String(object.ContentLength ?? 0));
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Spaces.GetObjectHttp)),
) {}

Change DigitalOcean.App to DigitalOcean.Functions.Function and region to namespace, and the same handler runs as a Function. The bindings don’t change.

An App runs your program as a container behind HTTPS, with as many instances as you ask for. Instances keep running between requests, so there’s no cold start, and you pay for them by the second whether or not traffic arrives.

It’s an easy place to start, and it fits APIs, websites and anything that holds state in memory between requests.

instance 1running · many requests at onceinstance 2runningno trafficinstance 1running · many requests at onceinstance 2runningno traffic
An App keeps its instances running. Each serves many requests at once, and idle instances are still billed.

A scheduled job runs the App’s own image on a cron schedule, does its work and exits. It shares the App’s code and bindings, so a nightly report is a few lines next to the handler.

nightly jobruns, then exitsnext night03:0003:00nightly jobruns, then exitsnext night03:0003:00
A job runs to completion at each scheduled time. Between runs nothing runs.

A Function runs only while a request is in flight and is billed per run, in gigabyte-seconds. An idle Function costs nothing. A cold one takes a moment to start.

It fits spiky or rare traffic: webhooks, small APIs, scheduled tasks with a trigger.

functionrequestrequestrequestidle: nothing billedfunctionrequestrequestrequestidle: nothing billed
A Function runs per request. A warm one answers at once; after a while idle, the next request starts it cold.

DigitalOcean Kubernetes runs the control plane; your workloads run on node pools, groups of Droplets of one size. You apply manifests from the same Stack.

A cluster takes about ten minutes to create and its nodes cost money while they exist. Choose it when you want Kubernetes itself: Helm charts, operators, or workloads you already run on it.

A Droplet is a VM: you choose its size and image, and everything on it is yours, from the packages to the security updates. It runs, and is billed, until you destroy it.

Choose it for software that needs a whole machine: a game server, a database you run yourself, a long-running process with local disk.

An app rarely needs just one. A common shape is an App for the API with a nightly job, and a Function for webhooks the API calls:

InvokeFunctionPutObjectPutObjectApiApp serviceResizeFunctionReportApp jobUploadsSpaces bucketInvokeFunctionPutObjectPutObjectApiApp serviceResizeFunctionReportApp jobUploadsSpaces bucket

Each runtime gets its own keys from its own bindings, each reaching one resource.