A personal podcast generator: the tool knows about a user's interests and, on a given schedule, gathers interesting news about those topics and creates engaging audio covering them.
- Async worker + Postgres-as-broker — episodes take minutes, so work runs in a dedicated worker with pg-boss in Postgres, not inside requests.
- At-least-once idempotency — delivery is at-least-once;
jobIdupsert + a reuse ladder make retries converge on one episode. - Re-encode, not byte-concat — synthesized chunks are re-encoded into one MP3 so playback seeks correctly; byte-concatenated clips drift.
- Ranking is the weak link — Tavily discovery works; cross-feed ranking and scoring is the main gap.
- Interests UI — a settings page where the user picks their topics and how the show runs: format and cadence.
- News ingestion — the backend pulls recent news about those interests from a search provider.
- Metrics dashboard — a dashboard of the business metrics the product would live or die on (mocked data for now).
- Audio generation — an LLM writes the episode script; a TTS provider voices it.
The goal is an MVP that answers one question: does the loop produce audio worth hearing? Most of the effort has gone into async orchestration, prompt engineering, and audio synthesis. Deploy, hardened auth, and observability are deferred (see What it would take to deploy).
Scoping calls:
- Customization means topics, cadence, and format: what the podcast covers, how often it runs, and how the story is told.
- "Engaging" = a multi-voice editorial briefing, not a robotic article summary.
- Dashboard = the core business metrics that drive decisions: retention, unit economics, and pipeline health (see Business).
- One feed per user, intentional for this prototype. It keeps the data model and UI single-subscription; multiple feeds are a fan-out that doesn't change the core loop.
- Auth is a deliberately minimal credentials login (no public sign-up), enough to gate the app; production would use a managed identity provider.
The UX stays small: one main page built around the loop (set interests, wait for the schedule, listen). I prioritized output quality over breadth of settings.
Generation takes minutes and sometimes finds nothing or fails, so the episode list shows four states instead of a happy-path-only list:
- In progress — a polled, stage-labelled skeleton, so a long run reads as progress, not a hang.
- Ready — title, topics covered, inline player.
- No news — a run that found nothing says so plainly.
- Failed — a clear message that the next scheduled run will try again.
Beyond that, richer customization, multiple feeds, and a polished player wait until the loop proves out.
A Next.js app serves the UIs, auth, and feed settings; PostgreSQL holds application data and the job queue; a separate worker runs the generation pipeline; finished audio lives in S3-compatible object storage.
- Generation is async. An episode takes minutes, so it never runs inside a request. The schedule enqueues a job; the worker runs the pipeline and updates episode status; the UI polls that status. Web and worker scale independently (request traffic vs. queue depth).
- Postgres is the broker. pg-boss lives in the app database: one less service, ACID with app data, native cron, row-level locking for stateless workers.
- Scale out on I/O. Wall time is mostly waiting on providers. A worker process can run multiple episodes concurrently; ffmpeg encode runs in a subprocess so it does not block the event loop. Throughput is capped by provider rate limits and memory for audio buffers, not CPU.
The pieces, and why each over the alternative:
| Piece | Chosen | Over | Advantage | Tradeoff |
|---|---|---|---|---|
| App & server | Next.js (App Router) | a separate API + SPA | one app for both UIs and the server, fastest to build and iterate on | UI and server are coupled; one deploy, scaled together (the worker is split out) |
| Store + job queue | PostgreSQL + pg-boss | Redis, RabbitMQ, or another dedicated broker | one datastore for data and jobs (ACID, native cron, no extra infra); ample for this low-volume, scheduled workload | Postgres is the shared chokepoint at high throughput |
| Episode generation | a dedicated worker process | running it inside the web server | a crash or memory spike can't take the app down; scales on queue depth, separate from web traffic | one more service to deploy |
| News | Tavily (search + extract) | RSS feeds / per-site scrapers | one API for discovery and extraction; no per-site scrapers to maintain | paid; ranking is opaque (the weak link) |
| Audio storage | S3-compatible object storage | blobs in Postgres | media belongs in a blob store; the row keeps only the key | presigned URLs so playback streams from storage |
Tavily, OpenAI, ElevenLabs, and S3 each sit behind a small adapter. Swapping a provider means changing that wrapper plus config (model names, voice IDs). SDK clients retry where supported; Tavily errors bubble up to pg-boss for job-level retry.
Two entities carry the app: a user has one PodcastFeed (their interests, chosen format, and cadence) and each scheduled run produces one PodcastEpisode. The feed is the standing subscription; the episode is a single dated issue of it.
The episode stores the topics, format, and cadence it ran with rather than referencing the live
feed, so editing the feed later doesn't change past episodes. Deletes are constrained per-relation
(cascade or restrict). Format and Cadence are reference tables (editorial style and
publishing schedule kept as data, not hard-coded enums), so a new style or cadence is a new row. The
episode's status is a persisted field that the UI reads.
Generation is schedule-only: each feed's cadence drives a recurring job, and a feed produces episodes only when that schedule fires. One job produces one episode end to end, running four stages in sequence and advancing the status at each: gather news (Tavily, scoped to the cadence) → write the script (OpenAI) → synthesize audio (ElevenLabs) → upload the MP3. The payload carries only the feed id; the feed's preferences are snapshotted onto the episode on its first scheduled fire (see Data model).
Why one job owns the whole pipeline. The stages are a strict sequence and one job maps to one episode, so a single job means no intermediate handoff state, no extra queues, and less coordination. For a low-volume, I/O-bound workload that simplicity is the right default (when it stops holding, see Known limitations).
Delivery is at-least-once, not exactly-once (the price of crash-safety), so a re-run is cheap and convergent rather than duplicative:
- The episode is keyed by
jobIdand the worker upserts on it, so a retry reuses its row (resetting aFAILEDone) instead of spawning a duplicate. - Reuse ladder: a retry skips work already done: a persisted script jumps straight to synthesis; already-linked articles skip the news search; only the failed stage re-runs.
- Audio is written to a deterministic key (overwrite, not orphan), and the key is persisted only after the upload succeeds.
The retry policy is explicit: a few attempts with backoff, plus a per-attempt expiry. That's the lease that lets another worker reclaim a job whose worker died. Tuning that expiry above worst-case synthesis is a known gap.
Empty news is a valid outcome, not a failure. If the window turns up nothing, the episode is
READY with no audio (the news stage only throws, and so retries, when every query fails).
On shutdown (deploys) the worker drains in-flight work before exiting, so an episode isn't killed mid-generation. That's an optimization, since the queue would re-run an abandoned job anyway, and a transient crash self-heals the same way (the lease expires and the job re-runs). Repeated crashes that exhaust retries are the gap a reaper would close.
Discovery and extraction are separate concerns: find recent, relevant URLs per interest, then pull clean article text from them. Provider-driven (Tavily) avoids per-site scrapers that rot when outlets change their markup. Tavily was the pragmatic choice over maintaining RSS plus per-site scrapers.
A multi-topic feed also runs one combined query across all interests, to catch cross-cutting stories the per-topic searches miss. It helps for related interests and degrades to noise for unrelated ones, so it's a cheap extra pass, not relied on.
The weak link is ranking. Each query returns its own flat, provider-ranked slice; there's no single candidate corpus to score, so we can't rank on the axes we'd actually want: recency, source credibility, substance, spoken-narrative fit, diversity, de-duplication. Fixing that means over-fetching into a persisted, de-duplicated corpus and scoring that. See the article cache under Known limitations.
This is the "engaging" half of the product. The feed's format prompt is the authoritative editorial spec; a format-independent contract is layered on in code: ground every claim in the supplied articles, synthesize don't summarize (weave sources into a throughline, don't recite them), label each line's voice, spoken words only, return structured output the model is held to via a strict JSON schema (re-checked for non-empties in code). So a new format is a new row, but the production invariants stay fixed. One-voice and two-voice shows come from the same contract; the host/guest labelling maps to distinct synthesized voices.
Multi-voice stitching is offloaded to the provider's text-to-dialogue flow: it voices each turn into one natural take rather than us concatenating clips (a single-host show is the same path with one voice).
The script is synthesized in chunks (the provider caps characters per request), then re-encoded into one file rather than byte-concatenated. Concatenated independent MP3s have no single timeline, so a streaming player drifts on seek (seek to 7:00, land elsewhere); re-encoding gives a correctly seekable file, at the cost of a CPU pass and an encoder dependency in the worker.
Cost is the pinned constraint. Multi-voice dialogue is eleven_v3-only. ElevenLabs offers no
cheaper multi-speaker tier, and it's the dominant cost. Cutting cost means dropping dialogue:
render each turn single-voice with a cheaper model and stitch the clips ourselves, trading the
natural conversation for the saving. That's a deferred lever. Model and voices should ultimately be
admin-configurable, not pinned in code.
Playback is authorize-in-app, then redirect to storage. The app checks that the requester owns the episode, then redirects the player to a short-lived presigned URL; the bytes stream straight from storage (with range requests for seeking) and never round-trip the app server.
Saving settings upserts the feed's cadence into one recurring schedule keyed by feed, so changing cadence rewrites that schedule in place, with no create/update/delete branching. Each fire snapshots the feed's current settings, so the latest save shapes the next run. Schedules fire on wall-clock boundaries (predictable delivery, not "24h after you subscribed"); per-user time and timezone are future work.
Scheduling on save is best-effort: the feed write is the commit, a queue hiccup is logged, not fatal. Known gap: a user won't know if a schedule failed to register; a robust version reconciles out-of-band (ensure-on-read or a periodic sync).
At this volume the scaling problems are duplicate work, an expensive TTS stage, and many feeds firing on the same cron, not CPU headroom:
- Per-stage queues. Today one job holds a worker slot for the whole pipeline under a single concurrency knob, but the four stages are heterogeneous: each has its own latency, per-call cost, rate limit, and ideal concurrency. Splitting them lets each scale to its bottleneck: a wide pool for the fast/cheap stages, a small rate-limit-aware pool for TTS. Mostly job-payload wiring plus a shared dead-letter queue; no schema blocker.
- Sublinear cost in users. TTS dominates the bill, so the biggest lever is segment-level audio reuse: voice a shared story segment once (keyed on text + voice) and "2× users → 2× TTS spend" stops holding. The secondary lever is a persisted, de-duplicated article corpus reused across feeds.
- Scheduled thundering herd. Feeds fire on the same wall-clock boundaries; jitter each across a window and put a per-provider rate limiter in front of dispatch.
On the product side, the next step I'd take is listener feedback (thumbs on segments, skip/replay signals) fed back into article selection and script tone.
Smaller gaps, roughly in order:
- Queue expiry tuning — the per-attempt expiry is a best guess; once real synthesis durations are known, set it above worst-case so a long run isn't reclaimed and re-run concurrently (re-paying for synthesis).
- Crash reconciliation — repeated crashes that exhaust retries leave a row stuck in-progress,
because
FAILEDis written only when the handler throws, not when the process dies; a reaper that fails stale in-progress rows closes it. - No integration tests against live providers — orchestration is covered by mocked unit tests; nothing hits the external APIs in automated runs.
- No grounding/quality eval — the script contract instructs grounding but nothing verifies the output honors it, so quality is asserted, not measured. A fixed fixture (known articles → a generated episode) scored against a rubric (grounded claims, synthesis over recital, voice labelling, spoken-only), by hand first and with an LLM judge later, would make it measurable.
For production:
- Postgres: a managed instance; run migrations on release.
- Web + worker as separate tiers — independently scalable containers for fault isolation. The worker already drains in-flight jobs on shutdown, so deploys don't drop episodes mid-generation.
- Object storage: a managed S3-compatible bucket (a config change, not a rewrite).
- Secrets & config: a real secrets manager.
- CI/CD: build, test, and deploy pipeline.
- Security hardening — a managed identity provider for auth, login rate limiting, security headers, and dependency scanning.
- Remaining gaps: per-user timezones, shipped observability (logs/metrics/alerting), cost + rate-limit budgets at volume, and operational basics (backups, TLS, health checks).
I'd ship this as a flat monthly subscription: a personalized audio briefing on topics the listener chooses. Ads don't fit the economics: every episode is produced for an audience of about one at real TTS cost whether or not it's played, so there's no shared audience to sell against.
Marginal cost scales with episodes × audio minutes, not headcount. A scheduled feed bills TTS every period whether anyone presses play. The commercial problem is lowering cost per listened minute: reuse shared content where you can, cut the cost of each minute, and avoid producing audio nobody will hear.
That maps to code levers tied to the two numbers a subscription lives or dies on: retention and gross margin per active subscriber:
| Lever | Moves | How |
|---|---|---|
| Cheaper provider tiers + capped episode length | margin | voiced minutes are the bill, so a length budget is a dollar cap; pick the cheapest tier per paid call without hurting engagement |
| Segment-level audio reuse | margin | voice a shared story segment once; savings depend on how much content overlaps across feeds |
| On-demand / lazy synthesis for dormant feeds | margin / retention | defer audio for feeds with no recent plays; needs a confidence threshold and a fallback |
| Article ranking + script quality | retention | lead with what listeners actually finish; lifts listen-through before retention slips |
| Per-stage queues, jitter, rate limiting | both | isolate the flaky/expensive stage and smooth the cadence burst; protects delivery, trims re-synthesis |
Retention. Cohort retention (how much of a signup cohort is still active weeks later) and its inverse, churn. I'd define "active" behaviorally (recently played), so a quiet quitter shows up before they cancel. The inputs I'd watch: listened minutes per active sub, listen-through rate (the earliest content-quality signal), week-1 activation, and delivery success rate. Roll those up into a subscriber-base view: start + new − churned = active now.
Gross margin per active subscriber. What a subscriber pays minus what it costs to serve them. The inputs I'd watch: cost per listened minute (the number the levers above move), ARPU, cross-feed content overlap (sizes the reuse saving), and waste ratio (produced audio never played). Margin × retention gives unit LTV. I'd leave acquisition (CAC, LTV:CAC, payback) out. It's marketing/finance, has no code lever here, and this prototype has no source for it.
Where these live. An in-app dashboard ships at /dashboard. The
numbers are mocked, but the layout reflects what I'd actually track. In production, metrics like
these are multi-source (app, billing) and normally live in a BI tool (Looker, Metabase) over a
warehouse.