Design a Calendar
How to design a shared calendar: repeating events, time zones and daylight saving, free/busy lookups, reminders, and sync, plus what interviewers ask.
On this page
A calendar service stores events, lets users invite other people to them, and shows each user their own schedule on every device. The question is popular because the infrastructure is ordinary, while the data is not: a repeating event such as "every Monday, forever" cannot be stored as one row per occurrence, a time of day only makes sense together with a time zone, and finding a time when eight people are free means reading eight different users' schedules.
The sections below follow the steps in A Framework for Any Design.
Clarify the problem
Design a calendar service like the ones in office suites.
I will assume the core is events, invites with replies, repeating events, free/busy lookups for finding a common time, and reminders. Should I include meeting rooms or calendars from other providers?
Treat a room as a person with a calendar. Skip other providers.
How many users are there, and how many meetings does each one have?
100 million users, 50 million of them active each day, with about four meetings a day each.
Then reads will far outnumber writes, and reminders will arrive in bursts at the top of the hour. My priorities are these: a saved event must never be lost and must show on the owner's devices immediately, invitees may see it a few seconds later, no reminder may be skipped or be more than a minute late, and every occurrence of a repeating event must appear at the right local time.
- Functional: create, edit and delete events; invites and replies; repeating events with changes to single occurrences; day, week and month views; free/busy lookups for several people; reminders; sync to every device.
- Non-functional: events are durable; the owner reads their own writes; attendees see a change within 5 seconds; the week view loads in under 200 ms; reminders arrive within 60 seconds and are never skipped; local times are correct across daylight saving changes.
- Out of scope: other providers' calendars, video calls.
Estimate the scale
A day has 86,400 seconds, and this estimate assumes the peak rate is 3 times the average. With 50 million active users:
- Writes: each active user makes 2 changes a day, so 100 million ÷ 86,400 is about 1,200 a second on average and 3,500 at peak.
- Reads: each active user loads calendar views 20 times a day, so 1 billion ÷ 86,400 is about 12,000 a second on average and 35,000 at peak.
- Reminders: 50 million users × 4 meetings is 200 million reminders a day, about 2,300 a second on average. If 3% of them fall due at the busiest top of the hour and must go out within 60 seconds, that is 6 million ÷ 60 = 100,000 a second, about 43 times the average.
How much new event data is stored each year?
- 50 million active users each create about 1 event a day
- About 1 KB per event (title, description, rule, times)
- About 4 attendees per event, each with a 250-byte per-person entry
Show the working
- Bytes per event: 1,000 + 4 × 250 = 2,000 B
- Per day: 50 × 106 × 2,000 B = 100 GB
- Per year: 100 GB × 365 ≈ 37 TB, or about 110 TB with 3 copies
Estimate 37 TB (anything from 10 TB to 120 TB is a good answer)
Write the endpoints to create an event, read one week, edit a single occurrence, reply to an invite, query free/busy and sync a device. How does a client avoid overwriting someone else's edit?
Compare with a model answer
Times are sent as a local time plus a zone name. Reads take a time window and return occurrences. Edits carry the event's version in an If-Match header and a scope of this, following or all. Sync is a "changes since this token" call.
Define the API Optional
Optional in the interview. Sketch the API only if the interviewer asks, if an API choice shapes the design, or if time permits. Otherwise say "I'll skip the detailed API unless you want it" and go to the data model.
POST /calendars/{cal}/events Idempotency-Key: 7f3a...
body: { "title": "Team sync",
"start": { "local": "2027-03-01T09:00", "tz": "America/New_York" },
"duration_min": 30,
"rrule": "FREQ=WEEKLY;BYDAY=MO", optional
"attendees": ["ben@...", "chen@..."],
"reminders": [{ "before_min": 10, "via": "push" }] }
201 { "event_id": "e81", "version": 1 }
GET /calendars/{cal}/events?from=2027-03-01&to=2027-04-01&tz=Europe/London
200 { "occurrences": [ { "event_id": "e81", "original_start": "...",
"start": "...", "end": "...", "title": "..." } ] }
400 window longer than 1 year
PATCH /events/{id}?scope=this|following|all&occurrence=2027-03-22T09:00
If-Match: 4
200 { "version": 5 }
412 Precondition Failed someone else changed it; body has the current event
POST /events/{id}/reply { "response": "accepted", "occurrence": ...? }
POST /freebusy { "people": [...], "from": ..., "to": ... }
200 { "busy": { "ben@...": [ ["2027-03-01T14:00Z", "2027-03-01T14:30Z"] ] } }
GET /calendars/{cal}/changes?since=token
200 { "changes": [...], "next": "token" }
410 Gone token too old; do a full resyncThe decision worth arguing is who expands a repeating event. The view endpoint expands on the server, so a web page needs no calendar logic. The sync endpoint sends the raw rule and exceptions, so a phone can expand any month offline. Both must use the same expansion library.
Sketch the records. How do you store "every Monday, forever" when one Monday is cancelled and another is moved? How do you find Ben's events for this week with one index lookup?
Compare with a model answer
Store the rule once, and store the changed occurrences as exceptions keyed by their original start time. Give each attendee an entry on their own shard that records the event's overall time span, using a far-future date for "forever", so one index on the span's end finds every event that could appear this week.
Model the data
events -- on the organizer's shard
event_id BIGINT PRIMARY KEY
organizer BIGINT
title, description, location TEXT
start_local TIMESTAMP -- 2027-03-01 09:00, no zone attached
tz VARCHAR(40) -- "America/New_York"
duration_min INT
rrule TEXT NULL -- "FREQ=WEEKLY;BYDAY=MO"
version INT
exceptions -- one row per changed occurrence
event_id, original_start PRIMARY KEY
cancelled BOOLEAN
new_start_local, new_duration, new_title NULL = unchanged
entries -- one per attendee, on THEIR shard
calendar_id, event_id PRIMARY KEY
span_start_utc, span_end_utc -- span_end = 9999-12-31 if no end
start_local, tz, duration_min, rrule, title -- copied from the event
exceptions JSON -- copied, plus this person's own declines
response VARCHAR(10) -- needs-action | accepted | declined
reminders JSON
INDEX (calendar_id, span_end_utc)
changes -- per calendar, for device sync
calendar_id, seq PRIMARY KEY
event_id, opThe most frequent read is "Ben's events that overlap this week", which is WHERE calendar_id = ? AND span_end_utc > week_start AND span_start_utc < week_end. The index skips everything that ended earlier. Each entry copies the event's times, rule and exceptions, so this read stays on Ben's own shard.
A relational database sharded by calendar fits this data, because an edit changes the event, its exceptions and the change log in one transaction.
Sketch where an edit is written, how it reaches the attendees and their devices, and where free/busy and reminders are handled.
Compare with a model answer
The edit is one transaction on the organizer's shard. A change stream then feeds workers that update the attendees' entries, nudge their devices and plan reminders. Free/busy lookups read a per-person cache.
High-level design
request and replyasynchronous message
1Ana creates a weekly event called "Team sync" on Mondays at 9:00 New York time and invites Ben and Chen. The request carries an idempotency key, so a retry does not create a second series.
- version
- 1
2One transaction on Ana's shard writes the event and its rule, Ana's own entry, a change-log row and an outbox row. The event is now at version 1.
- version
- 1
3The outbox row reaches the change stream, and a fan-out worker picks it up.
- version
- 1
- entries written
- 2
4The worker writes an entry and a change-log row on Ben's shard and on Chen's shard. Each write carries version 1 and is ignored if the stored version is newer, so a late message cannot roll an entry back.
- version
- 1
- seen by Ben after
- 2 s
5A silent push notification tells their devices to call the changes endpoint with their last token. Ben and Chen have the event about 2 seconds later.
6Ben opens his week view. One index range scan on his shard returns the series, and it expands to Monday 9:00 New York time, which is 14:00 in London.
- version
- 1
- delivery
- at least once
7Suppose the worker crashes after writing Ben's entry but before writing Chen's. The unacknowledged message goes to another worker, which repeats both writes. Ben's entry does not change, and Chen's arrives a few seconds late.
- version
- 2
8Ana renames the event on her laptop, while her phone, which has been offline since version 1, sends a time change. Both requests say
If-Match: 1. The laptop's request is applied first and creates version 2, so the phone's request gets a 412 response with the current event.
Deep dives
Repeating events and time zones
A rule such as "every weekday at 9:00, with no end date" has infinitely many occurrences, so the service has to decide what is stored and what is computed. There are two options.
One row per occurrence. The service creates a row for every occurrence up to some far-off date. Reads become a plain range query, but the cost is large: a weekly meeting that runs until 2100 is about 3,800 rows for each attendee. Changing "all occurrences to 10:00" rewrites every one of those rows, and the series still has an end date, after which the events silently stop.
A rule plus exceptions, expanded on read. The service stores one row for the series, in the standard iCalendar RRULE format that devices already understand, and a small exception row for each occurrence that was changed. Editing all occurrences changes one row. The cost is that every read must run expansion code with subtle edge cases.
Store the start as a local time plus a zone name, and key each exception by the occurrence's original start time, which never changes even when the occurrence is moved. The three edit scopes map onto the data as follows. Editing "this occurrence" adds an exception. Editing "all occurrences" changes the series row. Editing "this and following" ends the old rule just before that occurrence and starts a new series from it.
The table shows Ana's Monday 9:00 New York meeting in March 2027, with March 8 cancelled and March 22 moved to 10:00.
| Original start (New York) | Exception | UTC | Ben in London |
|---|---|---|---|
| Mon Mar 1, 09:00 | none | 14:00 | 14:00 |
| Mon Mar 8, 09:00 | cancelled | no occurrence | no occurrence |
| Mon Mar 15, 09:00 | none | 13:00 | 13:00 |
| Mon Mar 22, 09:00 | moved to 10:00 | 14:00 | 14:00 |
| Mon Mar 29, 09:00 | none | 13:00 | 14:00 |
The UTC column shows why the zone matters. New York changes its clocks on March 14, 2027, so Ana's 9:00 moves from 14:00 to 13:00 in UTC. London changes on March 28, so for two weeks Ben sees the meeting at 13:00 and then at 14:00 again. This is correct because the meeting means "9:00 for the organizer", and it works only if the service expands the series in the event's own time zone and converts to the viewer's zone afterwards.
- A repeating event must store a zone name such as
America/New_York, never a fixed offset such as −05:00, which is correct for only part of the year. - On the night the clocks go forward, 2:30 does not exist, and on the night they go back, 1:30 happens twice. Pick one rule and apply it everywhere. The iCalendar convention is to move a missing time forward by the length of the gap and to use the first of a repeated time.
Free/busy for many people
When Chen asks when Ana, Ben and five other people are all free next week, the service must read seven people's schedules, each stored on a different shard and each containing series that need expanding. The answer needs only busy intervals, not titles, so private details stay hidden. There are two ways to compute it.
Expand on every lookup. The service reads each person's events and expands the series itself. The answer is always exact, but the slowest shard sets the latency.
A cached list of busy intervals per person. The service keeps a sorted list of each person's busy intervals for roughly the next eight weeks. At four meetings a day that is about 224 intervals, and at 16 bytes each about 3.6 KB per person. A lookup is one cache read per person, and the times are exact. The cost is that the list must be rebuilt whenever the person's calendar changes or the time zone database is updated.
| Option | Good at | Bad at | Pick it when |
|---|---|---|---|
| Expand on every lookup | The answer is always exact and nothing has to be kept in sync. | Each lookup does one expansion per person, and the slowest shard sets the latency. | Use it at small scale, or as the fallback when the cache is down. |
| Cached busy intervals per person Usual default | One cache read per person gives exact times, and eight weeks of meetings take about 3.6 KB. | A person's entry must be rebuilt on every change and on every time zone update. | Use it as the default for scheduling views. |
The choice here is the cached busy intervals. The service reads the seven cached lists in parallel, merges them with the interval merging technique and returns the gaps that fall inside working hours. The cache for 100 million users is about 360 GB.
Reminders at scale
A repeating event has no last reminder, so the service cannot create all its reminders in advance. Instead it plans reminders inside a rolling horizon, using a job scheduler.
- Planning: a daily planner expands each calendar's next 48 hours and creates a scheduled job for each reminder in that window. The fan-out workers add jobs when an edit falls inside the window. Each job is keyed by calendar, event, original start and offset, so planning twice creates one job.
- Checking when the job fires: the job re-reads the event and does nothing if it was cancelled, moved or declined.
- Surviving the burst: the scheduler loads each minute's jobs a minute early and hands them to the notification system, which is built for bursts of 100,000 a second.
- Duplicates: jobs run at least once. A "sent" record keyed by the job catches most duplicates, and a rare duplicate reminder is better than a missed meeting.
Edits from many devices and sync
Every edit sends the version it started from in an If-Match header, and the database applies it only if the stored version still matches. A stale edit receives a 412 response containing the current event. The client then merges the two changes and retries, or asks the user when both changed the same field.
Devices sync from the per-calendar change log. Each change takes the next number from a per-calendar counter inside the same transaction as the edit, so the numbers commit in order and a request for "everything after 1,042" cannot miss a change. That number is the sync token. Log rows older than about 30 days are deleted, so a device with an older token gets a 410 response and does a full resync.
Bottlenecks and failures
What breaks first at 10 times the load
At 10 times the load the peak is 35,000 writes and 350,000 reads a second. Adding servers, read replicas and shards handles most of that. The harder problem is a very large guest list: a company-wide meeting with 50,000 invitees means 50,000 entry writes for every edit. Above roughly 1,000 guests, the service should write one shared event and give each guest only a small pointer row, as a news feed does for accounts with millions of followers.
What happens when a component fails
| Component that fails | What happens | What the design does |
|---|---|---|
| A calendar DB primary | Writes to its calendars stop until a replica takes over. | The primary replicates synchronously to one replica, and the service fails over within seconds. |
| The change stream | Attendees and devices stop hearing about changes. | Organizers' writes still succeed, and the outbox rows wait in the database until the stream recovers. |
| The job scheduler | Server-side reminders stop. | Device alarms still fire, and on recovery the scheduler sends only reminders that are less than 5 minutes late. |
What a strong answer sounds like
Interviewers for this question mostly listen for how the candidate handles repeating events and time zones, because those are the parts that do not look like a standard web service. The table shows how the answers differ by level.
| Level | What the answer contains |
|---|---|
| Junior | Draws an events table with a start and end time in UTC, stores each occurrence of a repeating event as its own row, and does not discuss invites to other users or reminders at scale. |
| Mid-level | Stores a repeat rule plus exceptions, keeps the local time and zone name, copies events to each attendee, and uses a queue to send reminders, but does not say what happens to the data when a worker crashes or two devices edit at once. |
| Senior | Does everything above, and also expands the series in the event's own zone across clock changes, versions edits with If-Match, makes the fan-out idempotent, plans reminders in a rolling horizon, and names the large-guest-list problem before being asked. |
Ana has a weekly meeting at 9:00. What do you store, and what does Ben in London see in March?
I store 09:00 with the zone America/New_York and the repeat rule, not a UTC time. I expand the series in New York time and then convert to the viewer's zone. Ben sees 14:00, then 13:00 for the two weeks between the US and UK clock changes, and then 14:00 again. That is correct, because the meeting means 9:00 for the organizer.
What if the US changed its daylight saving rules?
Future occurrences fix themselves the next time they are expanded, once the time zone database is updated. I would rebuild anything I had derived in UTC, which means the span columns, the busy caches and the planned reminders.
Follow-up questions
How do you book a meeting room without double booking?
A room is a calendar that accepts an invite automatically only if no confirmed event overlaps it. The overlap check and the acceptance run in one transaction on the room's shard, and that transaction also increments the room's change counter. Two bookings for the same slot therefore cannot interleave, and the one that commits second sees the first and is declined.
An attendee declines one occurrence of a series. Where is that stored?
It is stored as an exception on that attendee's own entry, keyed by the occurrence's original start time. The shared event and every other attendee's entry are untouched.
Why not store all times in UTC?
UTC is right for a single instant such as a flight. It is wrong for a repeating event, because "9:00 every Monday" means local time and its UTC value changes when the clocks change.
After your attempt, tick what you really did. Be strict: "I thought about it" is not "I said it out loud".