Design Google Calendar
hard 60 minEvents with a start and an end look like the simplest table there is.
See it run
Show a month, expand a rule, invite guests, cross time zones, remind, sync and search, one step at a time.
Operations
Show a month
Rights, cache, range query, expand.
Step 1 of 10
Ask
window
January
A month of one calendar, in the reader's zone. Why: a window is required, so the answer is bounded.
Step 1: Ask
user = gateway.verify(token)require(rights(user, cal) >= READER)key = (cal, month, zone, seq(cal)) # change number in the keyview = redis.get(key)if view is None: rows = db.range(cal, month.start, month.end) view = expand(rows, month, zone) # rules and exceptions redis.set(key, view, ttl=HOUR)return view, etag(view), sync_token(seq(cal))- Time
- 15 to 100 ms
- Scale
- 26,000/s at peak
- Cached
- about 15 ms
- Not cached
- under 100 ms
With the change number in the key an edit makes a new key. Nothing has to be deleted, and nobody sees an old month.
In the real world
The same google calendar doing real jobs. Pick one and step through it.
Bob was in a tunnel.
Step 1 of 4
Change
A meeting moves. The hint is sent to a socket that is dead.
Step 1: Change
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Storing an offset instead of a zone
critical-5 is true for New York only in winter.
Wrong{"start": "2026-01-12T09:00:00-05:00"}Right{"start": "2026-01-12T09:00:00", "timeZone": "America/New_York"}Using updated_at as a bookmark
criticalA change with an earlier time can commit later, behind the bookmark. Deletions leave no row.
WrongSELECT * FROM events WHERE updated_at > :lastRightSELECT * FROM changesWHERE calendar_id = :cal AND seq > :tokenRemove, then publish
criticalA crash between the two loses the reminder.
Wrongredis.zrem(key, r); kafka.send(r)Rightclaim(r, lease=10); kafka.send(r); done(r)Check, then book the room
majorTwo requests both see a free room.
Wrongif count_overlaps(room, t) == 0: insert()RightEXCLUDE USING gist (room_id WITH =, during WITH &&)Midnight for all-day events
majorMidnight UTC is the evening before in America, so a birthday moves a day.
Wrongstart = "2026-05-15T00:00:00Z"Rightstart_date = "2026-05-15" # no zone
Interview tips
Show depth early
- Ask about repeating events and zones.
- Say that all-day events are dates.
- Promise against index.
Defend with numbers
- 32,000 rows a second if every date is saved.
- 34M reminders in a minute.
- 1.5 TB for the month cache.
Be safe by order
- Change number in the transaction.
- Outbox with the event.
- Publish before done.
Know the small version
- One service, one database, cron.
- Never cut zones or API versions.
- Add sync and search when needed.