Interactive walkthrough

How one image travels through WildLens

A camera-trap photo goes in. Thirteen steps later it is a database record tagged {"wild boar": 1}, a thumbnail in object storage, and an email to everyone subscribed to that species. Step through it below.

AWS ap-southeast-2 Terraform S3 · SQS · Lambda · DynamoDB · SNS MegaDetector → SpeciesNet
Design document — project in active development
01 · Ingest path

From upload button to tagged record

Highlighted boxes are the components doing work at the current step. Solid green is data moving now, faint grey is not yet reached, amber is the failure path.

POST /upload verify JWT dedupe · write PENDING presigned URL · 5 min PUT bytes ObjectCreated event claim message update status ≤ 300px 1 msg / species 3 failures client polls GET /files/{sha} every 3s Browser SHA-256 API Gateway + Cognito Lambda /upload S3 · raw sha.jpg SQS ingest queue Lambda · ML 3 GB · max 2 DynamoDB wildlens-files DLQ + alarm S3 · thumbs thumbnail SNS email
Ten components, three bands: intake along the top, processing through the middle, outputs along the bottom. The SQS queue sits between S3 and the ML worker — that placement is the one structural change from the original coursework design.
Step 1 / 13

active this step already traversed not yet reached response / poll failure path
02 · Architecture decision

Why a queue sits in the middle

This is the single structural departure from the original design, and it is not decoration. The figure draws the thing that actually changes: who decides how many 3 GB workers come into existence.

ORIGINAL — S3 INVOKES LAMBDA DIRECTLY S3 Lambda 3 GB Lambda 3 GB Lambda 3 GB Lambda 3 GB … × N — no ceiling one retry loop = unbounded spend WILDLENS — S3 → SQS → LAMBDA S3 SQS buffers Lambda 3 GB Lambda 3 GB hard cap: 2 3 failures DLQ held for inspection Worst realistic case — a retry loop running unnoticed for eight hours: ≈ $80 without the queue ≈ $4 with the queue, capped at 2 SQS and the DLQ both sit inside the perpetual one-million-request free tier — the brake itself costs nothing.
The two sides differ in exactly one respect: who controls how many workers spawn. Without the queue that decision belongs to S3, and S3 knows nothing about the budget.
03 · Record lifecycle

Four states, and a free garbage collector

The original wrote to the database only once processing finished, so for the three minutes in between the UI had nothing to render. Writing early and updating in place is what makes a progress indicator possible at all.

PENDING written by /upload message claimed PROCESSING written by ML worker inference complete DONE + tags, TTL removed retries exhausted FAILED with errorReason abandoned upload: a one-hour DynamoDB TTL reaps the row at no cost What the user sees ⏳ Received, queued… 🔍 Identifying species… ✅ Found: 1 wild boar ❌ Failed — [reason]
The right-hand column is what each state renders as in the UI. The dashed arrow is the cleanup mechanism: a PENDING row is born with a one-hour expiry, and that expiry is removed only when the work completes.
04 · Queue semantics

Three things that bite first-time queue users

Each of these is handled explicitly in the Terraform and in the worker. They are listed here because the handling, not the queue itself, is the interesting part.

SQS delivery 1 delivery 2 Worker ML DynamoDB conditional write “write only if status <> DONE”

① The same file processed twice

Standard SQS guarantees at-least-once delivery, not exactly-once. Unguarded, a redelivery means running inference twice and emailing subscribers twice.

Handled by: a conditional write — “only if this record is not already DONE”. The second run catches ConditionalCheckFailedException, logs it, and exits successfully. The property is idempotency.

Worker needs up to 900 s Message hidden for 30 s queue assumes the worker died → redeliver → redeliver → …

② The hidden clock that fans out

While a worker holds a message, SQS hides it for the visibility timeout. If that expires before the work finishes, the message is handed to another worker — exactly the runaway the queue was meant to prevent.

Handled by: visibility timeout ≥ 6 × the function timeout. A 900 s function gets 5400 s, set in Terraform with the reasoning in a comment.

SQS Worker attempt crash · × 3 DLQ 🔔 alarm → email main queue stays clear

③ One bad file blocks the queue

A corrupt image crashes the worker. The message returns, is retried, crashes again — indefinitely, holding up everything behind it.

Handled by: a redrive policy at three attempts, plus a CloudWatch alarm on DLQ depth ≥ 1. docs/runbook.md documents the triage steps.

05 · Cost engineering

Running this on a $100 credit

The interesting risk is not the running cost; it is the resources that bill by the hour whether or not anything happens.

ComponentIdle monthActive month (~200 files)
ECR — 4.5 GB container image$0.45$0.45
S3 — originals, thumbnails, static site$0.10$0.30
Lambda — ML worker$0.00$2.00
DynamoDB — on-demand$0.00$0.05
SQS · DLQ · SNS · Cognito · API Gateway$0.00$0.00
CloudWatch — 14-day logs + X-Ray$0.20$0.50
Total per month$0.75$3.30

The $32/month trap, avoided deliberately: a great deal of tutorial material puts Lambda inside a VPC because it sounds more secure. A VPC-attached Lambda that needs outbound internet requires a NAT Gateway — $32 a month, billed hourly, whether or not it carries traffic. Nothing here needs a VPC: every service the worker talks to is a public AWS endpoint already gated by IAM. That decision is recorded as an ADR.

Six guardrails: budget alarms at $10 / $25 / $50 · a concurrency cap of 2 on the queue’s event source mapping · 14-day log retention · ECR lifecycle policy keeping three images · uploads kept exactly as long as the records that describe them (ADR 8) · terraform destroy between working sessions.

06 · Build plan

Four milestones, each a complete artefact

Ordering principle: whatever is hardest to debug gets built earliest, and in the environment where debugging is cheapest. Inference is proven on a laptop before it ever enters a container, because a round trip through a container image of over a gigabyte costs many minutes.

MILESTONE A

Inference running in the cloud

Toolchain, IAM user, budget alarms, Terraform for buckets and table, ML proven locally against the test set, container on ECR, baseline cold-start measured.

Phases 0–3 · done
MILESTONE B

Working end to end

Queue, DLQ, idempotency, four-state lifecycle, cold-start optimisation with before/after numbers, Cognito, REST API, web client with polling.

Phases 4–7 · done
MILESTONE C

Operable, not just working

Tag subscriptions over SNS, X-Ray tracing, dashboard, alarms, runbook, GitHub Actions with OIDC federation and infrastructure security scanning.

Phases 8–10 · done
MILESTONE D

Complete

Video frame sampling with MaxN counts, README, thirteen ADRs, this diagram and a demo recording. Cross-cloud JWT verification on GCP (Phase 11) is optional and not built.

Phases 12–13 · done · 11 optional