📣The December 13th release is out!Read the release notes

    An astronaut taking some a loaf of bread out of the oven.

    Triplit x Bun

    TLDR

    We build an experimental Triplit server in Bun and Hono, and upgrade the Starter plan for Triplit Cloud.

    Triplit runs on Bun (and Hono)

    This week we've been experimenting with running the Triplit syncing server in Bun and writing a storage adapter for bun:sqlite. Our experiments were successful! We're still working on testing this in production to see if there's a noticeable difference in performance over Node. If you'd like to play around with it yourself, you can run the associated Docker image. The guide on self-hosting Triplit remains unchanged.

    While working on this, we built a Hono app to encapsulate the Triplit syncing server. We're fans of Hono because of its simple, portable and adheres to web standards. Hono is a great choice if you're interested in building a custom server that expands on Triplit, or if you want to run Triplit in one of the environments that Hono supports (e.g. Deno or Cloudflare Workers.). Here's an example of how we used our Hono app to build the Bun server in 19 lines of code:

    import { createBunWebSocket } from 'hono/bun';
    import { createTriplitHonoServer } from '@triplit/server';
    
    const { upgradeWebSocket, websocket } = createBunWebSocket();
    
    const honoServer = createTriplitHonoServer(
      { storage: 'bun-sqlite' },
      upgradeWebSocket
    );
    
    const port = +(process.env.PORT || 8080);
    
    const bunServer = Bun.serve({
      fetch: honoServer.fetch,
      websocket,
      port,
    });
    
    console.log(`Listening on http://localhost:${bunServer.port} ...`);
    

    In most cases, running the Triplit server on a different platform is just a matter of using the appropriate upgradeWebSocket method from Hono. Adding additional routes or middleware is as simple as invoking the methods on the honoServer object.

    import { createBunWebSocket } from 'hono/bun';
    import { createTriplitHonoServer } from '@triplit/server';
    
    const { upgradeWebSocket, websocket } = createBunWebSocket();
    
    const honoServer = createTriplitHonoServer(
      { storage: 'bun-sqlite' },
      upgradeWebSocket
    );
    
    // add your own routes or middleware
    honoServer.get('/my-route', (c) => {
      return c.text('Hello World');
    });
    

    A better Starter plan for Triplit Cloud

    We're upgrading our Starter plan, including the free trial, to include more memory by default, with no increase in price. We found that after accounting for the operating system and Javascript engine, 1GB gave a more reasonable amount of space for Triplit to manage WebSocket connections and caching.

    Bug fixes and improvements

    There's a lot of small improvements to mention this week:

    • Visual tweaks to the Triplit console that should make it easier to use on smaller screens.
    • More error messages in the Triplit console for data mutations that fail when synced with the remote server.
    • Updated docs for Schema type helpers
    • More helpful error messages when referencing a variable in a permission filter or query filter that doesn't exist.
    • Fixed a bug where a query with a select(['id']) clause would return an empty object instead of the expected id field.