A worked example
A permit-intake app, with a public submission portal, a reviewer dashboard, and the data behind both, written out in full so every section appears at least once. It is an illustration rather than something to clone, and it is deliberately larger than the everyday shape: it spans several backends, which is why some of its Functions sit in a backend block of their own. Every Function appears in the file whether or not it names a backend; the Functions and Workers in the file are what the slice deploys, and they are also its slots.
This one file is the whole of what the slice is and what it costs. Each Function books its memory beside its route, each collection, database and bucket states its size, and the slice-wide limits sit in one limits block. There is no other place a size is chosen, so drift plan can quote the price from the file alone.
slice "permit-intake" {
labels = { client = "Gemeente Amsterdam", env = "production" }
limits {
timeout = "30s"
log_retention = "72h"
backup_retention = "7d"
queue_depth = 500
}
}
variable "decision_memory" {
default = "128MiB"
}
environment "staging" {
vars = { decision_memory = "64MiB" }
}
atomic {
backend "default" {
function "POST /submit" {
handler = "PostSubmit"
memory = "32MiB"
}
function "GET /permit-types" {
handler = "GetPermitTypes"
memory = "32MiB"
}
function "GET /status/:token" {
handler = "GetStatusToken"
memory = "32MiB"
}
# parses the uploaded file, off the queue
function "QUEUE validate" {
handler = "QueueValidate"
memory = "64MiB"
}
}
backend "reviewer" {
function "POST /reviewer/login" {
handler = "PostReviewerLogin"
memory = "32MiB"
}
function "GET /reviewer/queue" {
handler = "GetReviewerQueue"
memory = "32MiB"
auth {
api_key = env("REVIEWER_KEY")
}
}
function "GET /reviewer/submission" {
handler = "GetReviewerSubmission"
memory = "32MiB"
auth {
api_key = env("REVIEWER_KEY")
}
}
function "GET /reviewer/mailbox" {
handler = "GetReviewerMailbox"
memory = "32MiB"
auth {
api_key = env("REVIEWER_KEY")
}
}
function "GET /reviewer/blob" {
handler = "GetReviewerBlob"
memory = "32MiB"
auth {
api_key = env("REVIEWER_KEY")
}
}
# renders the decision PDF
function "POST /decision" {
handler = "PostDecision"
memory = var.decision_memory
auth {
api_key = env("REVIEWER_KEY")
}
}
}
backend "mail" {
# sends the transactional email
function "QUEUE notify" {
handler = "QueueNotify"
memory = "32MiB"
secrets = ["RESEND_API_KEY"]
}
}
}
backbone {
nosql "submissions" {
size = "128MiB"
}
nosql "audit-log" {
size = "64MiB"
}
nosql "mailbox" {
size = "64MiB"
}
nosql "reviewers" {
size = "16MiB"
seed = "backbone/reviewers.jsonl"
}
nosql "permit-types" {
size = "16MiB"
seed = "backbone/permit-types.jsonl"
}
blobs "uploads" {
size = "512MiB"
}
queue "validate" {}
queue "notify" {
depth = 200
}
secret "RESEND_API_KEY" {
value = env("RESEND_API_KEY")
}
secret "MUNICIPALITY_NAME" {
value = env("MUNICIPALITY_NAME")
}
secret "SUBMITTER_BASE_URL" {
value = env("SUBMITTER_BASE_URL")
}
}
canvas {
site "/" {
dir = "canvas/public"
}
site "/reviewer" {
dir = "canvas/reviewer"
}
}
edge {
rate_limit = "600/min"
egress {
mode = "allowlist"
hosts = ["api.resend.com"]
}
domain "permits.example.nl" {}
}
hook "pre_deploy" {
run = "npm --prefix canvas/reviewer run build"
}
test "e2e" {
run = "npx playwright test"
}What each size is
- Memory on a Function is the slot's own pool, and what it is billed at. Eleven Functions book 480MiB between them: nine at 32MiB, the queue consumer that parses uploads at 64MiB, and the PDF renderer at 128MiB through the
decision_memoryvariable. The renderer is the one that needs room; the rest are small handlers. - Storage on a collection, database or bucket is the enforced limit and what it is billed at. Five collections hold 288MiB, from the 128MiB of
submissionsdown to the 16MiB lookup tables that are seeded from a file, and theuploadsbucket holds 512MiB. - The
limitsblock sets what belongs to the whole slice: a 30 second timeout, three days of logs, a week of backups, and a default queue depth of 500. Limits the file leaves out take the platform's figure. The slot count (eleven), the database count (none) and the scheduled jobs (none, because no Function has acron) are counted from what the file declares. rate_limit = "600/min"inedgeis the slice's requests-per-minute limit. It is the same limit aslimits.requests_per_minute, so it is written in one of the two places only.- Queues
validateandnotifyare named inqueueblocks.validateleaves outdepthand takes the slice'squeue_depthof 500;notifystates its own 200.
The three secrets and the reviewers' key are references: each is written env("NAME"), and its value comes from the terminal, from --var, or from a .env file beside the Driftfile, never from the Driftfile itself. staging is another slice from the same file, permit-intake-staging, with the PDF renderer cut to 64MiB; see Environments.
drift file resolve prints the shape the file compiles to, offline, and drift plan adds the price the platform quotes for it:
$ drift file resolve
slice permit-intake (monthly)
──────────────────────────────
functions (11)
· function POST /submit 32MiB
· function GET /permit-types 32MiB
· function GET /status/:token 32MiB
· function QUEUE validate 64MiB
· function POST /reviewer/login 32MiB (backend reviewer)
· function GET /reviewer/queue 32MiB (backend reviewer)
· function GET /reviewer/submission 32MiB (backend reviewer)
· function GET /reviewer/mailbox 32MiB (backend reviewer)
· function GET /reviewer/blob 32MiB (backend reviewer)
· function POST /decision 128MiB (backend reviewer)
· function QUEUE notify 32MiB (backend mail)
nosql (5)
· audit-log 64MiB
· mailbox 64MiB
· permit-types 16MiB
· reviewers 16MiB
· submissions 128MiB
blobs (1)
· uploads 512MiB
queues (2)
· notify 200 messages
· validate the slice's queue depth
limits
· slots 11
· limits.requests_per_minute 600
· limits.timeout 30s
· limits.log_retention 72h
· limits.backup_retention 7d
· limits.queue_depth 500
sites (2)
· / canvas/public
· /reviewer canvas/reviewer
domains (1)
· permits.example.nl
write-only values (8, read from the environment)
· function GET /reviewer/queue $REVIEWER_KEY
· function GET /reviewer/submission $REVIEWER_KEY
· function GET /reviewer/mailbox $REVIEWER_KEY
· function GET /reviewer/blob $REVIEWER_KEY
· function POST /decision $REVIEWER_KEY
· secret RESEND_API_KEY $RESEND_API_KEY
· secret MUNICIPALITY_NAME $MUNICIPALITY_NAME
· secret SUBMITTER_BASE_URL $SUBMITTER_BASE_URL
environments: staging
the price comes from the platform: drift planEvery section it uses has a page of its own: Atomic, Backbone, Canvas and Edge.