Cima Architecture
I built Cima to log bouldering sessions, track projects, train fingers, and get technique feedback from climbing videos. The web app and mobile app talk to the same API.
The main split in the architecture comes down to time. Logging a climb is fast, so it happens in a single request. Analyzing a video is slow, so the clip uploads straight to S3 and background workers process it while the climber keeps going.

What the video pipeline produces: a pose overlay on the clip, four movement scores, and coaching notes.
Where Cima runs
SST deploys the TanStack Start web app and the Effect API to AWS. The Expo mobile app calls that same API.
The AWS stack also includes:
- An S3 bucket behind CloudFront for videos, thumbnails, pose JSON, and transcoded playback files.
- Two SQS queues for video processing, plus a shared dead-letter queue (DLQ).
- Lambda workers for pose extraction, AI analysis, and failed-job cleanup.
- An API Gateway WebSocket API backed by DynamoDB for live progress updates, plus a second DynamoDB table for session caching and rate limits.
PlanetScale hosts PostgreSQL separately. SST links each resource to the Lambda functions that need it and passes in the database connection settings.
Logging a climb
When a climber logs an attempt, the client calls the problem.create oRPC procedure. Better Auth checks who is signed in, and Effect Schema validates the input. An Effect service then confirms the climber owns the session and saves the row to PostgreSQL with Drizzle.
Both clients cache server state with TanStack Query. On the web, a successful save updates the session view and refreshes related queries right away. Keeping climb writes synchronous means a success response always guarantees the attempt is in the database.
Getting feedback on a video
- The API verifies the climber's session, creates a video record, and returns a signed S3 upload URL. The client uploads the clip straight to S3 and confirms the upload. Video bytes never pass through the API Lambda.
- S3 puts an upload event on
MediaPipeQueue. A containerized Python Lambda runs MediaPipe (MODEL_COMPLEXITY=2) to extract 33 body landmarks at 10 FPS. It writes the pose JSON, thumbnail, and playback rendition to S3, streams progress over WebSockets, and queues apose_data_readymessage onAnalysisQueue. - A Node.js Lambda reads the pose JSON (compressing it by about 90% to fit LLM context cleanly) along with selected video frames. It uses Moondream to detect holds and wall angle. If the pose quality checks pass, it calls the primary LLM (with fallback models configured) to generate scores and coaching notes. Runs usually finish in 15 to 32 seconds, save to PostgreSQL, notify open clients over WebSockets, and send an Expo push notification if the climber left the app.
Making retries safe
Setting up two queues is simple. Most of the real work was making sure retries do not double-run analyses, waste LLM spend, or leave clips stuck in QUEUED.
Preventing duplicate runs with a lease
SQS delivers messages at least once, so the same video can be delivered to the analysis worker more than once. To make the worker safe to repeat, each run first claims a 10-minute lease in PostgreSQL with a unique leaseToken:
const [run] = yield* db
.update(videoAnalysisRun)
.set({
status: "processing",
leaseToken: crypto.randomUUID(),
leaseUntil: new Date(now.getTime() + ANALYSIS_LEASE_MS),
attempts: sql`${videoAnalysisRun.attempts} + 1`,
})
.where(
and(
eq(videoAnalysisRun.videoId, videoId),
ne(videoAnalysisRun.status, "completed"),
or(
isNull(videoAnalysisRun.leaseUntil),
lt(videoAnalysisRun.leaseUntil, now),
),
),
)
.returning();If another worker already holds an active lease, or the run already finished, this update returns nothing and the duplicate message exits. Before saving the final result, the worker locks the row with SELECT ... FOR UPDATE and checks that its leaseToken still matches.
The timeouts fit together around this lease:
- Analysis Lambda timeout: 5 minutes
- Database run lease: 10 minutes
- SQS visibility timeout: 30 minutes (6x the Lambda timeout)
A running worker always finishes inside its lease. If a worker crashes, the lease expires well before SQS redelivers the message, so the retry can claim it cleanly.
Faster retries, permanent errors, and the DLQ
Waiting 30 or 60 minutes for a visibility timeout makes sense after a crash, but it is too slow for a short API error. When either worker catches a retryable error, it calls SQS ChangeMessageVisibility to retry sooner: 1, 5, 15, and 30 minutes for MediaPipe, and 1, 5, and 15 minutes for analysis (never before a held lease expires).
Some errors should not retry at all. MediaPipe saves the last 60 seconds of its 10-minute timeout (FINISH_RESERVE_MS) so clips that run too long can write a PipelineError marker like VIDEO_TOO_LONG and stop cleanly. The clients read that error code and hide the Retry button.
Analysis retries stop after 3 tries (compared to 5 for MediaPipe) because each retry can pay for another LLM call. Once retries run out, messages move to ProcessingDLQ. A dedicated ProcessingDLQWorker marks the video FAILED and sends the WebSocket and push notice so nothing stays stuck in QUEUED.
Concurrency limits and x86_64 vs. arm64
A burst of uploads would normally start one Lambda per message. That can drain PostgreSQL pooler connections and hit Moondream's rate limit. Instead of using Lambda reserved concurrency (where throttled runs count against SQS's DLQ retry limit), each queue sets maximumConcurrency: 10 on its event-source mapping so extra messages simply wait in SQS.
Every Node.js Lambda in Cima runs on arm64, except the Python MediaPipe container, which stays on x86_64 (3008 MB memory, 5 GB /tmp). In tests with real iPhone 10-bit HEVC videos, Graviton cost 13 to 19% less per clip, but decoded HEVC 8 to 17% slower. On longer clips, that slowdown pushed runs past the timeout, so x86_64 was worth the small extra cost.
What the split costs
Sharing one oRPC contract catches most API mismatches across web and mobile in TypeScript. Still, older mobile app builds stay installed on phones after an API deploy, so contract changes have to stay backward-compatible. For example, adding cursor pagination to problem.list meant wrapping the new input in Schema.UndefinedOr so older builds can keep calling it with no arguments. Cima also serves a frozen /api/app/version endpoint (AppVersionPolicy) to prompt or require updates when needed.
Keeping pose extraction and AI analysis in separate queues lets a failed analysis retry using the pose JSON already in S3, without re-reading the video. It also lets S3 lifecycle rules tag originals (playback=original vs. playback=rendition) so originals replaced by a playback rendition move to Glacier Instant Retrieval after 30 days.
The trade-off is extra client state. A video can finish uploading while pose extraction or AI feedback is still running, and both apps have to show each stage clearly, including when a climber can retry and when they need to trim and upload again.
Franklin Jara