Cloud video platform

RyuZCloud

Status today: Live at ryuzcloud.com on AWS (ECS Fargate, RDS, ALB, S3, CloudFront, SQS). No users and no load test. Every number below was measured either on my local VM or in the AWS session of 2026-11-14, and each one says which.

Stack
Go API, Go and FFmpeg HLS worker, PostgreSQL, SQS, S3 and CloudFront signed cookies, Next.js 15, Terraform on AWS (ECS Fargate, RDS, ALB)
Kind
Solo portfolio project. No users, no revenue.
Measured where
Local: Docker Compose on one Ubuntu VM. AWS: us-west-2.
How I work
How I work and verify

The problem

A video platform has two awkward properties. The files are large, so they should never pass through the API. And transcoding is slow and fails in interesting ways: a worker is killed halfway, a message is delivered twice, two workers race for the same job. A single upload still has to end up as exactly one playable video.

RyuZCloud is the core of a video site built to work through that: accounts, channels, direct uploads, an asynchronous HLS pipeline, and private, authorised playback.

What I built

What exists, and what does not.

Built and tested

  • A Go API (standard-library net/http, a modular monolith) with Argon2id passwords, server-side sessions and channels
  • Uploads straight to private S3 with a presigned PUT; the API confirms the object with HeadObject before queuing
  • A separate Go worker: ffprobe, then 360p and 720p HLS renditions and a thumbnail, with leases, retries and a sweeper
  • Private playback through CloudFront signed cookies scoped to one video's path
  • A Next.js 15 frontend with an hls.js player, and a seeded, licence-recorded demo library
  • Terraform for the whole AWS stack, and GitHub Actions CI that never touches AWS

Not built yet

  • Multipart or resumable uploads (single PUT only)
  • Search, view counting
  • Autoscaling, Multi-AZ, WAF, private subnets, a tested database restore
  • Any measurement of load, concurrency or real cost

System architecture

This diagram scrolls sideways on a narrow screen.

RyuZCloud system architecture on AWSThe browser reaches a load balancer that serves a Next.js app and a Go API. The browser uploads video directly to a private S3 bucket using a presigned URL. The API records the upload in PostgreSQL and puts a job ID on an SQS queue. A Go worker with FFmpeg takes the job, claims it in PostgreSQL, reads the source from S3 and writes HLS files back. Playback goes through CloudFront with signed cookies.BrowserNext.js UIhls.js playerALB (HTTPS)Next.jsGo APIECS FargatePostgreSQL 17source of truthfor job stateSQS + DLQcarries a job ID onlyGo workerFFmpeg, Fargate SpotPrivate S3 bucketsources and HLSCloudFrontOAC, signed cookiesjob IDreceiveclaim with a leaseHLS outpresigned PUT, bypasses the APIplaybackLocally, Redis, MinIO and the API itself stand in for SQS, S3 and CloudFront.
System architecture on AWS. The browser reaches a load balancer that serves a Next.js app and a Go API. The browser uploads video directly to a private S3 bucket using a presigned URL. The API records the upload in PostgreSQL and puts a job ID on an SQS queue. A Go worker with FFmpeg takes the job, claims it in PostgreSQL, reads the source from S3 and writes HLS files back. Playback goes through CloudFront with signed cookies.

An upload works like this: the API validates the request and returns a presigned PUT; the browser sends the file straight to the bucket; the API then confirms the stored object and, in one transaction, marks the video queued and inserts the job row. Only then does it send the job ID to SQS. Video bytes never touch the load balancer, the API or Next.js. Locally, the same code runs with MinIO, Redis and the API itself standing in for S3, SQS and CloudFront, selected by environment variables.

Decisions and what each cost

From the project's documented tradeoffs.
DecisionChoiceTradeoff accepted
Job statePostgreSQL is the source of truth; SQS only says "look at job X"Duplicates are harmless by design. Crash recovery waits for the lease to expire.
ComputeECS Fargate, worker on Fargate SpotNo servers to patch, and Spot is safe because jobs are leased and retried. An interrupted encode restarts from the beginning.
PlaybackCloudFront signed cookies on a sibling subdomain, signed with the standard libraryOne signature covers the playlist and every relative segment, with no new dependency. Needs a domain I control, and cookies cannot be revoked early.
NetworkingPublic subnets, no NAT gateway; tasks accept traffic only from the load balancerCheaper, with weaker isolation. Private subnets are the hardening step.
DatabaseRDS PostgreSQL, single-AZAn AZ outage means downtime until restore.

The three hardest problems

1. A background pipeline that stays correct under crashes, duplicates and retries

The queue delivers at least once and is not a store of truth, so it carries only a job ID. The truth lives in a job row in PostgreSQL, and the design follows from that:

  • Claim is one conditional UPDATE. With several workers racing, exactly one matches and the others drop the message.
  • Lease and heartbeat. Every change to the job requires that this worker still owns it; otherwise the worker abandons its work.
  • Sweeper. Jobs with no live owner are sent again, using FOR UPDATE SKIP LOCKED.
  • Acknowledge only after commit. The result transaction commits first; the SQS message is deleted afterwards.
  • Master playlist last. A half-finished video is never playable.

This diagram scrolls sideways on a narrow screen.

RyuZCloud worker crash recovery timelineWorker A claims a job, which sets attempts to 1 and a 120 second lease, and starts encoding. It is killed at about 2 percent progress. The lease runs out. A sweeper notices the job has no live owner and puts the job ID back on the queue. Worker B claims it with attempts equal to 2, finishes, commits the result and only then acknowledges the message.Worker AJob rowSweeperWorker Bencoding, sending heartbeatskilled at about 2%A owns the job: attempts = 1, lease 120 slease runs outB owns it: attempts = 2no live owner found,job ID sent againencodes, commits result,then acknowledgesDefaults: lease 120 s, heartbeat every third of the lease, sweeper every 15 s. Recovery took "several minutes" when tested.
Crash recovery. Worker A claims a job, which sets attempts to 1 and a 120 second lease, and starts encoding. It is killed at about 2 percent progress. The lease runs out. A sweeper notices the job has no live owner and puts the job ID back on the queue. Worker B claims it with attempts equal to 2, finishes, commits the result and only then acknowledges the message.

Tradeoffs: recovery waits for the lease, a retry restarts the encode from the beginning, and how long recovery takes has not been measured yet.

2. A CloudFront signed-cookie bug that a unit test could not see

The bucket is private and video reaches viewers only through CloudFront, using signed cookies that the API sets after its normal visibility checks. An HLS playlist refers to its segments by relative path, which is why cookies are used instead of a signature in the URL.

In the first AWS session, uploads and processing worked, but playback returned 403. Decoding the cookie policy showed its resource ended in %2A rather than *: the code had built the URL with Go's URL type, which percent-encodes the wildcard, and CloudFront matches the literal text. The unit test had only signed a hand-written string, so it never exercised the real code path.

Resource in the cookie policy
  broken:  https://media.<domain>/videos/<id>/%2A
  fixed:   built as  "https://" + domain + "/" + VideoPrefix + "*"

The fix builds the string directly, and a regression test asserts that the real grant path keeps the literal wildcard. The lesson is to test what the handler builds, not what the helper accepts.

3. Measuring honestly, including the changes that did not work

After the frontend redesign I measured before and after on the same machine with the same seeded library. Two layout-shift fixes worked. One change did not: making Chrome use hls.js instead of its built-in HLS player was slower to the first frame and made pages heavier, so I reverted it. The ledger records both, and the revert is listed as not yet re-measured rather than assumed to be fixed.

Evidence

Every number here has a row in the project's docs/metrics.md, and only rows marked Run or User-reported are quoted. Estimates, such as the list-price cost per day, are left out. Each line says whether it was measured on my local VM or on AWS. I ran none of these checks again while writing this page.

Correctness and tests (local)

  • The worker was SIGKILLed mid-encode; its lease expired and the job finished on attempt 2. The crash script passed 43 checks (35 baseline plus 8 recovery). In an earlier run the kill came at about 2 % of the encode.

    Run 2026-11-10

    Local: Docker Compose on the Ubuntu VM (4 vCPU), synthetic 10 s clip, lease 120 s. Recovery time was not measured [R2, R3].

  • The upload script passed 23 checks and the processing script (upload, queue, worker, HLS) 35.

    Run 2026-11-10

    Local: Docker Compose on the Ubuntu VM, browser-equivalent upload to MinIO [R1, R4].

  • All 9 Go test packages pass against a real Postgres 17, the real-FFmpeg transcode tests pass in 11.9 s, and the frontend passes 116 of 116 tests.

    Run 2026-11-24

    Local: Go 1.26.10 image and Postgres 17 container (2026-11-10); Vitest in the container (2026-11-24) [T1, T3, T4].

  • govulncheck reported 13 reachable vulnerabilities, then 0 after upgrading Go (1.25.14 to 1.26.10), pgx and x/text. gitleaks found 0 leaks across 15 commits.

    Run 2026-11-10

    Local: govulncheck v1.1.4, gitleaks 8.21.2 [S1, S2].

The seeded library (local)

  • A 40-clip library (971 s of footage) went through the real upload path: 40 ready, 0 failed, every job on its first attempt. Its 430.6 MB of originals became 288.5 MB of HLS in two renditions.

    Run 2026-11-24

    Local: Docker Compose on the VM, worker concurrency 1, 2 CPUs, 360p and 720p renditions. Clips from Pixabay and Wikimedia Commons [L1, L2].

  • Worker job time divided by clip length had a median of 0.768× (range 0.321 to 2.789×) over 40 clips of 8 to 60 s, covering download, probe, both renditions, thumbnail and upload.

    Run 2026-11-24

    Local VM, worker 2 CPUs, FFmpeg 2 threads. One seed, so the spread is across clips, not repeated runs. Not measured on Fargate [P1].

Frontend (local)

  • On the real local stack, 8 of 8 browser tests passed: 9 pages at 390 and 1440 px with 0 WCAG 2.1 A/AA violations, 0 px sideways overflow at 320 px, and the player usable by keyboard alone. Lighthouse accessibility was 100 on every measured page.

    Run 2026-11-26

    Local: Compose stack, Playwright 1.65, Chromium; Lighthouse 13.6.0 on production builds [T6, P4].

  • Layout shift went from 0.668 to 0 on the desktop credits page and from 0.17 to 0 on the mobile watch page. Switching Chrome to hls.js made time to first frame slower (653 ms to 976 ms unthrottled, medians, n = 12) and pages heavier, so it was reverted; the revert is not yet re-measured.

    Run 2026-11-26

    Local: production builds on the VM, seeded library, Lighthouse 13.6.0 and Playwright Chromium. Timings are local, with no CDN [P4b, P4db, P3b].

AWS

  • Unsigned media requests got 403 from CloudFront and from S3 directly; with signed cookies they got 200.

    Run 2026-11-14

    AWS us-west-2, curl checks [S3].

  • On AWS, playback returned 403 because the cookie policy’s resource ended in %2A instead of *: the URL builder percent-encoded the wildcard. The fix builds the resource string directly, and a regression test asserting the literal wildcard passes.

    Run 2026-11-23

    Found in the 2026-11-14 AWS session; the regression test passed locally on 2026-11-23 [T5].

  • Terraform planned 115 resources from an empty state. Two uploads (10 s and 6 s HEVC) were each transcoded to 360p and 720p on Fargate, logged at 33 s and 16 s. 20 CloudWatch alarms were defined and 19 of 20 were OK at the first check. The teardown destroyed 94 resources.

    User-reported 2026-11-14

    AWS us-west-2. 94 does not match the 115 planned, and the ledger leaves that unexplained. Worker task size was not confirmed; n = 2, not a benchmark [C1, C2, C3, C4].

Not measured yet

  • Not measured yet: concurrent uploads, recovery time after a worker kill, duplicate outputs after recovery, transcode speed on Fargate, time from apply to first played video, and real cost from Cost Explorer.

    Not run 2026-11-26

    Listed as Not run in the project’s ledger. A list-price cost estimate exists there but is not repeated here [R5, R6, R7, C5, C6, P1b].

Tradeoffs and limits

  • The site is live, but no number on this page was measured on the current deployment. The AWS figures come from the 2026-11-14 session.
  • No latency, throughput, concurrent-upload or real-cost figures exist. Transcode speed was measured on my local VM, not on Fargate.
  • The AWS counts do not reconcile: 115 planned, 94 destroyed. The project's ledger leaves that unexplained.
  • Tasks have public IPs and no NAT, there is no WAF, no Multi-AZ database, and no restore has been tested.
  • Uploads are single-part only, and encodes are CPU-only.
  • Safari's native HLS with cross-origin cookies is configured but unverified.

What I would improve next

These come from the project's own list and are planned, not done.

  1. Measure transcode speed on Fargate with a stated task size, and the real cost of running the stack.
  2. Measure recovery time after a worker kill, and run concurrent uploads to check nothing is lost or duplicated.
  3. Re-measure the player revert, and time a rebuild from zero using the runbook.
  4. Move to private subnets or endpoints, test a database restore, and add multipart uploads.