Chord's entire backend runs on Go AWS Lambda functions sitting behind API Gateway. No servers to patch. No cluster idling at 3 a.m. waiting for a podcaster in another timezone to hit record. From day one we had a small team and one rule: don't pay for compute nobody is using.
This post is the honest version of how that went. Why Lambda and API Gateway made sense for an early-stage product. Why Go is a great fit for it. The limits that bit us, like timeouts and shipping ffmpeg inside a function. And how we deal with cold starts without throwing money at them.
TL;DR
- Pay-per-request compute is a superpower at the early stage. Your bill tracks your usage, so low traffic means a low bill.
-
Go is one of the best languages for Lambda. You ship a single static binary on
provided.al2023, init is fast, and memory use is small. - Design around the timeouts from day one. API Gateway HTTP APIs give you 30 seconds, and it's a hard limit. Anything longer becomes an async job.
- ffmpeg fits in a Lambda layer, but heavy encoding doesn't belong in Lambda. We use layers for light media work and Fargate for full video encodes.
- Fix cold starts cheaply first. A tiny warmup path in the handler goes a long way. Provisioned concurrency is for the few routes where latency really matters.
What Chord is, and why cost mattered so much
Chord is a browser-based studio for recording, editing and repurposing audio and video. You send guests a link, everyone joins from the browser, and each participant is recorded locally on their own machine. Those local tracks upload in the background, so a shaky Wi-Fi connection doesn't ruin the final file. After the session you edit in the browser, clean up audio with an Enhance speech workflow, and turn the conversation into clips and show notes.
If you've used Riverside, the recording model will feel familiar. We wrote an honest Riverside vs Chord comparison if you want to see where the two differ.
Under the hood that's a lot of moving parts. Session management, auth, uploads of large media files, transcription, AI workflows, rendering and exports. A classic setup would be a few always-on servers plus a job queue plus workers.
That setup didn't fit us. Traffic for a recording product is spiky by nature. A session runs for an hour, then nothing for a while. Paying for servers sized for the peak, around the clock, made no sense. We wanted infrastructure that costs close to nothing when nobody is recording. That pointed straight at a serverless backend.
Why Lambda and API Gateway work for an early-stage product
The pitch for Lambda is simple. You pay per request and per millisecond of compute, and nothing when idle. The Lambda pricing page has the exact numbers, and the free tier alone covers a surprising amount of early traffic.
API Gateway is the other half. It gives every function a public HTTPS endpoint and takes care of the boring but important parts: auth, throttling, CORS and custom domains. At Chord we use HTTP APIs, the simpler and cheaper flavor of API Gateway, with a Cognito JWT authorizer on every route. An unauthenticated request never reaches our code, and never costs us a Lambda invocation.
Here's how the trade-off looked for us:
| Concern | Always-on servers | Lambda + API Gateway |
|---|---|---|
| Cost at low traffic | You pay for peak capacity 24/7 | You pay per request, close to zero when idle |
| Scaling | Autoscaling groups, load balancers, tuning | Handled per function by AWS |
| Auth at the edge | Middleware in your app | Cognito authorizer before your code runs |
| Patching and OS updates | Your job | AWS's job |
| Long-running work | Fine | Hard limits, needs a different design |
| Cold starts | Not a thing | Real, and now billed |
That last row matters more than it used to. Since August 2025, AWS bills the INIT phase for ZIP-packaged functions on managed runtimes too. Custom runtimes, which is what Go uses, were already billed for init. Either way, a fast init is now a cost question, not only a latency one. That's one more reason we like Go here.
π Note: Lambda isn't free at scale. Past a certain steady load, containers or VMs win on price. For a product finding its market with spiky traffic, that break-even point is a long way off.
Why Go is a great fit for Lambda
Go compiles to one static binary. There's no interpreter to boot and no dependency tree to load at startup. On Lambda that turns into fast init times and low memory use, so most of our functions run comfortably at small memory sizes.
One thing that trips people up: there's no managed Go runtime anymore. The old go1.x runtime is deprecated, and AWS's Go guide points you to the OS-only provided.al2023 runtime. You build a Linux binary called bootstrap, zip it, and that's your function.
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
go build -tags lambda.norpc -o bootstrap ./cmd/sessions
zip sessions.zip bootstrap
A few details worth knowing:
-
Build for
arm64. Graviton functions are cheaper per GB-second than x86, and Go cross-compiles to ARM with zero effort. -
Use the
lambda.norpctag. It drops RPC code only the old runtime needed, which shrinks the binary. - Set up clients once, outside the handler. Anything you create at package level survives between warm invocations.
That last point is the single biggest performance habit in our codebase:
package main
import (
"context"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
)
// Created once per execution environment, reused on every warm invoke.
var db *dynamodb.Client
func init() {
cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
panic(err)
}
db = dynamodb.NewFromConfig(cfg)
}
func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
// db is already connected here. No per-request setup cost.
return events.APIGatewayV2HTTPResponse{StatusCode: 200, Body: `{"ok":true}`}, nil
}
func main() {
lambda.Start(handler)
}
π‘ Keep
init()lean, though. Since init time is billed, loading config and creating SDK clients is fine. Warming caches or calling other services at startup is not.
The Lambda patterns we use at Chord
The request path is short. The browser talks to API Gateway, Cognito checks the token, a Go function does the work against DynamoDB and S3. Anything slow gets pushed off the request path into background workers.
One function per domain, not per route
We don't run one giant "Lambdalith", and we don't deploy a function per endpoint either. Each function owns a domain, like sessions, recordings or tools, and routes internally. That keeps the number of deploy units manageable while still letting each domain have its own memory size, timeout and IAM permissions.
Each service lives in its own repo with a cmd/ folder per function and shared internal/ packages for auth, logging and data access. Every cmd/<name> builds to its own bootstrap.
Never send media through the API
Large files go straight from the browser to S3 with presigned URLs. The Lambda only signs the request. This dodges two limits at once: the 6 MB synchronous payload cap from the Lambda quotas, and the API Gateway timeout. It also means we never pay Lambda time to shovel bytes around.
Async jobs with an ID
Anything that can take more than a few seconds becomes a job. The API creates a job record in DynamoDB, returns 202 with a jobId, and a worker picks it up. The client checks the job status. More on why in the next section.
Lambda timeouts, payload limits and other intricacies
Lambda's limits are generous until they aren't. These are the ones we designed around, from the Lambda quotas and the HTTP API quotas:
| Limit | Value | What it means in practice |
|---|---|---|
| Lambda max duration | 15 minutes | Fine for most jobs, not for long video encodes |
| API Gateway integration timeout | 30 seconds on HTTP APIs, fixed | Your sync endpoints must answer fast |
| Sync request and response payload | 6 MB each | Media never goes through the API |
| Async invoke payload | 1 MB | Pass S3 keys and IDs, not data |
| Deployment package, incl. layers | 250 MB unzipped | Big binaries like ffmpeg need care |
| Layers per function | 5 | Keep layers few and focused |
/tmp storage |
512 MB to 10 GB | Configure it for media work |
The timeout mismatch nobody warns you about
The Lambda timeout and the API Gateway timeout are separate settings. If API Gateway gives up at 30 seconds but your function is allowed 60, the client gets a 504 and your function keeps running, and billing, for nothing. For every function behind a synchronous route, we set the Lambda timeout just under the gateway's.
This is one of the trade-offs of HTTP APIs. REST APIs can raise the integration timeout past 29 seconds, but only for Regional and private APIs, through a quota request. On HTTP APIs, 30 seconds is the ceiling. We're fine with that. It pushes you toward the right design anyway.
Make slow work asynchronous
The cleaner fix is the job pattern from the previous section:
-
The API validates and enqueues. It writes a job to DynamoDB and returns
202with ajobIdin milliseconds. - A worker does the real work. It's triggered by an S3 event, a queue or an async invoke, and it gets the full 15 minutes.
- The client follows the job. It checks status until the output is ready in S3.
This also makes retries safer, because the job record tells you what already happened.
β‘ In short: sync routes answer in seconds, everything else is a job. Pass references (S3 keys, job IDs), never payloads.
One newer option worth knowing: since late 2025, API Gateway REST APIs support response streaming from Lambda, with request timeouts up to 15 minutes. HTTP APIs don't. If you need to stream something like AI output to the browser, that's the point where a REST API starts to earn its extra complexity.
Shipping ffmpeg with Lambda layers
A media product without ffmpeg is hard to imagine. Probing files, extracting audio, generating thumbnails and waveforms, small transcodes. Putting a static ffmpeg build in a Lambda layer lets every media function share one copy instead of bundling it into each zip.
How the layer is built
Layer contents get extracted to /opt at runtime, and /opt/bin is on the PATH. So the layer zip is just:
ffmpeg-layer.zip
βββ bin/
βββ ffmpeg
βββ ffprobe
And in Terraform:
resource "aws_lambda_layer_version" "ffmpeg" {
layer_name = "ffmpeg"
filename = "build/ffmpeg-layer.zip"
source_code_hash = filebase64sha256("build/ffmpeg-layer.zip")
compatible_runtimes = ["provided.al2023"]
compatible_architectures = ["arm64"]
}
The gotchas
-
Match the architecture. An x86 ffmpeg build in an
arm64function fails with a crypticexec format error. Build or download the static binary for the same architecture as the function. - Watch the 250 MB budget. ffmpeg plus ffprobe eats a big chunk of the unzipped limit, and that budget is shared with your function code and every other layer.
-
Give it disk. Media work needs scratch space, so we raise
/tmpstorage on media functions and clean it up at the end of each invocation. Warm environments keep/tmpbetween runs. - More memory means more CPU. Lambda scales CPU with memory, so ffmpeg functions get much more memory than our API functions, even if they don't need the RAM.
- Respect the deadline. Don't let ffmpeg run until Lambda kills it. Derive a deadline from the context and leave yourself time to clean up and mark the job as failed.
func runFFmpeg(ctx context.Context, args ...string) error {
// Stop ffmpeg 10s before Lambda's hard timeout so we can report the failure.
if dl, ok := ctx.Deadline(); ok {
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, dl.Add(-10*time.Second))
defer cancel()
}
cmd := exec.CommandContext(ctx, "/opt/bin/ffmpeg", args...)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("ffmpeg: %w: %s", err, stderr.String())
}
return nil
}
π Note: if you outgrow the 250 MB limit, Lambda container images go up to 10 GB. We stayed with ZIP plus layers because it keeps Go deploys tiny and fast.
Lambda cold starts: custom warmers vs provisioned concurrency
Go already has some of the shortest Lambda cold starts around. Still, the first request after a quiet period pays for a new execution environment. For a user opening their dashboard that's barely noticeable. For someone joining a live recording session, every bit of lag shows.
We use two tools, depending on how much a route matters.
Option 1: a warmup path in the handler
A scheduled EventBridge rule pings the function every few minutes with a tiny payload. The handler spots it and returns right away, so the environment stays warm for almost no cost.
type warmup struct {
Warmup bool `json:"warmup"`
}
func handler(ctx context.Context, raw json.RawMessage) (any, error) {
// Scheduled ping: keep the environment alive, do nothing else.
var w warmup
if json.Unmarshal(raw, &w) == nil && w.Warmup {
return nil, nil
}
var req events.APIGatewayV2HTTPRequest
if err := json.Unmarshal(raw, &req); err != nil {
return nil, err
}
return route(ctx, req)
}
It's cheap and simple, but be honest about what it does. One ping keeps roughly one environment warm. A burst of concurrent users still triggers fresh cold starts. And AWS can recycle environments whenever it wants, so it's best effort.
Option 2: provisioned concurrency
Provisioned concurrency keeps a set number of environments initialized and ready. No cold starts up to that number, guaranteed. The catch is that you pay for it every hour it's configured, whether requests come in or not. That's exactly the always-on cost we were trying to avoid.
Two things make it reasonable:
- Use it only on latency-critical routes, like joining a session. Everything else lives with the occasional cold start.
- Schedule it. Provisioned concurrency works with Application Auto Scaling, so you can raise it during the hours your users are active and drop it at night. Our usersβ busy hours are predictable, so this works well
| Approach | Cost | Handles bursts | Best for |
|---|---|---|---|
| Do nothing | Free | No | Background workers, admin routes |
| Warmup ping | Near zero | No, about one environment per ping | Low-traffic routes that should feel snappy |
| Provisioned concurrency | Billed while configured | Yes, up to the configured amount | Routes where latency is the product |
π‘ Measure before you optimize. CloudWatch logs an Init Duration on every cold start. Check how often it happens on each function before paying to make it go away.
When Lambda stopped being the right tool
Serverless-first doesn't mean serverless-only. Full video encoding moved to Fargate. Encoding an hour-long multitrack session can blow past 15 minutes, and it wants steady CPU for the whole run. Fargate tasks have no duration cap, and we still only pay while a task runs. A Lambda kicks the task off, and the worker reports back to the same job record as every other job.
A few things we learned there:
- Parallelize the pipeline. We split the encode into steps that run in parallel, with a fallback if one fails. That made encoding much faster than a single long ffmpeg run.
- Tune quality settings before buying more compute. For our 1080p output, CRF 26 cut file size a lot with no difference we could see.
- Keep the contract the same. Lambda or Fargate, a worker reads inputs from S3, writes outputs to S3 and updates the job. The API doesn't care where the work ran.
Start lean, keep the bill honest, and move work when it outgrows Lambda
If you're building something new, Go on Lambda is a strong default. Keep sync routes fast. Turn everything slow into a job. Put ffmpeg in a layer for light work and move heavy encoding to containers. Fix cold starts with the cheapest tool that works for each route.
That's the backend behind Chord today. If you record podcasts, interviews or video content, give Chord a try. And if you're running Go on Lambda yourself, I'd love to hear which patterns worked for you in the comments.
Top comments (0)