Design Google Calendar
Understanding the Problem
📅 What is Google Calendar? Google Calendar is a shared calendar service: people create events, invite others, accept or decline, and see everyone's schedule on the web and their phones. At work it also books meeting rooms and finds times when everyone is free. Booking tools like Calendly add a public link where anyone can pick a free slot on your calendar, and the event appears for both of you.
Calendly-style booking links come up as their own interview question ("design a scheduling link service") and also as a follow-up to "design Google Calendar." They're the same system: both rest on knowing each person's busy times and creating an event without colliding with another one. We'll design the calendar first and treat booking links as one of its features.
Functional Requirements
Core Requirements
- Users should be able to create, edit and delete events, including recurring events (every weekday, every other Tuesday), and view their calendar for any day, week or month.
- Users should be able to invite people to an event, and invitees should be able to see it on their calendar and RSVP.
- Users should be able to find a time when attendees are free and get meeting room suggestions, and book a room without conflicts.
- Users should be able to publish a booking link that shows their free slots, so others can book a meeting without back-and-forth.
Below the line (out of scope)
- Tasks, out-of-office auto-replies and working location features.
- Video conference link generation (we'll assume a call to another service).
- Full CalDAV server support for third-party clients (we'll mention interop).
Non-Functional Requirements
Ask about scale. For our design: 500 million users, 100 million daily active users, and organizations with up to hundreds of thousands of employees and tens of thousands of meeting rooms.
Core Requirements
- Viewing a calendar should be fast: under 200 ms for a week view.
- Edits should be visible to the person who made them immediately, and to attendees within a few seconds.
- Rooms and booking-link slots must never be double-booked. These need strong consistency. Personal calendars can overlap; that's the user's choice.
- Times must be correct across time zones and daylight saving changes. A weekly 9:00 am meeting in New York stays at 9:00 am New York time all year.
- The system should be highly available; people rely on it to know where to be.
Below the line (out of scope)
- Offline editing with conflict resolution (we'll keep the clients online, with read caching).
Some math:
- Reads: 100M daily users opening the calendar around 10 times a day across devices is 1 billion views or syncs a day, about 12,000 per second, with peaks a few times higher on Monday mornings as each region wakes up.
- Writes: if each daily user creates or changes about one event a day, that's 100M writes a day, around 1,200 per second. With an average of 5 attendees, each write updates about 5 calendars, so 6,000 attendee updates per second.
- Storage: 100M events a day at around 1 KB with attendee entries is on the order of 35-40 TB a year.
Reads dominate, but not by a huge factor, and the hard parts aren't throughput. They're recurrence (a single row that represents an unlimited number of meetings), fan-out (one event on many calendars, sometimes thousands) and free/busy (answering "when is everyone free?" across many calendars in milliseconds).
Point out early that most of a calendar isn't contended at all: two of my own meetings can overlap and that's fine. Contention exists only where a resource can be booked by many people: rooms, and slots on a booking link. That's where strong consistency goes, and only there.