Yoink

  • Web products
  • Product Engineering
  • 2024
  • Private

WXT, Next.js, NestJS, Go and 6 more

Yoink is a media extraction tool built as six parts. A WXT extension, a Next.js dashboard and a macOS app are the clients. A NestJS backend owns every persistent decision. A Go Lambda and a Python Lambda extract, unless the desktop app does it locally. Dedicated extractors cover YouTube, LinkedIn, X, Instagram, Threads, Pinterest, Facebook and Kartoons. A generic path covers other pages that carry a <video> element.

The split is not about scale. It is about which parts are allowed to fail. Extraction breaks whenever a platform quietly changes something, and billing must never be wrong. Putting both in one process means the first one takes out the second. So I gave nothing that runs an extractor any database credentials.

A media extraction platform with a browser extension, a web dashboard, a macOS app, Go and Python Lambdas, and one backend for auth, quotas and billing.

outputsession

# extension: Download clicked on a YouTube watch pagePOST /api/auth/download-ticket        hmac, 120 s ttlGET  /api/download?downloadTicket=…   backendApiKeyGuard: ticket -> api key        device id matchesplatform=youtube -> lambdas-python    pytubefixPOST /api/internal/authorize          allowedPOST /api/internal/download/start     quota checked, row openstreaming to the browser download managerPOST /api/internal/download/complete  status=completed

8 lines

numbersfrom the write-up

6parts: three clients, a backend and two Lambdas

120 s
lifetime of a signed download ticket
5 min
idle before the desktop engine stops
Chapter
Web products
Category
Product Engineering
Year
Availability
Private
stack10 parts
  • WXT
  • Next.js
  • NestJS
  • Go
  • Python
  • Electron
  • AWS Lambda
  • PostgreSQL
  • Stripe
  • Terraform

System Architecture, Browser Extension, Next.js, NestJS, AWS Lambda, Electron, PostgreSQL, Terraform

architecturethe signed ticket
An extension and a dashboard reach one backend that owns every write, while Go on Lambda streams the download to the browserExtensionsends X-API-KeyDashboardproxies, holds no secretNestJS backendthe only writerauthorizelimitsticketsbillingLambda · Goyt-dlp · ffmpegPostgreSQLidentity · access · keysusage · download historysubscriptions · couponsBrowserno staged fileapi keyproxyone writerticketresultstreamsa signed ticket keeps the key out of the urlthree auth modes, one shared secretAn extension and a dashboard reach one backend that owns every write, while Go on Lambda streams the download to the browserapi keyproxyone writerticketstreamsExtensionsends X-API-KeyDashboardholds no secretNestJS backendthe only writerauthorizelimitsticketsbillingPostgreSQLidentity · keysusage · historysubscriptionsLambda · Goyt-dlp · ffmpegBrowserno staged filea signed ticket keeps the key out of the urlthree auth modes, one shared secret
Two clients reach one backend that owns every write, and Go on Lambda streams the bytes to the browser.

Six parts, two runtimes

The backend shells out to nothing. It picks a Lambda per request. YouTube goes to Python on pytubefix, and everything else goes to Go on yt-dlp and ffmpeg from a pinned layer. YouTube format lookups can fall back to Go, but YouTube downloads never do. Both Lambdas sit behind Function URLs in RESPONSE_STREAM mode.

PartRuntimeJob
apps/extensionWXT, ReactIn-page button, tickets, desktop handoff
apps/webNext.js, NextAuthDashboard, web downloads, release files
apps/backendNestJS on VercelKeys, quotas, billing, history, routing
services/lambdas-goGo, yt-dlp, ffmpegEvery platform except YouTube
services/lambdas-pythonPython, pytubefixYouTube
apps/electronElectron, local Go engineExtraction on macOS without Lambda

The dashboard holds no backend secret in the browser. Its /api/backend/[...path] route injects the service token and X-User-* headers, and forwards only an allowlist of user-facing namespaces.

A download in flight

The extension never puts its API key in a URL. A browser download manager needs a plain GET, so the extension first mints a ticket at POST /api/auth/download-ticket. It is an HMAC-signed payload carrying the key id and device id, valid for 120 seconds by default. The backend resolves it and proxies to the right Lambda. The Lambda calls /api/internal/authorize, which checks the key, plan, burst and hourly limits, the monthly cap and a per-plan duration cap. Then /api/internal/download/start opens a download_history row. If that write fails, both Lambdas refuse rather than serve a download nobody recorded. Completion or failure is posted back, and the Go handler attaches an estimated Lambda cost. A Go stream that breaks midway aborts with no Content-Length, so the browser sees truncation instead of a clean end.

Web Downloader Interface

The desktop path

The macOS app extracts and downloads on the machine, with no Lambda involved. Electron spawns yoink-engine, built from the Go service's cmd/engine, on 127.0.0.1 at a free port. Each engine start mints a new X-Engine-Token, and the engine stops after five idle minutes. The bundle carries yt-dlp, an LGPL ffmpeg and yoink-youtube, a PyInstaller build of the same pytubefix code. The renderer reaches the backend and engine only through typed IPC, and the API key sits in the macOS Keychain. Quotas still apply: /api/desktop/authorize runs the same checks, and history rows record desktop_engine as their source. The extension can also hand a page to the desktop app through /api/desktop/queue/enqueue.

Decisions and costs

  • One writer. Neither Lambda nor the engine can reach PostgreSQL, so admin analytics read one store and split it by executionSource. The price is a network hop per download, and a backend outage stops extraction that would otherwise succeed.
  • Write before the sandbox freezes. AWS freezes a Lambda once it responds, so detached goroutines would lose writes at random. The Go options handler finishes LogUsage first, and the format list waits on it.
  • Fail closed on accounting. An unrecorded download is a free one, so I made a missing history row mean no bytes. A backend blip now stops downloads that would have succeeded.
  • Serialize quota per user. download/start takes pg_advisory_xact_lock, recounts the month and inserts in one transaction. That closed a race where parallel requests passed authorize and overshot the cap.
  • The one I would revisit: the duration cap applies only when the caller sends durationSeconds. Otherwise the backend logs a warning and allows it, which keeps older clients working but leaves a gap.

Running it

pnpm dev starts everything and refuses to run on a port conflict. The ports are 3000 to 3004 for extension, web, backend and both Lambdas, and 5173 for Electron. BACKEND_SERVICE_TOKEN must match in web, backend and both Lambdas, so rotating it is a four-service change. Terraform in infra/terraform covers both Lambdas, the Vercel projects and the R2 bucket for desktop updates, each behind a feature flag. Pushes to release deploy through local pre-push hooks. The desktop build is arm64 only and ad-hoc signed, so an update downloads a DMG to install by hand rather than relaunching itself. Yoink is in active development, and the source is private.

All 43 projects