Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building a race-safe booking engine on Cloudflare Workers + D1 (no ORM, no date library)

I run a small booking system for shops in Malaysia: barbers, car washes, massage therapists. Each shop gets one link, and customers pick a service, a staff member, a day and a time. It runs entirely on Cloudflare Workers + D1 with Hono , and the whole app is about 1,700 lines of TypeScript. Here are the four parts that took the most thought, with the actual code. 1. "Today" in the business's time…

Building a race-safe booking engine on Cloudflare Workers + D1 (no ORM, no date library)

The author runs a small booking system for shops in Malaysia, offering services like barbers, car washes, and massage therapists. Each shop has its own unique URL, and customers select a service, staff member, day, and time slot. The entire app is written in TypeScript and consists of about 1,700 lines of code. The author uses Cloudflare Workers and D1 (SQLite) to build this system.

1. Handling time zones with the Intl API

The challenge arises when a shop in New York and a shop in Kuala Lumpur need to know which time slots are available on a specific day. The Intl API in Workers can handle this requirement without needing an additional date library.

2. Pure function for checking slot availability

The slot engine is a pure function that takes the following parameters: open time, close time, duration, and staff IDs. It iterates through possible time slots, checking if a given slot is within the range and if the slot is available. For a specific day, the function performs up to 31 calls, which is fast enough to avoid the need for caching.

3. Preventing double bookings with SQLite's id-based race condition handling

Due to SQLite being used as the database, requests can't hold a transaction open between checking and inserting a new booking. To prevent race conditions and double bookings, the author inserts the new booking first and then checks if any overlapping bookings exist. If an overlap is found, the newly inserted booking is updated with a 'cancelled' status, and the original booking remains active. This approach ensures that the booking with the lower ID takes precedence, eliminating the possibility of double bookings.

4. Stripe integration without using the Stripe SDK

The author uses plain fetch requests to make Stripe API calls instead of using the official Stripe SDK. This approach results in smaller code size and easier readability, which is ideal for a simple booking engine. The author handles a Checkout Session and a webhook using this method.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Also reported by 1 other outlet

Read the original at dev.to →

More in Tech

Prisma Accelerate Retires December 1: A SaaS Migration Guide

Prisma Accelerate has a shutdown date. Prisma's October changelog confirms that Accelerate is retired on December 1, 2026, and that includes hosted Accelerate connections to Prisma Postgres.

  • Prisma Accelerate retiring on December 1, 2026
  • Pin Prisma version to 7, replace Accelerate URL, test changes, maintain rollbacks

A 31-character name froze this Node server for 6 seconds

Here's a signup check. A display name is words with single spaces between them. const NAME_RE = /^ (\w + \s?) *$/ ; "Ada Lovelace" passes. "Linus" passes. Each request takes about 3 ms.

  • Node server freezes for 6 seconds
  • 31-character display name causes issue
  • Regular expression leads to backtracking

Lighting the Skies

  • Mechanical devices once believed key to ending WWI in US favor.
  • Radar, not nuclear weapons, more crucial in WWII aerial combat.
  • Searchlights, since 1806, provided reliable battlefield lighting.

More from Saturday 7 November →