← all posts

Bun + Elysia after six months in production

TypeScriptBun

Six months ago I put a Bun + Elysia service into production: yun-stream, a backend that scrapes several streaming providers behind one clean contract and feeds a TV client. Here’s the honest report — what earned its place, what I’d change, and why I’m still happy with the bet.

The one design decision that mattered

Everything good about this codebase traces back to a single interface. Each provider is scraped differently, breaks differently, and changes its HTML on a different schedule. Left unchecked, that becomes five bespoke tangles. One shared contract keeps them honest:

interface IProvider {
  readonly id: string;
  search(query: string): Promise<SearchResult[]>;
  details(id: string): Promise<Media>;
  streams(id: string): Promise<StreamLink[]>;
}

The router never knows which provider it’s talking to. It knows there is a provider that can search and return StreamLink[]. When a provider’s site changes and its scraper rots, exactly one file changes, and the type checker tells me the moment a provider stops honoring the shape. Five scrapers, one silhouette. That discipline is the whole architecture.

Put a TTL cache in front of everything slow

Scraping is slow and the upstreams are rate-limited, so a small in-memory cache with a time-to-live sits in front of every provider call. Not Redis — I didn’t need another moving part for a service that fits in one process. Just a map with expiry:

class TTLCache<T> {
  private store = new Map<string, { value: T; expires: number }>();
  constructor(private ttlMs: number) {}

  get(key: string): T | undefined {
    const hit = this.store.get(key);
    if (!hit) return undefined;
    if (Date.now() > hit.expires) { this.store.delete(key); return undefined; }
    return hit.value;
  }

  set(key: string, value: T) {
    this.store.set(key, { value, expires: Date.now() + this.ttlMs });
  }
}

Wrap each provider call in cache.get(key) ?? await fetchAndCache(key) and the p95 latency drops off a cliff, while the upstreams stop rate-limiting me. It’s twenty lines and it’s carried the service for six months. I have a whole separate post’s worth of opinions about not reaching for Redis too early, but the short version is: measure first, most services never outgrow a map.

What Bun and Elysia got right

  • Startup and iteration speed. Cold start is effectively instant, and bun --watch reloads faster than my eyes can move to the browser. On a scraper you redeploy constantly, so this compounds.
  • Batteries included. Test runner, bundler, and TypeScript execution all ship in the runtime. My package.json has a fraction of the dev dependencies it used to.
  • Elysia’s type inference. Its schema-to-type flow means my route handlers know the shape of validated input without a manual generic in sight. It’s the closest a JS framework has felt to just describing the data.

Where I got bitten

It wasn’t all clean. Two things cost me real time:

  • Ecosystem edges. Every so often an npm package leaned on a Node API Bun hadn’t fully implemented yet. It’s rare and getting rarer, but when it happens you lose an afternoon confirming it’s not your code. Always check the Bun compatibility notes before you commit to a heavy dependency.
  • “It works on Node” muscle memory. A couple of subtle differences in stream and buffer behavior meant a copy-pasted snippet from a Node answer didn’t behave identically. Not bugs in Bun — just a reminder it’s a different runtime, not a drop-in.

Would I pick it again?

For this shape of service — a small, fast, self-contained backend I redeploy often — yes, without hesitation. The speed is real and the developer experience is genuinely nicer than the Node setup it replaced.

Would I put a bank’s core ledger on it tomorrow? No. But that was never the question.

The right tool is the one that fits the job and the blast radius. For a scraping proxy with a pluggable provider contract and a TTL cache doing the heavy lifting, Bun + Elysia has been a quietly excellent choice. Six months in, it hasn’t once made me wish I’d gone back.

— Abu more posts →