DEV Community

Cover image for Why we chose Bun
Christopher Ribeiro for Alertpix

Posted on • Edited on

Why we chose Bun

At Alertpix we allow streamers to receive donations from their audience via Pix Instant Payment and show an alert on the live stream.

I was eyecatching Bun for a long time. And while developing the initial version of the platform the excitement to use it when it was more stable was really high.
And when 1.0 reached, I knew it, our real time system should be written in Bun.

No common js or esmodules madness

Our API is in node. And God, how I suffered to import nanoid in an esmodule project. I had to vendor it, since using a previous version was not ideal.
With bun, we can no longer worry about that. Just import what you need and done.

import fs from "node:fs"
const path = require("node:path")
Enter fullscreen mode Exit fullscreen mode

TypeScript ou of the box

We all know that TS is just a linter, so we need it as the project grows right?
That feeling when the auto complete works, hits different.
But the struggle to setup TypeScript in nodejs is a pain.

Well, with Bun, its no longer an issue anymore. It just works.

Fast startup times

Oh boy, while developing Alertpix, I was relying solely on using cloud environments since my laptop was in repair.
I can count how many hours I wasted waiting node to sync the changes (I'm talking about you Next, you are slow even on high end machines) in these cloud enviroments. When switched to Bun, everything felt fast.

Buildless deployment

Our realtime service needs to be deployed as fast as possible.
It means that, the time to identify a bug in production, fix the issue, commit and run de CI deployment should be small.
And we know that, even cached, deployments are slow because of the build step. The bigger the project, the more time it takes.

Since bun runs TypeScript without a build step.
In summary, our container pulls Bun, install the packages, copies the needed files and runs the code with Bun:

FROM oven/bun

WORKDIR /app

COPY package.json .
COPY bun.lockb .

RUN bun install --production

COPY src src
COPY tsconfig.json .

ENV NODE_ENV production
CMD ["bun", "src/index.ts"]

EXPOSE 3000
Enter fullscreen mode Exit fullscreen mode

Pub Sub is easier

Our real time system is a pub sub on top of websockets.
And it is so easy to do, that we already covered it in this post


Alertpix

Top comments (1)

Collapse
 
iagocavalcante profile image
Iago Angelim Costa Cavalcante

Awesome!