Prompt
How do I do round robin scheduling with a calendar API?
Latest observation
Round robin scheduling with a calendar API usually means:
- You have a list of people/resources
- You assign them in turn to incoming slots/events
- You use the calendar API to create/update events and check availability
Basic approach
1) Keep a rotation list
Example:
[Alice, Bob, Carol, Dan]
Each new event gets the next person in the list, then you advance the pointer:
- Event 1 → Alice
- Event 2 → Bob
- Event 3 → Carol
- Event 4 → Dan
- Event 5 → Alice again
2) Check calendar availability before assigning
Before you create an event for a person, query their calendar for conflicts in the desired time window.
If they’re busy:
- skip them and try the next person, or
- find the next available time, depending on your rules
3) Create the event in the calendar
Use the calendar API’s event creation endpoint to create:
- title
- start/end time
- attendee or organizer
- metadata (like assignment ID, rotation index, etc.)
4) Persist the rotation state
Store the “next person to assign” somewhere durable:
- database
- Redis
- config store
This prevents resets if your service restarts.
Pseudocode
rotation = ["alice", "bob", "carol"]
next_index = load_rotation_index()
def assign_next(slot):
global next_index
for i in range(len(rotation)):
person = rotation[(next_index + i) % len(rotation)]
if is_available(person, slot.start, slot.end):
create_calendar_event(person, slot)
next_index = (next_index + i + 1) % len(rotation)
save_rotation_index(next_index)
return person
return None # nobody available
If you’re using Google Calendar API
Typical flow:
freebusy.queryto check availabilityevents.insertto create the event- Save the assigned person and rotation index
Example logic:
- call free/busy for each candidate
- pick the first available in round robin order
- create event for that person
If you’re using Microsoft Graph Calendar API
Typical flow:
getScheduleor calendar view to check free/busyPOST /users/{id}/eventsto create the event- store rotation state
Important considerations
Concurrency
If multiple requests assign at once, use a lock or transaction around the rotation index so two events don’t get the same person.
Time zones
Always normalize event times to the correct time zone.
Fairness
If people have different working hours or exceptions, availability checks should account for that.
Recurring schedules
If you’re scheduling recurring events, assign the next person per occurrence rather than all at once unless you want a fixed cycle.
Simple database model
round_robin_state
- id
- rotation_name
- next_index
- updated_at
And optionally:
assignments
- id
- slot_start
- slot_end
- assigned_user_id
- calendar_event_id
Recommended algorithm
- Load current index
- For each candidate in rotation order:
- check availability
- if available, create event
- update index
- If none are available, return unassigned / retry later
If you want, I can give you:
- a Google Calendar API example
- a Microsoft Graph example
- or code in Python/Node.js for round robin scheduling