← Work Case study · November 2026

A barbershop booking site that can’t double-book: Astro inside one Durable Object

BonsCut is a barbershop in Bali. Its site shows each barber’s free hours for the week, takes bookings in English and Russian, and gives the shop an admin with a calendar, shifts, clients and stats. Everything except the static files runs inside a single Cloudflare Durable Object with SQLite. That one decision is why two clients can never book the same slot, and why the booking code stays plain and synchronous.

The BonsCut barbershop website, with its free-times board and booking button
bonscut.com

What the shop needed

  • A first screen that sells the shop: the sign, a short video of the room, the price list in the style of their printed one.
  • A “Free times” board: the days of the week, and under each one every barber’s day by the hour. A free hour links straight into booking.
  • Booking in four steps: service, barber (or “any barber”), date and time, then name and phone or WhatsApp. After booking the client gets a link to see the booking, add it to a calendar or cancel it.
  • An admin for the front desk: calendar by barber, bookings with search, shifts and days off, services and prices, clients with history and notes, a gallery, and stats.
  • Alerts in the staff Telegram group, email confirmations and reminders for clients.
  • Local rules: prices in rupiah, the Asia/Makassar time zone, and phone numbers that work whether a local types 0812… or a tourist types their own country code.

The architecture

One Worker, one Durable Object, and Cloudflare’s static asset server.

  • Photos, scripts and fonts are served straight from Cloudflare’s edge.
  • Every other request goes to one Durable Object named “Shop”. It holds the SQLite database and renders the Astro pages itself.
  • Two cron triggers call into the same object: one every five minutes, one once a month.
export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    if (url.pathname.startsWith('/video/')) return video(request, env);
    return env.SHOP.get(env.SHOP.idFromName('bonscut')).fetch(request);
  },
  async scheduled(controller, env) {
    const shop = env.SHOP.get(env.SHOP.idFromName('bonscut'));
    if (controller.cron === '0 4 1 * *') await shop.monthly();
    else await shop.everyFiveMinutes();
  },
};

Why the whole app lives in a Durable Object

A booking system has one hard rule: the same barber can’t be booked twice for the same minutes. The usual answers are row locks, unique constraints across time ranges, or a queue.

A Durable Object gives you a simpler one. Its SQLite database is synchronous, and our booking function never awaits anything between “is this slot free?” and “insert the booking”. Inside one object, no other request can run in that gap. The check and the insert sit in one transaction, and there is nothing to lock.

The price is location. All page renders go to one object in one place. From Bali, the HTML takes 0.5 to 0.75 seconds to start arriving, against 0.17 seconds for a static image from the edge. For one shop that is fine. For many shops you would give each shop its own object with idFromName(shopSlug).

One database, two homes

On Cloudflare the code talks to the Durable Object’s SQLite. On a laptop the same code opens a file with node:sqlite, so tests, scripts and the dev server use the real schema and the real queries.

interface Backend {
  all(sql: string, params: Param[]): unknown[];
  run(sql: string, params: Param[]): { changes: number; id: number };
  exec(sql: string): void;
  transaction<T>(fn: () => T): T;
}

Both backends are synchronous. One difference bit us: a Durable Object can’t set PRAGMA user_version, so on Cloudflare the schema version lives in a one-row table, and migrations run inside transactionSync.

Finding free times

Free start times come from one small function: walk the working day on a fixed step and keep every start where the visit fits before closing and doesn’t overlap a booking.

export function freeStarts(work, busy, duration, step, notBefore = 0) {
  if (!work) return [];
  const out = [];
  for (let t = work.start; t + duration <= work.end; t += step) {
    if (t < notBefore) continue;
    if (busy.some((b) => t < b.end && t + duration > b.start)) continue;
    out.push(t);
  }
  return out;
}

Around it:

  • “Any barber” gives the visit to whoever has the fewest booked minutes that day.
  • A lead time keeps people from booking a slot that starts in ten minutes, and a horizon limits how far ahead they can book.
  • Fake bookings are capped. One client can hold at most three upcoming online bookings, and requests are rate-limited per IP address (per /64 for IPv6).

Reminders and summaries on a cron

Every five minutes the Worker asks the object to send due reminders. Each reminder is claimed before the email goes out and released if the email fails, so a slow run never sends the same reminder twice, and a failed one is retried next time.

The same job posts the day’s summary to the staff Telegram group once a day. Once a month the object erases clients who haven’t visited for three years, which is what the privacy policy promises.

Email without an email provider

The shop sends email from its own Gmail. The site posts each letter to a small Google Apps Script web app with a shared secret, and the script sends it with MailApp. A free Gmail account can send to 100 recipients a day this way, which is far more than one shop needs.

Staff alerts go to Telegram instead. By default they carry the time and a link to the admin, not the client’s name and phone, because that would hand personal data to a third party.

The Safari video gotcha

Cloudflare’s static asset server answers a byte-range request with the whole file. Safari won’t play a video without a proper 206 Partial Content answer, so left alone, the hero video wouldn’t play in Safari. The Worker answers range requests itself. The clips are under 2 MB, so it reads the whole file and returns only the requested bytes.

const start = m[1] ? Number(m[1]) : Math.max(0, size - Number(m[2]));
const end = m[1] && m[2] ? Math.min(Number(m[2]), size - 1) : size - 1;
out.set('content-range', `bytes ${start}-${end}/${size}`);
return new Response(body.slice(start, end + 1), { status: 206, headers: out });

Speed

There is no client-side framework. Booking is one TypeScript file, and the admin charts are SVG drawn on the server.

The home page still scored only 90 to 95 in our own Lighthouse runs, under the 95 we promise in writing. Three changes fixed it:

  • CSS is now inlined into each page, so the first screen doesn’t wait for stylesheet requests.
  • The hero poster is preloaded ahead of the fonts.
  • The English page no longer downloads the Cyrillic font just for the two words “Русская версия”.

PageSpeed Insights on mobile now gives the home page 99, with the largest element on screen at 2.0 seconds.

What we’d do next

The remaining cost is the trip to the Durable Object for every page view. Caching the public pages at the edge for a minute would cut it, at the price of a free-times board that can be a minute old. The booking step checks the slot again anyway, so a stale board can’t cause a double booking.

Want booking like this on your site?

See prices, or tell us about your shop.