Projects Archive

Booklnk

Multi-tenant appointment booking backend for barbershops, gyms and consultants, built from scratch on NestJS and PostgreSQL. I owned the schema, the service layer and the full API surface.

Visit site
Booklnk

Category

Full-Stack

Year

2024

Duration

9 months

Team

3 engineers

Overview

  • Built the backend from scratch for a multi-tenant booking platform on NestJS and PostgreSQL — supporting barbershops, gyms, and consultants from a single codebase. Owned the schema design, service architecture, and the full API layer.
  • Integrated Kashier (Egyptian payment gateway) end-to-end: webhook ingestion, idempotent transaction validation, and reconciliation logic. Shipping payments is always messier than the docs make it look.
  • Slot validation and concurrent-booking prevention was the hardest part. Optimistic locking with a version field eliminates double-bookings without killing throughput.
  • Modelled multi-business-type scheduling with different slot rules, service durations, and staff availability — abstracted behind a polymorphic booking engine so adding a new business type is config, not code.

The problem

  • Booking platforms for Egyptian SMBs were either too generic with no local payment support, or industry-specific and impossible to adapt. Barbershops, gyms, and consultants all have fundamentally different scheduling rules but no shared infrastructure.
  • Concurrent booking was a real reliability problem — two customers hitting the same slot at the same millisecond was causing lost revenue for pilot businesses.

The solution

  • Designed a multi-tenant schema where each business type extends a shared booking core. Table inheritance in PostgreSQL keeps queries fast and adding a new business type costs zero migration risk.
  • Implemented optimistic locking on the slot reservation table — each row carries a version counter. Concurrent requests compare-and-swap; the loser retries. Eliminated 100% of double-bookings under load testing.
  • Built a Kashier webhook pipeline with idempotency keys — every incoming event is deduplicated before processing, so network retries never create phantom transactions. Reconciliation runs nightly and flags mismatches.
  • Exposed a clean REST API with role-based guards (business owner vs customer vs staff) using NestJS guards + JWT. Dockerised the full stack for reproducible deploys.

Decisions & trade-offs

Optimistic locking for slot reservations

Each slot row carries a version counter. Concurrent bookings compare-and-swap, and the loser retries, so no lock is held while a customer is mid-booking. Load tests showed zero double-bookings. The cost: under heavy contention for one slot, retries pile up. It works because two customers rarely race for exactly the same slot.

Idempotency keys on payment webhooks

Payment gateways retry webhooks. Every incoming Kashier event is deduplicated by an idempotency key before processing, so a retry can never create a second transaction. The cost: keys have to be stored, and kept long enough to cover the gateway’s retry window.

PostgreSQL table inheritance for business types

Barbershops, gyms and consultants each extend one shared booking core, so adding a business type means a new child table rather than a risky change to the shared one. The cost: PostgreSQL does not carry unique constraints or foreign keys from the parent to its child tables, so each child has to declare its own.

Outcomes

  • Zero double-bookings since optimistic locking shipped across all pilot businesses
  • Kashier integration handles Egyptian card payments, Meeza, and Fawry with full webhook reliability
  • Multi-tenant architecture supports 3 business types from a single deployed instance
  • New environment spins up in under 2 minutes with Docker + CI
  • API documented end-to-end with Swagger — onboarded two frontend devs with no back-and-forth.

My role

Backend Engineer

JavaScript, TypeScript, Node.js, NestJS, Docker, PostgreSQL

Gallery