Prompt
Appointment booking API with round robin routing
Latest observation
Oct 16, 2026
OpenAI APIWeb search: off
Here’s a solid design for an appointment booking API with round-robin routing for assigning bookings to providers/agents/staff.
1) Core idea
When a new appointment request arrives, the system should:
- Validate the request
- Find the eligible providers/resources
- Select the next provider using round robin
- Create the appointment
- Return the assigned provider and booking details
2) Typical entities
Customer
idnameemailphone
Provider
idnamestatus(active,inactive)service_typestimezone
Appointment
idcustomer_idprovider_idservice_typestart_timeend_timestatus(booked,cancelled,completed)created_at
RoundRobinState
Tracks where the next assignment should go.
idqueue_key(e.g."haircut:nyc","support","default")last_assigned_provider_idupdated_at
3) Example API endpoints
Create booking
POST /appointments
Request
{
"customer_id": "cust_123",
"service_type": "consultation",
"start_time": "2026-10-20T10:00:00Z",
"duration_minutes": 30
}
Response
{
"appointment_id": "apt_456",
"customer_id": "cust_123",
"provider_id": "prov_789",
"service_type": "consultation",
"start_time": "2026-10-20T10:00:00Z",
"end_time": "2026-10-20T10:30:00Z",
"status": "booked"
}
Get appointment
GET /appointments/{id}
Cancel appointment
POST /appointments/{id}/cancel
List available providers
GET /providers?service_type=consultation
4) Round robin selection logic
A simple version:
- Fetch all active eligible providers for the requested service
- Sort them consistently by
idorcreated_at - Find the provider after
last_assigned_provider_id - If at the end, wrap around to the first provider
- Save the new
last_assigned_provider_id
Pseudocode
def select_next_provider(queue_key, eligible_providers):
state = get_round_robin_state(queue_key)
providers = sort_by_id(eligible_providers)
if not providers:
raise Exception("No providers available")
if state is None or state.last_assigned_provider_id is None:
chosen = providers[0]
else:
ids = [p.id for p in providers]
if state.last_assigned_provider_id in ids:
idx = ids.index(state.last_assigned_provider_id)
chosen = providers[(idx + 1) % len(providers)]
else:
chosen = providers[0]
update_round_robin_state(queue_key, chosen.id)
return chosen
5) Important production considerations
A. Concurrency
Two bookings can arrive at the same time and select the same provider if state is not protected.
Fix:
- Use a DB transaction
- Lock the round robin state row (
SELECT ... FOR UPDATE) - Or use Redis with atomic operations
B. Availability checks
Round robin should only choose providers who are actually free.
Check:
- working hours
- existing appointments
- blackout periods
- provider status
C. Fairness
If a provider is unavailable, skip them and continue round robin to the next eligible one.
D. Multi-tenant / queue-based routing
You may want separate round robin sequences for:
- each service type
- each location
- each team
- each tenant
Use a queue_key like:
tenant_1:consultation:nycsupport:level1
6) Example workflow
- Client calls
POST /appointments - API validates input
- System gets eligible providers for
consultation - Round robin state says last provider was
prov_2 - Next eligible provider is
prov_3 - Appointment is created for
prov_3 - State is updated to
prov_3
7) Suggested database approach
Table: providers
id | name | status | service_type
Table: appointments
id | customer_id | provider_id | service_type | start_time | end_time | status
Table: round_robin_state
queue_key | last_assigned_provider_id | updated_at
8) If you want a more scalable design
Use:
- PostgreSQL for booking data
- Redis for round robin counters/state
- message queue for async notifications
- distributed lock for safe assignment under load
9) Edge cases to handle
- No eligible providers
- Provider becomes unavailable after selection but before booking commit
- Appointment conflicts
- Cancelled bookings shouldn’t break sequence unexpectedly
- Provider removed from rotation
- Rebalancing when providers are added/removed
10) Minimal implementation pattern
Booking transaction
- Start transaction
- Lock round robin state
- Query eligible providers
- Pick next provider
- Verify provider availability again
- Insert appointment
- Update round robin state
- Commit
If you want, I can also provide one of these:
- OpenAPI spec
- SQL schema
- Node.js/Express implementation
- Python/FastAPI implementation
- System design diagram
- Redis-based round robin implementation