# Solving Dynamic Scheduling for Frappoint

Scheduling appointments in businesses can quickly become complex. Different services take *different amounts of time,* *multiple providers* offering the same service may have varying ***availability***, and managing ***overlapping bookings*** can be a nightmare.

While building **Frappoint**, this was the hardest challenge I had to overcome. Instead of defining static duration’s for every available service and provider, I needed scheduling to be “*alive*” to ***adapt*** whenever new services, providers, or resources were added. I wanted the system to **evolve** with changes instead of freezing or breaking down.

## The Problem

* Services have different duration’s ( e.g., haircut (30m) vs. hair treatment (60m)).
    
* Providers have **individual schedules** and varying services they offer.
    
* Logical Resources to be used when offering the service (e.g., clippers, massage tables).
    
* Avoiding the possibility of double-booking is critical.
    
* Reducing manual scheduling to reduce manual errors and overhead

Traditional scheduling approaches (static tables and manual blocks) weren't flexible enough. I needed a system that could **dynamically calculate availability** in real-time.
    

## Introducing Slots

The concept that helped me crack this problem was simple but powerful: **slots**.

Think of them as *dynamic time units* that combine:

1. **Service Durations** - Every service has a duration,  which for me I went with a uniformity of minutes
2. **Provider Allocation** - Each provider has a timeline (e.g.,  Shift 9 AM - 5 PM) and a set of services they can perform.
3. **Service Unit / Resources** - Logical shared resource for performing the service (Clippers for haircut and such)

Combining these three we get a **slot**, a bookable time unit.

*It defines when the service can be performed, who can perform the it and what resources are required.* 

These slots are then split into *chunks* of (10, 15, 30 mins depending on your setup) that can be **combined into a single booked unit** for a client. This approach ensures:

- Providers are never double-booked.
- Resources are allocated efficiently.
- Availability automatically adapts as services or providers are added or removed.


## How It Works in Practice

Imagine a haircut service (30 minutes) offered by Jane and John:

| Provider | Service | Duration | Available Slots |
| -----------------------------------------------|
| Jane | Haircut | 30 min | 9:00, 9:30, 10:00... |
| John | Haircut | 30 min | 10:00, 10:30, 11:00... |

*Jane and John's slots are calculated dynamically*, so if Jane is already booked at **9:30** that slot disappears from the list of available bookings. 

## Lessons Learned

Working on this feature taught me to:
* **Think in units of time, not just appointments.** Breaking schedules into slots to make everything more flexible.
* **Separate concerns.** Services, providers, and resources each have their own logic. 
