Prompt
How do I expose free/busy lookup in my app?
Latest observation
To expose free/busy lookup in your app, you generally need to provide an API or UI that answers: “Is this user/resource available at this time?”
The exact approach depends on whether you’re building a calendar app, an internal scheduling tool, or integrating with something like Google/Microsoft calendars. Here’s the common pattern.
1) Define what “free/busy” means
Usually it means:
- Free: no event blocks the time
- Busy: an event or booking conflicts with the requested interval
- Sometimes also:
- Tentative
- Out of office
- Working elsewhere
- Resource unavailable
Decide:
- Which event types count as busy?
- Do private events count?
- Do recurring events count?
- Do you consider buffers/travel time?
2) Create a lookup API
A typical endpoint looks like:
POST /availability/freebusy
Request
{
"attendees": ["user1@example.com", "user2@example.com"],
"start": "2026-01-20T09:00:00Z",
"end": "2026-01-20T17:00:00Z",
"timezone": "America/New_York"
}
Response
{
"results": {
"user1@example.com": [
{
"start": "2026-01-20T10:00:00Z",
"end": "2026-01-20T10:30:00Z",
"status": "busy"
}
],
"user2@example.com": []
}
}
You can also return a simpler boolean if you only need “any conflict?”
{
"available": false
}
3) Back it with calendar/event data
Your lookup should query:
- confirmed meetings
- holds/bookings
- blocked times
- working hours exceptions
- resource reservations
Implementation usually involves:
- Convert request time into the user’s timezone
- Fetch all events overlapping the interval
- Merge overlapping busy periods
- Return the resulting busy windows
A basic overlap rule:
event.start < requested_end AND event.end > requested_start
4) Handle recurring events and exceptions
This is the part many people miss.
If you support recurring events:
- Expand recurring rules into occurrences for the requested window
- Apply exceptions/cancellations
- Consider modified instances
Libraries like:
- iCal/ICS parsers
- RRULE libraries can help with recurrence expansion.
5) Support multiple calendars/resources
If users can have:
- personal calendars
- team calendars
- room/resource calendars
then your API may need to aggregate across them.
Example:
- user is free only if none of their relevant calendars are busy
- room is free if no booking exists on that resource calendar
6) Add auth and privacy controls
Free/busy data can be sensitive. Common rules:
- Only authenticated users can query
- Users can only query calendars they’re allowed to see
- Return only busy blocks, not event details, unless permitted
- Optionally redact titles and attendees
7) Offer integration-friendly formats
If you want other systems to consume it:
- REST/JSON API
- GraphQL field
- iCalendar/CalDAV-style availability
- Webhook or SDK
If you’re integrating with Google/Microsoft ecosystems, you may need to map to their:
- FreeBusy endpoints
- Availability APIs
- Calendar permissions model
8) Optimize for performance
Free/busy lookup can get expensive if you have many users or recurring events. Common optimizations:
- Index events by time range
- Cache computed availability for short periods
- Precompute busy blocks for popular horizons like today/this week
- Store merged busy intervals per day
9) Example implementation logic
Pseudo-code:
def freebusy(user_id, start, end):
events = fetch_events(user_id, start, end)
busy = []
for event in events:
if event.status in ["cancelled"]:
continue
if overlaps(event.start, event.end, start, end):
busy.append({
"start": max(event.start, start),
"end": min(event.end, end),
"status": "busy"
})
return merge_overlapping_intervals(busy)
10) If you want scheduling, return slots too
Instead of only busy intervals, you can expose:
- busy intervals
- available slots
- nearest open slot
- suggested meeting times
Example:
{
"busy": [
{"start": "2026-01-20T10:00:00Z", "end": "2026-01-20T10:30:00Z"}
],
"free_slots": [
{"start": "2026-01-20T09:00:00Z", "end": "2026-01-20T10:00:00Z"},
{"start": "2026-01-20T10:30:00Z", "end": "2026-01-20T17:00:00Z"}
]
}
If you want, I can help you design:
- a REST API spec for free/busy,
- a database schema, or
- an implementation for a specific stack like Node.js, Python, or Java.