Serverless: Lambda, Go and DynamoDB#
Status: ported (#547), and serving qa and prod. Gunnar chose this direction on 2026-11-09 (#535), and the spike that had to measure it first passed. The Quarkus backend it replaced went in
559, and its infrastructure, Quarkus on Fargate behind a load balancer with PostgreSQL on RDS, in#
557. The git tag pre-serverless marks the last main before the move, for a rollback in the#
worst case; the rollback-tags ruleset keeps anyone, administrators included, from deleting or
moving it.
Why#
An environment cost about $1.86 a day while it was up on the containers
(cost.md), almost all of it billed by the hour whether anyone
used it or not: the load balancer, the Fargate task, the database instance and the task's public
IPv4 address. So environments were taken down when idle, and env.sh up and down were a daily
chore that was easy to forget: qa once ran four days unnoticed.
Serverless bills per request instead. At TaskFest's traffic, an environment that is always up costs about $1.80 a month at list price (cost.md):
| Price in eu-central-1 | At demo traffic | |
|---|---|---|
| Lambda, arm64 | $0.20 per million requests, $0.0000133334 per GB-second | inside the free tier |
| API Gateway HTTP API | $1.20 per million requests | cents |
| DynamoDB on demand | $0.7625 per million writes, $0.1525 per million reads; 25 GB free | cents |
| S3 for attachments | unchanged | cents |
| CloudFront, Route 53 | unchanged | the zone's $0.50 a month |
| CloudWatch Logs | $0.63 per GB after 5 GB free | cents |
Lambda's free tier is 1 million requests and 400,000 GB-seconds a month, account-wide, and does not expire.
No load balancer, no NAT gateway, no VPC for the backend at all, and so no public IPv4 address.
Nothing to take down, and prod can simply stay up.
The shape#
taskfest.cloud.hilling.de
│
▼
CloudFront ──── /* ──> S3 (the built SPA, unchanged)
│
└───────── /api/* ──> API Gateway ──> Lambda (Go, arm64) ──> DynamoDB
HTTP API │
└──> S3 (attachments)
- Six functions (#554, #508, #277):
apiserves every route behind the HTTP API;streamsfollows the table's stream and deletes the files of attachments that go;orphansandreplayrun on a schedule;logshipsends the logs on to the monitoring server, where an environment names one (observability.md);pushsends a change to a task to its owner's other devices (Push). The infrastructure says what each is given. - DynamoDB, one table. The partition key is the user,
USER#<sha256 of the email>; the sort key says what the item is:METAfor the user,TASK#<id>,DRAFT#<id>,ATT#<id>, andSESSION#<key>for each of the website's and the apps' sessions, so that deleting the account ends them, andDEVICE#<installation id>for each phone an app registered for push notifications (Devices). A board is oneQueryonTASK#, and a draft, which is no task yet, never matches it. Task stays the aggregate the domain model says it is. The sessions and the website's sign-ins under way have partitions of their own,SESSION#<key>andSIGNIN#<key>(Sign-in), and so does the index of each installation of the app,INSTALLATION#<installation id>(Devices). - The per-user limits (five drafts, five attachments, two per task) are kept on the user's
METAitem, changed in the same conditional transaction as the item they count. That replaces the row lock (User.lockRow). For drafts it is the open ones with their expiry, so that one TTL deletes stops counting without anything counting it down (Drafts). - The sweeps become DynamoDB TTL on drafts and detached attachments, with a stream handler that deletes their files from S3. The orphan sweep and the deletion replay run from EventBridge Scheduler.
- The API contract stays.
doc/api/openapi.jsonis what the Go code is generated from and tested against, so the website and the apps do not notice the switch.
The code#
serverless/ (opens in a new tab) is one Go module; its conventions are in
serverless/CLAUDE.md.
cmd/apiis the backend: one binary that serves API Gateway's events on Lambda and plain HTTP anywhere else, so that local development and the end-to-end tests can run the code Lambda runs.internal/lambdahttpturns one into the other.cmd/streamsdeletes the files of attachment items that go, from the table's stream, andcmd/orphansis the hourly clean-up of files no item refers to (Attachments).internal/apiholds the routes and wire types, generated fromdoc/api/openapi.json, and the handlers. Every route is ported; one test checks that every route of the contract is served, and each route's tests check its responses against the contract.internal/boardis the domain, with no AWS package in it;internal/storeis DynamoDB, andinternal/filesthe attachment bucket in S3.internal/authis sign-in, below, andinternal/gravatarthe picture fallback.cmd/pushsends a change to a task to its owner's other devices;internal/pushis what it sends and to whom, withinternal/push/apnsandinternal/push/fcmthe two push services, andinternal/notifythe API's side, which hands each change to it (Push).
Locally, against the end-to-end stack
(end-to-end-stack.md), whose
DynamoDB Local is on port 8000, SeaweedFS on 8333 and Keycloak on 8082, with the stack's own
backend stopped (docker compose -f deployment/docker/docker-compose.e2e.serverless.yml stop
backend frontend):
cd serverless
TABLE_NAME=taskfest-local DYNAMODB_ENDPOINT=http://localhost:8000 AWS_REGION=eu-central-1 \
AWS_ACCESS_KEY_ID=taskfest AWS_SECRET_ACCESS_KEY=taskfest-secret \
TASKFEST_ATTACHMENTS_BUCKET=taskfest-attachments S3_ENDPOINT=http://s3.localhost:8333 \
TASKFEST_AUTH_ENABLED=true TASKFEST_AUTH_PROVIDERS=keycloak TASKFEST_COOKIE_SECURE=false \
TASKFEST_OIDC_KEYCLOAK_ISSUER=http://localhost:8082/realms/taskfest \
TASKFEST_OIDC_KEYCLOAK_CLIENT_ID=taskfest-backend \
TASKFEST_OIDC_KEYCLOAK_CLIENT_SECRET=taskfest-secret \
TASKFEST_OIDC_KEYCLOAK_AUDIENCES=taskfest-app go run ./cmd/api
Tasks#
The board and creating, replacing and deleting a task (#550) keep every rule of the Quarkus
backend's TaskResource, and its tests are ported case for case: internal/board holds the
rules, internal/api the requests, internal/store the items.
- Ids are counted per user, by
lastTaskIdon the user'sMETAitem: an atomicADD, then aPutItemthat may not overwrite, stepping over an id a task written around the count holds. Two writes rather than one transaction, since a transaction cannot hand the counted id to its ownPut; a create failing in between leaves a gap in the ids, and nothing minds one. A deleted task's id is not given again. Quarkus's ids are unique across all users; nothing relied on that. - Replace and delete are conditional on the item existing in the caller's partition, so
another user's task, or none, is a 404 and nothing is written. A replace that leaves out both
the due time and the zone keeps them (#497) by not touching them in the
UpdateItem. - Validation is Java's, not Go's, where they differ. A description is blank as
String.isBlanksays (Hibernate Validator 9.1's@NotBlank) and measured in UTF-16 code units, as@Sizemeasures it. A time in a daylight-saving gap moves later and one in an overlap takes the earlier moment, asZonedDateTime.ofdoes; Go'stime.Dateleaves that open. - Time zones are the names in Go's tzdata, exactly as written (
zones.gen.go), but for EST, MST, HST and ROC, which the JDK does not have and refuses. Compared name for name with JDK 25.0.5 (tzdata 2026e), the one difference left is the other way round: the JDK still takes sixSystemV/zones tzdata dropped long ago, which no browser or app sends. - What follows from later stories: the function's role needs
dynamodb:GetItem,PutItem,UpdateItem,DeleteItem,Query,BatchWriteItem, which deleting an account uses, andConditionCheckItem, which IAM checks for each item of a transaction, and on the attachment buckets3:PutObject,GetObject,DeleteObjectandListBucket, without which aHEADof a missing file is a 403 rather than a 404.serverless.tfgives the API function's role exactly these (#554). - Keys are read as Jackson reads them: exactly as written, so
"Description"is no description, and of a key given twice the last one counts. - Jackson's leniencies about values are not copied. It takes a number for a string
(
"description": 5was the task "5"), an enum's position for the enum ("importance": 2wasHIGH), and a date as an array or a day count. The Go backend refuses each with a 400; no client sends one.
Drafts#
Starting, adding and discarding a draft (#551) keep the Quarkus backend's DraftResource, and
its tests are ported case for case; its files are attachments like a task's.
- A draft is a
DRAFT#<id>item with its id from the same count as tasks, so it keeps the id when it is added. Adding it is one transaction that deletes the draft and writes the task. Adding it again, a retry whose answer was lost (#427), finds no draft and sets the values on the task instead; a task that was never a draft takes them too, as in Quarkus. A start steps over an id a task written around the count holds, as a create does. Discarding a task's id is a 404, and the task stays. - The draft sweep is DynamoDB TTL on
expiresAt, an hour after the start, as long as an announced upload lasts. TTL deletes within about two days, so a draft past itsexpiresAtis gone to every read and write: adding or discarding it is a 404, and it no longer counts. - The limit of five is the open drafts on the
METAitem: anopenDraft#<id>attribute per open draft, holding its expiry, and adraftsVersionthat every change counts up. Attributes rather than one map, since removing a key from a map the item lacks is an invalid request. A start reads them, leaves out the expired ones, and writes the new set together with the draft, on the condition that the version is still the one it read. Two drafts started at once cannot both take the last place: one of the two transactions fails its condition, counts again and is refused; a test starts six at once with room for one. Adding and discarding take the draft off the set and count the version up in their own transaction, so a start that read the set before them cannot write it back. - A plain counter would not do, since TTL deleting a draft would never count it down. Neither
would counting the
DRAFT#items with aQuery: two starts at once would both count four.
Attachments#
A task's files and links (#552) keep the Quarkus backend's AttachmentResource, and its tests,
AttachmentThumbnailTest, LinkAttachmentTest and DraftTaskTest are ported case for case:
internal/board holds the rules, internal/api the requests against an in-memory store and
bucket, internal/store the items against DynamoDB Local, internal/files the signed links
against LocalStack with signature checking on. Files still travel straight between the browser
and S3, through presigned links signed for exactly the announced size and type, and the bucket is
the same one.
The Go backend keeps to serverless/ in it (#578). Both backends ran side by side until the
cut-over, each with its own database, and shared each environment's bucket, where the Quarkus
backend's files are still at the top level:
| The containers' backend | The Go backend | |
|---|---|---|
| Files | <key>, <key>.thumbnail |
serverless/attachments/<key>, and .thumbnail |
| Deletion records | deleted-accounts/<hash> |
serverless/deleted-accounts/<hash> |
Each orphan clean-up took only its own files, and each replay only its own records, which it kept
for as long as its own restores needed them: the RDS snapshots for the one, DynamoDB's restore
points for the other. The Quarkus clean-up listed the whole bucket and left out every key with a
slash, so its code needed no change. IAM keeps them apart as well: the Go functions' roles reach
objects under serverless/ only. Callers in the Go code name a file by its bare key, and
internal/files adds the prefix.
- An attachment is an
ATT#<id>item with its id fromlastAttachmentIdonMETA, the id of the task or draft it is on, and its object's key: random, and with no slash, so the orphan clean-up lists it; stored underserverless/attachments/. A thumbnail is the same key with.thumbnail. - The sweeps are DynamoDB TTL on the item's
expiresAt, set for as long as it is not kept for good, whichever ends first: an upload not confirmed an hour after it was announced, a deleted task's attachment ten minutes after the delete, the undo window, and a draft's when the draft expires. A confirmed attachment on a task has none. Past it, an attachment is gone to every read and write and no longer counts, as for drafts. Deleting a task detaches its attachments in the same transaction, and the undo'sattachmentIdsputs them back on the new task; adding a draft makes its attachments a task's, and discarding it deletes their items in its transaction. - The limits are counted from the items. A write reads
attachmentsVersiononMETA, then the task or draft, then the user'sATT#items, strongly consistent, and writes with the condition that the version is still the one it read, counting it up. Every write to attachments does so, deleting a task and adding or discarding a draft included, so two files announced at once cannot both take the last place, and none is attached to a task deleted meanwhile; tests announce six at once with room for two, and race an attach against a draft's add. The draft is read before the task: a draft becomes a task, never the other way round. - The files of a deleted item go through the table's stream.
cmd/streamstakes the stream's records, with old images, and deletes the file and thumbnail of everyATT#item that goes: removed, discarded with its draft, or deleted by TTL. A record whose files fail to go is answered as a failure; Lambda sends it and the shard's later records again, holding the shard until it succeeds, so the event source mapping caps the retries at five, and an hour's age, and lets the orphan clean-up take what is given up. Removing an attachment, and a mismatch on confirm, also delete the files at once, after the item; Quarkus deleted the file first, so that a failure in between left a row pointing at nothing rather than a file nobody could find. With the stream, neither order loses track of one. - The orphan clean-up is
cmd/orphans, which EventBridge Scheduler runs hourly. It reads every user'sATT#items with aScan, the one read across partitions, lists the bucket, and keeps every rule of Quarkus'sOrphanPlan, whose tests are ported: an object no item refers to goes after seven days; a table without a single file deletes nothing; more than two orphans older than an hour raise the alert, a JSON log line withorphanSweepAlert; an available attachment whose file is missing is logged, never deleted. Expired items still count as referring to their files, which are the stream's to delete. The alert line feeds the orphan alarm (the infrastructure). - A link to open a file is handed out again while half its hour is left, as before, per Lambda instance rather than per backend task; with several instances, a browser sees a few URLs for a file at worst. Each link ends with the credentials that signed it, when they end first, and says so in its expiry, where the credentials tell their end. On Lambda they do not: the function's credentials come in environment variables, without an expiry. A link signed shortly before they lapse can stop working before the expiry it reports, and since the browser keeps it, a preview stays broken for up to half an hour, until the next link. Gunnar accepted that (#569) rather than signing anew on every request, which undoes #236, or signing with a role assumed for the purpose, which knows its end at the price of a role and an STS call per start.
- Locally,
TASKFEST_ATTACHMENTS_BUCKETnames the bucket andS3_ENDPOINTpoints at the end-to-end stack's SeaweedFS (#556); the Go code's own tests still start LocalStack.
Sign-in#
The Go backend signs in as the Quarkus backend does (authentication.md), with the same paths, callbacks included, so the redirect URIs registered at Google and Cognito stay valid. The website signs in through the backend and gets a cookie; the apps send a bearer ID token, or the token of an app session they trade one for (#281, authentication.md). Every provider must vouch for the email, a bearer ID token must have been issued to one of the provider's named clients and be an ID token, and the provider list and the Gravatar fallback are unchanged. The function checks bearer tokens itself, not API Gateway's JWT authorizer: the cookie needs the function anyway, and one place decides for both.
Two things differ, by Gunnar's decision on #549:
- The session is stored, not carried. The cookie,
taskfest_session, holds a random value; the session is the itemSESSION#<its SHA-256>, so the table holds nothing that lets anyone in. Sign-out deletes it, so a copied cookie stops working too, which Quarkus's encryptedq_sessiondid not. No chunked cookies, no encryption key. A sign-in under way is aSIGNIN#item, with its PKCE verifier and nonce, taken and deleted in one request by the callback, so a callback works once. - It is not renewed with the provider. After a verified sign-in the session keeps the email, name and picture, and nothing of the provider's tokens. It ends after eight hours without a request, as before, and in any case seven days after signing in. There are no refresh tokens and no offline access, and nothing happens at the hour mark, where Quarkus's renewal once broke every sign-in; the price is that a withdrawn account stays signed in for up to seven days rather than an hour.
Both kinds of item carry expiresAt, the table's TTL attribute (#554), and the backend checks the
times itself as well, since TTL deletes late. A busy session
records its latest request at most every five minutes. A request with no or an ended session
gets a 401: Quarkus answered the website's scripts a 499 instead, and the frontend treats both
alike. A sign-in that fails at the callback (a second tab's, a callback used twice, one
cancelled at the provider) goes back to the app, signed out, rather than to Quarkus's blank 401.
Signing in or out also expires any q_session and q_auth cookie left from the Quarkus
backend.
Devices#
A device (#277) is a phone an app registered for push notifications with
PUT /api/devices/{installationId}, by the installation id the app generated once. Gunnar's
decision: a device lasts as long as the app session that registered it.
- The item is
DEVICE#<installation id>in the user's partition, withplatform,token,language,session, the key of its app session,created, when that session began, andexpiresAt, the session's end, so TTL takes the two together. - An installation is one device, of one account at a time. Its index,
INSTALLATION#<installation id>with the sort keyINSTALLATION, a partition of its own, names the user's partition and the session that have it, and expires with that session. Without it, a phone that signed out of one account without reaching the backend, as the app does offline, and then into another would be the device of both for up to 30 days, and get the first account's pushes. - The session names its one device, as
deviceon the session item. Registering is one transaction (store.Devices.Register): the device is written; the session is set to name it, on the condition that it lasts and still names the device it was read with; the index is set to name the two, on the condition that it is as read, and the device it named in another account is deleted; and the session's earlier device is deleted with its index, if both are still the session's. A lost race is read and tried again. - Signing out deletes the device and its index with the session (
Sessions.DeleteSession), each on the condition that it still names that session: registering the same installation id from a new session, after signing in again on the same phone, moves the device to it, and the old session's end must not take it along. The session item goes first, since deleting it is what signs out (Gunnar's decision on #695); should the device's delete fail after it, what is left gets no push (below) and expires by TTL with the session's end. - Deleting the account deletes its devices with everything else in the partition, but a
device follows its session: one of a session signed in after the deletion stays, as the
session does, and the replay does not count it as left over (
followsSessionSince). An installation's index is not in the partition, so the sweep deletes each device's just before it, on the condition that it still names the device's session, as signing out does: the privacy policy says a deletion leaves only its record. Before, so that a delete that fails leaves the device, by which the next attempt finds the index again. A later registration of the installation elsewhere finds the device it names gone and takes it over all the same. - Only an app session registers one, found by its bearer token (
auth.Service.AppSessionKey); a provider's ID token or the website's cookie is a 401, as for signing the app out. The body is read strictly: a key the contract does not name, or anything after the object, is a 400. - A device is pushed to only while its session item exists. Reading them for a push is
Devices.Registrations: one strongly consistentQueryonDEVICE#, leaving out those past theirexpiresAt, since TTL deletes late, then one strongly consistentBatchGetItemof their sessions, leaving out those whose session item is gone or has ended. A sign-out that failed after deleting the session can so leave a device behind, but never one that gets a push.
Push#
After a change to a task is written, the API hands it to the push function, which sends it to
the owner's devices but the one that made it (#277,
the decision).
- What pushes: a task added, by a create, an undone deletion, which re-creates it, or a draft
added; a task replaced, as done when its state turns to
DONE, reopened when it turns back, and changed otherwise, even when nothing visible changed; a task deleted. Drafts, attachments and deleting the account push nothing, and neither does adding a draft again, a retry whose answer was lost (#427):Writes.AddDraftOrRetrysays the draft had already become the task, which only took the values (api.DraftAdds). - What it says: the title "TaskFest", and what happened before the description, in the
language the device registered with: "Added: Buy milk", "Erledigt: Buy milk". The words are
internal/push's: Added, Changed, Done, Reopened, Deleted, and Neu, Geändert, Erledigt, Wieder offen, Gelöscht. A later push for the same task replaces one still showing:apns-collapse-idon an iPhone,collapse_keyand the notification'stagon Android, eachtask-<id>. The task's id comes along astaskId, as text, for the app to open the board with. - Which state a replace turned from costs no read: every replace is
Writes.ReplaceFrom, oneUpdateItemreturning the item as it was (ALL_OLD), andReplaceis it without the state, so that path is the same with or without a push. A delete is a transaction, which returns nothing, soWrites.DeleteTaskreads the task first, one strongly consistentGetItem, to name it: the push names the task as it was read just before the delete, so a rename landing in between is not in it. A task the read found none of, one that came about just after it, is deleted and answered as ever, but pushes nothing, since nothing names it. That read is made only where a push is sent; elsewhere a delete isDeletealone.api.ChangeWritesis what the two are to the API, and without them a replace or a delete pushes nothing rather than the wrong kind. - The API invokes
pushasynchronously (internal/notify), with Lambda'sInvokeandInvocationTypeEvent, in one attempt of at most a second, without the SDK's retries: Lambda answers 202 once the event is queued, and the request does not wait for Apple or Google, nor for seconds of retries with their back-off, since a change not pushed is only a push the fewer. The function is named by the API's settingTASKFEST_PUSH_FUNCTION; unset, as locally and in the tests, nothing is invoked. A failure to invoke is logged and never fails the change, which is made, and which a retry would make twice. - The event is the owner's partition key, never the email, the task's id, the kind (
ADDED,CHANGED,DONE,REOPENED,DELETED), the description, andexceptSession, the key of the app session that made the change: the hash of its bearer token, as the session is stored, taken without reading the session again (auth.CallersAppSessionKey), and left out for the website and an ID token. An event without an owner, a task or a known kind is logged and dropped. - What is sent is what holds when it is sent. Events are queued asynchronously, so two
changes a moment apart, done and then reopened, may arrive the other way round, and since a later
push for a task replaces the one showing, the stale one would stay. So
pushfirst reads the task, a strongly consistentGetItemin the owner's partition (store.Current), and decides by it (push.AsItIs): a task that is there is named by its description now; added, changed, done or reopened of a task gone since is not sent, nor done of one open again, nor reopened of one done again; deleted is sent, with the event's description, only while the task is gone, not after an undo brought it back. What is not sent is logged with why. - The devices are
Devices.Registrations: those whose session lasts (Devices), each with its session's key, so that the one whose session isexceptSessionis left out. The rest are sent to in parallel, eight at a time. Just before each send, the installation's index is read again, strongly consistent (Devices.StillRegistered), and a device whose index no longer names the owner and the session it was read with, signed out or signed in to another account meanwhile, is skipped and logged. OneGetItemper device; it narrows the window to the send itself, and cannot close it. - iPhones through APNs, its production host only, over HTTP/2:
POST /3/device/<token>, an alert with the default sound,apns-push-typealert,apns-priority10 andapns-topicthe environment's bundle id. It is authorized by a provider token, a JWT signed ES256 with the environment's.p8key, naming the key (kid) and the team (iss), signed again after 50 minutes, since Apple refuses one older than an hour and throttles one signed for every push, and at once after a 403. - Android through FCM's HTTP v1 API,
POST /v1/projects/<project>/messages:send, with a Google access token that needs no key: Workload Identity Federation trades the function's own AWS credentials, those of its role, for a token of the pool's provider that trusts it, and that for one of the service account that may send, by impersonation (x/oauth2'sexternalaccount). The token is kept for its hour. - A token its service no longer knows forgets the device: APNs' 410, or 400
BadDeviceToken; FCM'sUNREGISTERED, orINVALID_ARGUMENTnaming the message's token. AnINVALID_ARGUMENTthat names no field, or another, stays an ordinary failure: it may be about the backend's own message, and forgetting every device over a fault of ours would be worse than a push that fails.Devices.Forgetdeletes the device and its installation's index in one transaction, only while the device still has that token and session, so one that registered a new token meanwhile stays. The app registers its next token at its next start. A sandbox token, from a build run from Xcode, isBadDeviceTokenat the production host and so forgotten too: such builds get no push, by the decision. - Failures and Lambda's retries. Lambda tries an asynchronous event that fails twice more. A retry sends to every device again, and a device that had the push would show it again, so the function fails only when a retry can send nothing twice: when the task or the devices could not be read, or when sending failed for some devices and reached none. A failure where another device got the push is logged and not tried again. A platform without its settings is skipped and logged.
- What it logs: per device, its installation id, platform and outcome (sent, gone, failed with the service's status and reason), per change, the task's id, the kind and the counts, and a change not sent, with why. Never the description, and never a push token: an APNs error drops the URL, which holds the token.
- The function's settings:
TABLE_NAME; for APNs, all four or none,TASKFEST_APNS_KEY_SECRET_ARN, the Secrets Manager secret with the.p8key, whichinternal/secretsreads at a cold start,TASKFEST_APNS_KEY_ID,TASKFEST_APNS_TEAM_IDandTASKFEST_APNS_TOPIC; for FCM, all three or none,TASKFEST_FCM_PROJECT_ID,TASKFEST_GOOGLE_WIF_AUDIENCE, the pool's provider (//iam.googleapis.com/projects/<n>/locations/global/workloadIdentityPools/<pool>/providers/<p>), andTASKFEST_GOOGLE_SERVICE_ACCOUNT, the service account's email. A platform with only some of its settings fails the start rather than being skipped without a word. - Its infrastructure is
push.tfand one of the jobs inserverless-jobs.tf, below (The infrastructure). The function exists in both environments, so the deploy always finds it, but sends nothing untilpush_notifications.ios_offeredorandroid_offered, each platform's switch: until then it has no platform's settings, and the API has noTASKFEST_PUSH_FUNCTIONand invokes nothing. What Apple and Google need is made by hand, per environment, and so is switching off (names-and-certificates.md).
Deleting an account#
DELETE /api/account (#553) keeps the
decision
and the Quarkus backend's tests: the record serverless/deleted-accounts/<SHA-256 of the email>
is written to the attachment bucket first, where a restore of the table cannot take it back, and
without a bucket an account is deleted without one. Two things differ, by Gunnar's decisions on
553:#
- The account is marked, then deleted in batches. A transaction holds at most 100 items, and a
user's tasks have no limit, so no single write deletes an account. The first write sets
deletedAtonMETA; then every item of the partition goes, 25 to aBatchWriteItem, andMETAlast. A deletion that cannot be marked takes its record back and answers a 500, as before. One that stops after the mark counts as done: the user is told so, and the account's next request finishes it before anything else (api.Settled, one strongly consistent read ofMETAper request,/api/auth/meincluded), or the replay does. A request is refused, with a 401, when that read fails or the deletion cannot be finished: it must never see what is left of a deleted account. The partition is read again until nothing is left, for what a request racing the deletion wrote, and once more afterMETAis gone, under a markedMETAwritten on the condition that there is none, so an account begun anew in that moment stays. Should that last read fail, nothing in the table is marked any more; the record in the bucket is, and the replay deletes what is left under a recorded account that has noMETA. The stream deletes the attachments' files as their items go. - It ends the account's sessions on every device. Each sign-in also writes a
SESSION#<key>item into the user's partition, which deleting the account deletes along with the session it names; the item expires with the session's seven days, or an app session's 30. Quarkus's sessions were encrypted cookies, so a session left open elsewhere began a new, empty account; now it is signed out, an app with an app session (#281) included. An app that sends a bearer ID token with every request has nothing a deletion can end: its next request uses a new, empty account, as before.
One gap is accepted, as in the Quarkus backend (Gunnar's decision on #572): two deletions of the same account at the same moment share one record, and if one of them cannot be marked, taking its record back also takes the other's. It needs both at once, a DynamoDB failure on exactly one, and a later restore; closing it would take a conditional delete in S3 or a lock on the account.
The replay#
cmd/replay deletes again any account a restore brought back, and prunes the records no restore
can need any more; internal/replay keeps every rule of Quarkus's DeletionReplay, whose tests
are ported. EventBridge Scheduler runs it daily, at 03:30 Berlin time. Lambda has no start-up to
run it in, so the restore procedure below runs it once against the restored table before the
API is switched to it, and nobody can sign in to a restored account first (Gunnar's decision on
553).#
- An account is deleted again only if it began before its deletion.
METAcarriescreatedAt, written with the first id the account counts and kept from then on; the write that marks the account deleted again is conditional on it, so an account begun anew since is never taken for the restored one. Times are whole seconds, and an account begun in the second of its deletion counts as before it: the deletion the user asked for wins (Gunnar's decision on #573). An account withoutcreatedAtcounts as older; there is none, as the table starts empty and no user moves over from the Quarkus backend (#557). The Quarkus backend's records, underdeleted-accounts/, are its own replay's and never this one's (#578): no account they name was ever in this table. - What a deletion left without
METAis deleted too, for the deletion that stopped afterMETAwent: no task, draft or attachment is ever written withoutMETA. A markedMETAis written first, on the condition that there is none, so a sign-up at that moment either keeps its account or finds it marked and has it settled like any deletion left half-way. A session signed in after the deletion stays; each link carries when its session began. Finishing a deletion left half-way spares such a session as well, so signing in again in between does not sign out. - The replay deletes the attachments' files itself, file and thumbnail, after their items: a restored table has no stream until the API is switched to it, and the orphan clean-up holds while the table has no file at all (Gunnar's decision on #573). What fails is left to the clean-up.
- Each record is handled on its own, and a run in which an account could not be deleted again fails, to be retried by the next. A record younger than five minutes is left to the request that wrote it, which may yet take it back and tell the user the deletion failed.
- A record is pruned once it is older than the oldest point the table could be restored to, by two days, unless its account is still there, and not if it was written again since it was read; that check and the delete are two requests, and a second deletion of the same address between them loses its record, a gap accepted like the one above (#573). The two days cover a deletion finished a day after its record, by the next daily run. That point is the start of any table's point-in-time recovery window in the region, or the oldest backup there, whichever is older: every table and backup counts, not only the table's, since a restore goes into a new table and the one it came from stays restorable until it is deleted, and a record kept too long costs nothing. When neither exists, or DynamoDB will not say, nothing is pruned. Point-in-time recovery is on for prod and off for qa (#553).
- Its role has
dynamodb:Query,GetItem,PutItem,UpdateItem,DeleteItemandBatchWriteItemon the table,DescribeContinuousBackupson every table,ListTablesandListBackups, and on the buckets3:ListBucket,GetObjectunderserverless/deleted-accounts/, andDeleteObjectthere and underserverless/attachments/(serverless-jobs.tf).
Restoring the table#
A DynamoDB restore always creates a new table; the old one stays until it is deleted. What was written between the restore point and the switch is lost, as with the database's snapshot restores (database.md), and files uploaded since are left to the orphan clean-up. A restore is billed by the size restored, cents for TaskFest. Every step runs as the administrator, with its profile.
- Restore into a new table, from point-in-time recovery (prod) or a backup:
aws dynamodb restore-table-to-point-in-time --source-table-name <table> \ --target-table-name <table>-restored-<date> --restore-date-time <time> aws dynamodb restore-table-from-backup --backup-arn <arn> \ --target-table-name <table>-restored-<date> aws dynamodb wait table-exists --table-name <table>-restored-<date> - Run the replay against it, before anything else can reach it. It asks for the MFA code
itself when the profile needs one, each time it runs, since it keeps no session the way the AWS
CLI does:
It logs one JSON line,(cd serverless && AWS_PROFILE=<admin profile> AWS_REGION=eu-central-1 \ TABLE_NAME=<table>-restored-<date> TASKFEST_ATTACHMENTS_BUCKET=<bucket> go run ./cmd/replay)deletion-replay, with how many accounts it deleted again; it exits non-zero when one could not be, and is then run again. - Switch the functions to the new table, as the administrator, in the environment's root.
OpenTofu forgets the old table, which stays, protected from deletion, until it is deleted by
hand;
table_nameinterraform.tfvarsnames the restored one; OpenTofu takes it over; deletion protection, which a restore does not carry over either, is set by hand on its own first; and the apply sets the rest a restore leaves out, TTL, the stream and point-in-time recovery, and points the functions, their roles and the stream's mapping at it:
and thentofu state rm module.environment.aws_dynamodb_table.data # table_name = "<table>-restored-<date>" in terraform.tfvars tofu import module.environment.aws_dynamodb_table.data <table>-restored-<date> # Deletion protection first, alone. The apply would send it together with the stream, and # DynamoDB refuses that: "DeletionProtection modification must be the only operation in the # request" -- the apply then fails half done, as in the trial on #553. aws dynamodb update-table --profile <admin profile> --region eu-central-1 \ --table-name <table>-restored-<date> --deletion-protection-enabled aws dynamodb wait table-exists --profile <admin profile> --region eu-central-1 \ --table-name <table>-restored-<date> # Must print true before the apply; the waiter alone can return before the change shows. aws dynamodb describe-table --profile <admin profile> --region eu-central-1 \ --table-name <table>-restored-<date> --query Table.DeletionProtectionEnabledenv.sh up <env>, naming the administrator's profile for it, asTASKFEST_<ENV>_AWS_PROFILE=<admin profile>(infrastructure.md). The change oftable_namereachesmainjust before, in a pull request; until this step has run, an apply ofmainwould try to replace the old table and fail on its deletion protection. - Redeploy the release that runs, with
deploy-serverless.ymland its tag: the apply changed the functions' settings, which reach what serves only as a newly published version (#555, Deploying a release). Until then the API serves server errors for whatever needs the table: the apply has given its role the restored table, while the version that serves still names the old one. So this follows the apply at once; should it fail, the API stays down until it is run again, or untiltable_nameis set back and applied. - Run the replay again, now against the switched table, at least five minutes after the switch. The run in step 2 passed over the deletions of its last five minutes, which may still have been under way, and deletions kept being recorded until the switch; this run takes both. Until it has run, an account deleted in those minutes is back. Deletions are not stopped during a restore, which would take the API down for its length; the window is minutes, and only for accounts whose owners have just deleted them (Claude's decision on #554, which Gunnar confirmed on 2026-11-12).
Tried in qa on 2026-11-13 (#553), from an on-demand backup of taskfest-qa-data into
taskfest-qa-data-restored-2026-11-13, which qa has used since. An account was deleted after the
backup: it came back with the restore, the replay in step 2 deleted it again (reapplied: 1), the
one in step 5 found nothing more (reapplied: 0), and signing in afterwards began a new, empty
account. The restore took about five minutes. Two steps were found missing and are written in
above: exporting the CLI's credentials for the replay in step 2, and the deletion protection set on
its own before the apply in step 3, which had failed half done without it; set by hand, the apply
went through. The old table and its backup stay until deleted by hand.
Why Go#
Measured cold starts of a real request after a pause, from published benchmarks:
| Cold start | |
|---|---|
| Quarkus on the JVM | 3.3 s |
| Quarkus with SnapStart and priming | 0.6 to 1.0 s |
| Quarkus native | 0.56 to 0.72 s |
| Go | about 0.46 s for a real app (2021, at 128 MB); a bare start 45 ms today |
| Rust | about 0.12 s; a bare start 17 ms |
Warm requests take about 5 ms in all of them. A demo is idle most of the time, so most visits start cold, and the cold start is what users notice. Go starts fast, compiles to one static binary for arm64, and its AWS SDK is first-class. Rust starts faster still, but not by an amount anyone would notice, at a far higher cost in writing it.
What speaks against it#
- It ties the backend to AWS. The handlers speak Lambda's event format, the data model is shaped by DynamoDB's access patterns, and sign-in, scheduling and clean-up lean on API Gateway, EventBridge and DynamoDB streams. Moving to another cloud would be a rewrite of the backend, where the container architecture moves almost as it is: a container, PostgreSQL and a load balancer exist everywhere. The domain logic is kept behind plain Go interfaces, so that the part worth keeping does not import an AWS package.
- Go is new to the project, and Gunnar does not mean to learn it. Claude writes and
maintains the Go code; Gunnar reviews behaviour, not idiom. That makes the tests, the
contract checks against
openapi.json,/code-reviewand CodeRabbit carry more of the review than they do for the Java backend. - Cold starts. Rare for a busy service, normal for a demo: see above.
- DynamoDB is not relational. Every access pattern is designed up front, a new query can mean a new index, and there are no ad-hoc SQL queries for support.
- The blue/green demonstration goes. ECS shifts traffic between two target groups; Lambda's equivalent is a weighted alias, which is simpler and shows less.
- Local development changes. LocalStack Community, which the end-to-end stack uses, was archived in March 2026. Amazon's own DynamoDB Local replaces it for the database.
- The website's sign-in is the hardest part. Quarkus keeps the website's session in an
encrypted cookie (
q_session) after an authorization-code flow; the apps send a bearer ID token. Go has to rebuild the first, or the website moves to signing in the browser. Decided during the port, not by the spike.
The spike first#
Before anything is ported, one endpoint, GET /api/tasks, is built in Go and run in qa beside
the current backend, to measure the cold start in Frankfurt rather than trust benchmarks:
- One Lambda function on
provided.al2023, arm64, and one DynamoDB table, created only whereserverless_spikeis true (qa). - No API Gateway and no sign-in yet: the function is invoked directly with the event API Gateway would send, including the claims its JWT authorizer would pass on.
- It succeeds if a cold invocation, initialisation included, takes under 500 ms at 256 MB, and a warm one under 50 ms. It fails if not, and Quarkus with SnapStart is then the fallback, in the language Gunnar knows. It passed at 512 MB instead (below).
- It costs nothing measurable: about a hundred invocations and a table of twenty items.
The spike's function and table, and serverless/spike/measure.sh, which uploaded the code, wrote
twenty tasks for the test account taskfest-test-one@example.com and printed Lambda's own
initialisation, cold and warm times, were removed with #554, which replaced them with
the infrastructure. They are in the git history before it.
What the spike measured#
Run on 2026-11-10 in qa: five forced cold starts per memory size, each followed by three warm calls, all reading the board of twenty tasks. Times in milliseconds, from Lambda's REPORT lines.
| Memory | Initialisation | First call | Cold, together | Warm | Memory used |
|---|---|---|---|---|---|
| 128 MB | 58–70 | 1015–1159 | about 1100 | 3–5, two at 50 | 34 MB |
| 256 MB | 57–70 | 432–545 | 490–615 | 3–5 | 35 MB |
| 512 MB | 58–72 | 180–265 | 240–340 | 3–5 | 38 MB |
- The function runs at 512 MB. It passes there; at 256 MB it missed the 500 ms in four rounds of five. Lambda bills by memory and time, so 512 MB costs twice as much per millisecond, which at a demo's traffic is still inside the free tier.
- Initialisation is flat, the first call is not. The first call halves each time the memory doubles, and Lambda gives CPU in proportion to memory, so it waits on CPU: most likely the DNS lookup and TLS handshake of the first DynamoDB request. Not measured separately; opening that connection during initialisation is the first thing to try in the port.
- Warm calls take 3 to 5 ms, and the function never used more than 40 MB.
That is ten times faster than the JVM on Lambda without SnapStart, and faster than Quarkus with it, so the port goes ahead in Go, at 512 MB.
With the connection opened during initialisation#
Run again on 2026-11-10 with the foundation (#548): cmd/api, which queries DynamoDB once while
it initialises (Store.Prime).
| Memory | Initialisation | First call | Cold, together | Warm | Memory used |
|---|---|---|---|---|---|
| 256 MB | 115–148 | 4–45 | 120–190 | 3–5, one at 16 | 34 MB |
| 512 MB | 120–142 | 4–5 | 125–146 | 3–8 | 39 MB |
- The guess was right. Initialisation grew by about 70 ms and stayed the same at both sizes, and the first call dropped from hundreds of milliseconds to a warm call's few. Lambda's initialisation is evidently not held to the CPU share of the memory size, so work moved there gets done faster.
- A cold request now takes under 200 ms even at 256 MB, well inside the 500 ms gate. The function stays at 512 MB: the routes still to come do work no priming covers, such as fetching a sign-in provider's keys, and at TaskFest's traffic the difference costs nothing.
The infrastructure#
serverless.tf and serverless-jobs.tf in deployment/aws-tofu/modules/environment/ (#554), in
both environments alike. The functions, the API and the table bill per request; what is fixed is in
cost.md, the alarms most of it.
- The table,
<project>-<env>-data, on demand. TTL onexpiresAtdeletes ended sessions, sign-ins under way, session links and devices; the stream carries what a deleted item held, for thestreamsfunction; point-in-time recovery is on in prod, for restoring, at fractions of a cent a GB-month, and off in qa (table_point_in_time_recovery, #553); and deletion protection keeps a destroy from taking people's data with it. - The
apifunction, arm64, 512 MB (measured), with a timeout of 28 seconds, under the HTTP API's own 30. Its role reaches its own table, its part of the attachment bucket, the sign-in secrets, its log group and, once push is offered, thepushfunction's alias, nothing else. - The HTTP API sends every request to it. Its address is public, so CloudFront adds a header
with a secret,
X-Origin-Verify, and the function refuses any request without it with a 403 (lambdahttp.FromOrigin); OpenTofu generates the secret. A Secrets Manager secret would cost $0.40 a month to prove only where a request came from, so it is in state and in the function's settings instead. The stage is throttled at 10 requests a second, bursts of 20, as a ceiling on what a flood could cost: about $30 a month of requests at the most (#607; it was 50 and 100). It is one bucket for everyone, not per user: a script at the ceiling slows every visitor down. An alarm mails when an hour holds 20,000 requests, well below the 36,000 the ceiling lets through, so a script below it is seen within the hour rather than a day later by a budget. The website and the app send their own bursts, a cleared or restored board, four at a time, inside the burst of 20. - CloudFront sends
/api/*to the HTTP API, without the viewer'sHost, which API Gateway would refuse: the function takes its own address fromTASKFEST_PUBLIC_ORIGIN. qa went first, on 2026-11-12, and prod followed with its cut-over (#557); the variableapi_backendthat switched between the two backends went with the containers' infrastructure (#557). - Sign-in is configured as for the containers before: on only where Google's client id is set,
and the test accounts beside Google where they exist. Google's client secret stays out of
OpenTofu: the function's setting
TASKFEST_OIDC_GOOGLE_CLIENT_SECRET_ARNnames the secret, and the function reads it once at a cold start (internal/secrets). The test accounts' secret is in state already (D4 on #141).
The background functions are in serverless-jobs.tf, each with a role for exactly what it
does:
streamsgets the table's stream, filtered to the removals ofATT#items, so no other write invokes it, with at most five retries and records at most an hour old.orphansruns hourly andreplaydaily at 03:30 Berlin time, on EventBridge Scheduler, which is free at two schedules. A failed run is not tried again; the next run does the same work.- They touch only
serverless/in the bucket. Before that prefix (#578),orphanscalled qa's six container files orphans on its first run and raised the alarm, andreplaywould have pruned the containers' deletion records, so #577 had switched both off for a day. - The Go orphan clean-up's alert line feeds the orphan alarm's metric through a metric filter.
push(#277,push.tf) is invoked by the API alone, asynchronously, on its aliaslive, and given 60 seconds: each request to APNs, FCM or Google's token exchange is bounded at ten, and eight devices are sent to at a time. Its role reads the table (GetItem,Query,BatchGetItem) and deletes a device its push service no longer knows (DeleteItem, which authorises the transaction's deletes), reads the APNs keytaskfest-<env>-apns-keyonce its key id is given, and writes its log, which goes to the monitoring server with the others. FCM needs no AWS permission: Google's STS checks the role's own signedGetCallerIdentity. Its settings come frompush_notifications: per platform, only onceios_offeredorandroid_offered, and the APNs key's read only with iPhones, so a key not yet in can never stop Android; either flag gives the API's rolelambda:InvokeFunctionon the alias and setsTASKFEST_PUSH_FUNCTIONto its ARN. Lambda tries an event that fails twice more, its default, but drops one older than five minutes, not the default six hours: a push is news only while the change is, and a phone told hours late that a task was added is worse than told nothing. Its errors have an alarm,push-errors, and its runs and errors are on the dashboard.
The alarms, each $0.10 a month, mail through the existing topic on entering ALARM and on leaving
it: the API function's errors and throttles, the HTTP API's server errors, at least five in one
five-minute period (#558, Gunnar's threshold), the HTTP API's request count, at least 20,000 in an
hour (#607), the stream function more than ten minutes behind (it reports a failed record rather
than failing, so its errors would never show one), the scheduled functions' errors, push's
errors (#277), and the table's throttled reads and writes. That is ten per environment, and the
orphan alarm the eleventh.
The dashboard taskfest-<env>-go-backend (#558, serverless-dashboard.tf) shows the requests
and their answers, the time they take, the API function's time, errors and throttles, the jobs'
runs and errors, how far the stream function is behind, and the table's reads, writes and throttles.
It is free: CloudWatch includes three dashboards per account, and these are the second and third.
The functions are created from serverless/dist/<command>.zip, which serverless/build.sh makes,
with Go where it is installed and the official Go image through podman or docker where it is not.
OpenTofu uploads the code only when it creates a function; a release deploys its own (#555).
Applying it needs the administrator (infrastructure.md). From the
repository root on main:
serverless/build.sh
(cd deployment/aws-tofu && TASKFEST_QA_AWS_PROFILE=<admin profile> ./env.sh up qa)
The plan it shows says what will change before anything happens.
Deploying a release#
A release deploys the code (#555), as it deploys the site:
release.ymlbuilds the six functions once, from the tag, with the versionGET /api/versionreports, and attaches them to the release astaskfest-serverless-<version>-<function>.zip.deploy-serverless.ymldeploys them, to qa after every final release, and to prod by hand through its protected environment, as the containers were.deploy-serverless.pyuploads each function's zip, publishes it as a version described by the release, and moves the function's aliasliveto it. API Gateway, the stream and the schedules invokelive, never the unpublished code, so nothing serves a version before its alias moves.- The API's new version is checked first. It is invoked with a request as API Gateway sends one, without CloudFront's header, which it must refuse with a 403: it has started, read its settings and secrets, and handled a request. It does not prove the table is reached -- the function starts even when its first read of the table fails, so that a moment's trouble does not fail a cold start. A release that cannot reach it answers 500s, which the server-error alarm reports only at five in one five-minute period: at TaskFest's traffic it may stay quiet, so after a deploy the dashboard's answers are the place to look. Anything else stops the deploy with every alias where it was. The jobs are not invoked, since a run does real work; a failing one raises its alarm.
- A failure after an alias has moved tries to move every alias back, each on its own, so the
functions do not stay on different releases. The aliases move one after another, so for the
seconds of a deploy they do anyway; and should moving one back fail too, the log names it, and
aws lambda update-alias --function-name <name> --name live --function-version <version>, with the administrator, puts it where the log says it was. A rollback isdeploy-serverless.ymlwith the previous release's tag. - The deploy role may upload, publish, invoke and move the aliases of these six functions, and
nothing else of them: no setting, no permission. A release from before a function existed,
logshipafter v1.6.1 andpushafter v1.8.4, leaves it where it is, so a rollback to one still deploys; any later release must have it. Sopush's apply, which creates it and lets the deploy role reach it, comes in both environments before the first release with it is deployed, or that deploy fails before it moves any alias. - A change of the functions' settings by OpenTofu reaches what serves only through a deploy. A
published version keeps the settings it was published with, and the aliases name versions, so an
apply changes the unpublished code's settings alone. After an apply that changes them -- a
restored table, the origin secret, sign-in -- run
deploy-serverless.ymlwith the release that runs; it publishes them with the same code.
A traffic-weighted canary was decided against (#555, the decision).
A function created by OpenTofu starts with what build.sh made, and its alias on that
unpublished code. The first deploy pins the alias on a published version of it before uploading
anything, so the upload does not serve the new code before its check. Code that changes what the
functions may touch goes out with the release after the apply that changes their roles, or by hand
before it, with the administrator, as #578's did:
for env in qa prod; do
for c in api streams orphans replay logship push; do
AWS_PROFILE=<admin profile> aws lambda update-function-code --region eu-central-1 \
--function-name "taskfest-$env-$c" --zip-file "fileb://serverless/dist/$c.zip" >/dev/null
done
done
Once a release's deploy has pinned the aliases on published versions, code uploaded so changes the unpublished code only, and the aliases keep their version until a deploy moves them. Before the first deploy, the aliases are still on the unpublished code, as OpenTofu creates them, and an upload serves at once, unchecked.