Prompt
How do I support recurring events with a calendar API?
Latest observation
To support recurring events in a calendar API, design for one recurring rule plus individual exceptions/overrides rather than storing every occurrence as a separate “full” event.
1) Model the series, not just instances
Store a master event that represents the pattern:
- title, description, location, attendees, etc.
- start date/time
- duration
- recurrence rule
Example recurrence fields:
rrule:"FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,WE,FR"timezone:"America/New_York"- optional:
untilcountbyday,bymonthday, etc.
2) Represent occurrences separately only when needed
You usually have three kinds of records:
A. Series master
The recurring definition.
B. Generated occurrences
You can generate these on the fly when querying, or cache them for performance.
C. Exceptions / overrides
For cases like:
- one occurrence moved to a different time
- one occurrence canceled
- one occurrence edited differently from the series
This is often represented by:
series_idoriginal_occurrence_startstatus: canceled | modified- changed fields
3) Support common recurrence rules
At minimum, support:
- daily
- weekly
- monthly
- yearly
Useful rule options:
intervalbydaybymonthdaybymonthcountuntil
Using an established standard like iCalendar RRULE is strongly recommended.
4) Expand occurrences on query
When a client asks for events in a date range:
- fetch single events
- fetch recurring series overlapping the range
- expand each series into occurrences in that range
- apply exceptions/overrides
- return the final list
This avoids storing millions of future instances.
5) Handle edits carefully
When editing a recurring event, offer actions like:
- This occurrence only
- This and future occurrences
- Entire series
Behavior:
- This occurrence only → create an exception/override record
- This and future → split the series into two rules
- Entire series → update master event
6) Handle deletions as cancellations
Don’t necessarily delete an occurrence from the series. Mark that specific occurrence as:
canceled: true
7) Include timezone support
Recurring events are tricky across DST changes. Store:
- original timezone
- local wall-clock start time
- recurrence rule in local time context
Then generate occurrences using timezone-aware logic.
8) API shape example
A series create payload might look like:
{
"title": "Team Sync",
"start": "2026-01-05T09:00:00",
"durationMinutes": 30,
"timezone": "America/New_York",
"recurrence": {
"freq": "weekly",
"interval": 1,
"byday": ["MO", "WE", "FR"],
"until": "2026-03-31"
}
}
An overridden occurrence:
{
"seriesId": "evt_123",
"originalStart": "2026-01-12T09:00:00",
"status": "moved",
"newStart": "2026-01-12T10:00:00"
}
9) Use a library if possible
Parsing and expanding recurrence rules is easy to get wrong. Use a standard library:
- iCalendar RRULE libraries
- date/time libraries with timezone support
10) Be clear about query semantics
Document how your API behaves for:
- date-range queries
- pagination
- conflict detection
- exception precedence
- recurring event IDs vs occurrence IDs
A common approach:
- recurring series has one stable
id - each returned occurrence has an
occurrenceIdor composite key like:seriesId + originalStart
If you want, I can also show:
- a recommended database schema,
- sample REST endpoints, or
- how to implement recurrence expansion in code.
Brands