Case Study

Fade & Co. — multi-barber booking with a race-safe scheduler

A three-chair barbershop that takes online bookings, including natural-language requests and deep links from the storefront. The non-trivial part isn't the form — it's making sure two people can never book the same chair at the same time, in the shop's timezone rather than the server's.

Role
Solo — design, engineering, documentation
Stack
Next.js 15 · Supabase Postgres + btree_gist · Groq / Gemini · Resend · Vercel · Unsplash
Timeline
8 days — 6 engineering layers, then 3 visual phases
Try the live demoView source
Fade & Co. landing page — cinematic barbershop photograph under a serif headline
Cinematic hero — one photograph, one overlay, one serif headline.

1. The problem

Small barbershops need online booking. The hard part isn't the UI — it's correctness. Two people clicking the same slot at the same moment is a race condition, and a naive “is this slot free?” check loses it silently: both requests read “free” before either writes, and one customer turns up to a double-booked chair.

Shop-local time is the second trap. The server runs on UTC, the shop runs on Asia/Kuala_Lumpur, and every conversion between the two is a place to be off by a day. I made timezone a first-class concept in a single module instead of scattering conversions through route handlers.

The third is combinatorial. Not every barber offers every service — Priya does hot-towel shaves, Sam does not — so a slot list is wrong the moment you forget to filter it by the pair. Get any of these wrong and the booking is still accepted; it just isn't possible.

2. How it works

The customer picks a service and a barber. The frontend asks for slots; the server computes them from hours, existing bookings, and time-off with a pure function. The customer picks a time and posts the booking. The database itself enforces the race safety, and a confirmation email fires in the background.

  1. Customer picks service and barber
  2. →↓GET /api/slots
  3. →↓computeAvailableSlots(hours, busy, timeoff)
  4. →↓Slot list
  5. →↓POST /api/bookings
  6. →↓Exclusion constraint enforces
  7. →↓201 or 409
  8. →↓Confirmation email

One predicate runs everywhere — the algorithm, the constraint, and the time-off check all use half-open intervals:

// Same convention in the algorithm and the constraint:
// overlap  ⟺  aStart < bEnd && aEnd > bStart
// tstzrange(..., '[)')  ⟺  half-open, no off-by-one

There is a second entry point into the same wizard: type “fade with Sam Saturday afternoon” into the box above it and a model returns a structured intent — service, barber, day, time, and a confidence score. Groq openai/gpt-oss-120b answers with temperature: 0 and Gemini is the fallback when it returns nothing usable. The UI shows the parse back to you before the slot list rather than jumping straight to times, and falls back to the plain wizard when confidence is low. That is the whole feature: it proposes, it never decides.

3. Technical decisions

Race safety is a DB constraint, not an app check.

Every junior dev writes if (slot is free) { insert }. That's a check-then-act bug under concurrency. The correct primitive is an exclusion constraint — Postgres refuses the second insert at the storage layer, no matter how the requests interleave. The app catches error code 23P01 and returns a friendly 409.

constraint fade_appointments_no_overlap
  exclude using gist (
    barber_id with =,
    tstzrange(starts_at, ends_at, '[)') with &&
  ) where (status != 'cancelled')

Half-open intervals everywhere.

[start, end) in the constraint, in the availability algorithm, and in the time-off overlap check. Two conventions that don't match produce phantom one-second overlaps: a 10:00 booking ending at 10:30 must not block a 10:30 start. Same predicate on every path.

The direct-POST bypass.

/api/slots only returns what the algorithm considers valid. But nothing stopped a client from POSTing any time directly — a 3 AM slot, an off-grid :07 start. I only caught this in code review, after the route already worked. The fix was a shared server-side validator that re-checks the requested time against the barber's hours before insert. Client filters are UX; server validation is correctness.

waitUntil for the confirmation email.

The booking POST returns in ~300ms; the email fires after. On Vercel, a floating promise dies when the response is sent — the exact bug I'd already hit on an earlier project. waitUntil from @vercel/functions extends the function lifetime until the send settles. The sender returns a boolean and never throws, so email can never break a booking. The waitUntil path is exercised against the local server; confirming delivery to a production inbox is still open.

Deep-linkable booking.

/book?barber=sam&service=fade preselects both and advances to the slot picker. Every service row and barber card on the landing page links through, so the booking flow is one URL param away from any marketing surface. The first version built the link and then ignored the param entirely — the barber card said “Book with Sam” and landed on a blank service list. Fixed in phase 3, along with the case where a deep-linked barber doesn't offer the chosen service.

Physical materials without photography we don't have.

Fade & Co. is a fictional shop. No real haircuts, no real barbers, no real interior. The solution was a small curated set of Unsplash photographs for the hero and the portraits, and hand-drawn SVG accents where stock imagery would be too obviously borrowed. Eight photographs ship as WebP with a JPEG fallback, every one credited in public/CREDITS.md. The whole thing is documented as a portfolio piece rather than dressed up as a real business.

Services listed as a printed menu with dotted leaders and right-aligned prices
Services as a printed menu — leaders, prices, no boxes.
Three barber portraits with names, roles, and service pills
Three barbers, photographed. Roles and specialities underneath.
About section on matte black with an offset interior photograph
Matte black, gold accent. The dark chapter.
Three five-star review cards on matte black, with gold stars and gold rules
Five-star cards on matte black, gold rules. Same palette as the admin.

4. The visual system

Fade & Co. needed to feel like a neighborhood barbershop, not a SaaS dashboard. SupportAI and LeadFlow both live in the same dark-zinc-and-indigo world; giving Fade & Co. the same palette would have made three projects feel like one design with three names. So: cream storefront (Instrument Serif, warm ivory base, brass accent), matte black and gold for the dark interior sections (About, Reviews), and the admin on the same dark palette — so the shop and its back office feel like one building.

The typography pairing is Instrument Serif for display — headlines, section titles — and Inter for body, with Geist Mono for every number, price, time, and reference code. The serif carries the heritage; the mono carries the precision.

Structurally, three phases added an announcement bar with a session dismiss, a trust strip, real photography for the hero and the portraits, the printed-menu services layout, the dark About and Reviews chapters, a booking flow with slide transitions and a success screen, and a mobile sticky CTA. The whole build was three phases over eight days; the details are what make it feel like a real shop.

5. The booking flow

A booking flow has three states users actually care about: choosing a slot, seeing it confirmed, and not having to think about it again. Everything else is intermediate. The wizard has four steps — service, barber, slot, confirm — the steps slide horizontally between each other, and the progress indicator shows completed, current, and upcoming states in brass.

The success screen is a small thing that matters. A reference code in mono with a copy button, the full booking summary, and an .ics download so the appointment lands in the user's calendar without retyping the details. Building the calendar file surfaced a real bug: the timestamps were emitted without the Z designator, which makes an RFC 5545 date-time a floating local time. A 12:00 booking in Kuala Lumpur opened at 04:00. This is what separates a demo from a product — the small courtesies.

The concurrency test fires two POST /api/bookings calls in the same tick via Promise.all, then asserts exactly one 201 and one 409 and that the database contains exactly one row for the slot. It passes against the local server and against the deployed URL. The database doesn't care where the request came from — the constraint is the constraint.

response A: 409 {"error":"slot_taken","message":"That slot was just taken. Please pick another time."}
response B: 201 {"ok":true,"reference_code":"FC-20261006-0005",...}
✅ Exactly one booking succeeded (ref: FC-20261006-0005)
✅ Second request rejected with 409 slot_taken
✅ DB has exactly 1 non-cancelled row for slot 2026-10-06T01:00:00.000Z
✅ Winning appointment cleaned up
PASS
Booking wizard on the barber step, progress indicator showing completed, current, and upcoming
Four steps, slide transitions, brass progress.
Booking confirmation with a checkmark, reference code, and booking summary
Reference code, full summary, .ics download.

6. What I'd do differently

  • Customer-facing cancellation. v1 has admin-only cancel. The customer path is a two-click flow through an email link with a signed token — deliberately deferred, but it's the first thing a real shop would ask for.
  • Time-off management is a shared calendar, not a form. A shop with three barbers coordinates time off constantly. v1 treats it as per-barber blocks. A month grid where the owner drags across barbers is the right UX.
  • Rate limiting is a Map, not Redis. Same trade-off as the earlier projects — fine for a demo, wrong for production. Upstash Redis with a sliding window.

7. Under the hood

First Load JS
116 kB on /
route JS 4.54 kB · this page 177 B / 111 kB
Commits
13 · 8 days · 3 visual phases
Size
9,263 lines / 85 files
app/ lib/ components/ scripts/ — *.ts and *.tsx only, excl. the generated UI kit
Stack
Next.js 15 App Router · Tailwind v4 · shadcn/ui (Base-UI) · Supabase Postgres + btree_gist · Groq / Gemini · Resend · Vercel
Cost
Zero paid tools
Supabase, Groq, Gemini, Vercel, Resend, GitHub — every service on a free tier. Unsplash photos used under the Unsplash License.
Admin today view with three barber columns, confirmed badges, and free-window blocks
The admin on the same matte black + brass as the dark storefront sections.

Built by Darvin Raj

Fade & Co. is a fictional barbershop. This is a portfolio piece — no real customers, no real bookings.

← Back to Fade & Co.