{
  "id": 18627559,
  "title": "Building a race-safe booking engine on Cloudflare Workers + D1 (no ORM, no date library)",
  "url": "https://urgent.news/2026/11/07/building-a-race-safe-booking-engine-on-cloudflare-workers-d1-no-orm",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-07T03:34:40.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/rasareka/building-a-race-safe-booking-engine-on-cloudflare-workers-d1-no-orm-no-date-library-258a"
  },
  "original_language": "en",
  "account": "Building a race-safe booking engine on Cloudflare Workers + D1 (no ORM, no date library)\n\nThe 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.\n\n1. Handling time zones with the Intl API\nThe 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.\n\n2. Pure function for checking slot availability\nThe 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.\n\n3. Preventing double bookings with SQLite's id-based race condition handling\nDue 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.\n\n4. Stripe integration without using the Stripe SDK\nThe 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.",
  "summary": "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…",
  "key_points": [
    "Utilizes Intl API for time zone handling without date library",
    "Implements pure function for slot availability checks",
    "Prevents double bookings using SQLite's id-based race condition handling"
  ],
  "editors_take": "Prioritizing minimal dependencies and native APIs over heavy libraries reduces codebase complexity and optimizes performance for lightweight, edge-based applications serving diverse global time zones.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}