Ch.43: Google Calendar System Design: Why Canceled Meetings Return

Outline

Transcript

0:00 In our fictional Google Calendar design, Nora cancels one Monday in her weekly meeting. Later, she moves future meetings from nine to 10. The canceled call reappears, and her teammates wait for a meeting nobody wanted. The wrong event model has changed her decision. Oof. She changed the time, and the system changed her mind. Did it save actual meetings, or just a rule that keeps generating Mondays? A repeating rule, plus exceptions: saved changes to particular meetings. Right. We'll follow Nora's edit through that model so a canceled meeting stays canceled, a moved meeting keeps its identity, and the weekly local hour stays correct when the clocks change.

0:40 Good. “Update every future row” sounds straightforward until there aren't any rows for next year. First, place that canceled Monday on the full architecture map. Left: her phone sends an edit. Middle: one owner stores the repeating rule and its exceptions. Right: services draw calendar squares, update attendees and send reminders. An occurrence is one meeting generated by that rule. Which of these boxes can change her decision? Only the authoritative series owner. The calendar squares and reminder jobs come from its committed version.

1:11 The same transaction leaves instructions for downstream updates, so a crash cannot erase that obligation. Okay, so the square can be wrong while the saved decision is right. I'd been treating those as the same thing. Nora needs a way to see which version she's looking at. Exactly. We'll return to this map with her corrected schedule. First, spell out what that little edit button is allowed to promise. Before choosing components, name the functional requirements: create a weekly event, invite attendees, move or cancel one occurrence, and change the normal start time from a chosen occurrence onward.

1:45 For example, Nora has three upcoming Mondays. She moves the first to Tuesday, cancels the second, then changes the ordinary future meetings to 10. Do her special decisions survive that last edit? In our product, yes. The Tuesday exception stays where she put it; the cancellation remains. Only ordinary future meetings take the new time. That's a deliberate policy, not a universal definition of “this and following.” I'd want that preview before clicking Save. Otherwise “following” is a very small button with an enormous interpretation problem. Agreed.

2:17 Changing weekdays or recurrence frequency needs another migration policy. Room reservations and finding everyone's perfect free slot are separate designs. Today we protect this edit. Now the non-functional requirements describe how reliably those actions work. Nora's accepted edit must survive a crash. An old phone must not silently overwrite it. But what does her teammate see while another calendar is still behind? Nora immediately sees the committed schedule: ordinary Mondays at 10. Her teammate might still see nine, with a view that needs refreshing.

2:50 That lag must be recoverable. For this fictional design, an ordinary month view should load in a few hundred milliseconds. Imagine Nora scrolls to next month and the server tries generating her entire future first. Her weekly rule never ends. With 10 million active series in our fictional workload, that mistake becomes everyone's stalled calendar. Right. I mean, she asked for 1 month, not the rest of her life. Expand that requested window, cap its result, and commit edits durably. The database choice comes after those constraints. With finite reads settled, consider the time we're generating: Monday, nine o'clock, New York.

3:29 My first thought was to store one UTC timestamp and add a week's worth of seconds. UTC is the shared world clock. Why wouldn't that work? Because New York changes its clocks. The same UTC hour then lands at a different local hour. A stopwatch can keep perfect time and still put Nora in the wrong meeting. Oh, right. She asked for Monday at nine, not every seven elapsed days. So we store that local hour and its time zone, then calculate a UTC timestamp for each date? Yes, with a zone-aware calendar library.

4:04 Google's documentation requires a time zone for recurring expansion. Source links are in the description. It affects which instants we generate. And what if a clock change makes a local time disappear, or happen twice? Nine in the morning avoids that here, but a different meeting could hit it later. The organizer confirms a policy up front. In our example, skip a local hour that never happens; if it happens twice, choose the earlier copy. Save those choices for future dates too. One instant needs a timestamp.

4:34 Repeating her intention needs the rule. Next, follow the first occurrence as Nora reschedules it to Tuesday. If we identify the meeting by its current start time, what does her old Monday cancellation link refer to now? That's the trap. Give the occurrence a stable identity: the series plus its original recurrence slot. Its actual start is a separate field. Moving it changes the appointment, not the slot it came from. Oh, that's why a Tuesday meeting can still have Monday in its identity. I'd have mistaken that for corrupted data in a support log.

5:08 Google's event contract uses original start time for this purpose. The iCalendar specification also references the original slot after a move. We aren't inventing that distinction to rescue our schema. Consider a future edit beginning at that Monday. Sorting by today's displayed time could put the moved Tuesday on the wrong side of the boundary. Yes. Choose the edit range using recurrence identity. Otherwise moving an occurrence can accidentally change which later command is allowed to affect it.

5:37 With stable occurrence identity, store one compact rule plus explicit exceptions. The ordinary rule generates Mondays. The first slot has a Tuesday override; the second slot has a cancellation marker. A common mistake is deleting the canceled meeting's row. Then the next expansion sees the weekly rule and helpfully creates it again. Extremely helpful. Nobody asked it to come back. Yes. Absence is ambiguous here. The marker says this particular generated occurrence must be suppressed, even though it has no visible calendar square.

6:09 Google's reference tells clients to retain canceled exceptions for the parent event's lifetime. A cancellation can have only enough fields to name the occurrence. It doesn't need a complete meeting body. Exactly. Deleting the entire series is a different operation. For our still-active rule, cleanup cannot erase a cancellation while that slot can be generated again. With the exception records defined, take the Tuesday move. Her command names the series, original Monday slot, new start and the revision she saw.

6:38 It also carries a stable request identifier. I think we could reuse the meeting's identifier for that last part too. But a second move is a different action. Authenticate Nora and check her permission to edit the series. If the revision matches, its owner saves Monday's move to Tuesday and the action receipt together. That commit also advances the version and leaves update instructions. Suppose her phone loses the response after that commit. She can't tell whether Tuesday was saved. What does retrying retrieve?

7:07 The same request identifier and parameters return the saved result. Changed parameters using that identifier fail. A genuinely new move gets a fresh command key and checks the current revision. Two identities, then. The request is the receipt for one action. The appointment's identifier survives rescheduling. Right, the receipt and the appointment. Nora gets the committed version and moved occurrence back while attendee copies catch up. Now make the future edit preserve that same distinction. Now extend that single-move transaction across the schedule.

7:40 Nora shifts the ordinary hour to 10, beginning at the original first-Monday slot. Split the repeating rule at that boundary. A rule segment is the rule active over one range of original slots. An interviewer could say, “Close the old segment, then create the new one. Why complicate it?” Walk me through what breaks between those two writes. Imagine the rule is truncated successfully, but its replacement fails. Next month's meetings vanish. Reverse the order, and a reader can see two copies before the earlier rule ends.

8:11 A reader can catch the schedule between those writes. So one revision has to mean one complete schedule. Not just one successful API call. Exactly. In one transaction, the earlier segment stops before the chosen Monday; its replacement starts there at 10. The Tuesday override and cancellation stay attached to their slots. Save the action's result plus pending worker tasks too. Nora gets a complete schedule, even if we crash immediately afterward. Okay, that's why one owner matters. Version checks on separate calls can't give us that all-or-nothing change.

8:44 A timetable with half its replacement page missing is still broken. Yes. Our chosen database can transact over that series. A different storage arrangement would need another commit protocol. Now the reader has to find every meeting in this complete version. With that complete version saved, the month view expands a finite window. For instance, Nora's original Monday could sit outside that month while her moved Tuesday falls inside it. Will the rule lookup find that meeting? Not by itself. For Nora's moved-in meeting, that lookup returns nothing: its Monday belongs to the previous month.

9:20 A second query, for overrides with actual starts inside this month, brings Tuesday in. Nice. But those aren't alternative queries. Looking only at displayed starts can leave the generated Monday behind as a second copy. We need to recognize two positions as the same meeting. Oh, that's the duplicate I'd miss. Merge by occurrence identity, then apply the cancellation markers. Index both the original slot and actual start: moving out hides the generated appointment; moving in adds its rescheduled date.

9:51 One identity keeps the result from counting it twice. Then cache that bounded result with the series revision, window and viewing zone. Nora's old revision can't pretend to show the new schedule. And cap the result: paginate a large range or narrow the window. Nora must get a bounded answer, never a silently dropped appointment. But an old view also feeds stale writes. Let's say Nora's sleeping phone returns with an edit against revision seven. Her laptop already committed eight. The owner rejects the old command instead of letting the last network arrival win.

10:26 Google's public API can reject a stale resource with an ETag, a version marker sent with a conditional write. Our whole-series revision applies that idea to the complete change we've designed. Hold on. My first instinct was to fetch eight and replay the command. But the phone might be canceling a nine-o'clock meeting whose meaning changed. A newer version number doesn't make that old intention safe. Right, Nora must confirm against the current schedule. Show the conflict and what changed. Don't quietly decide that her old click meant something else.

10:59 If cancellation races a schedule change, one transaction wins and the other sees a revision conflict. Once she confirms again, the original recurrence slot still names the meeting she means. Next, follow the work instructions from that committed edit into attendee copies and reminders. Suppose the worker updates one attendee, then crashes. Its saved progress lets retries finish the others; copies reject an older revision arriving after a newer one. Fine, but Nora's second Monday already has a reminder job.

11:30 Can cancellation still stop it after that worker wakes up? Yes, if cancellation wins before send authorization. The same series owner checks the original slot, current revision and cancellation marker, then records permission to send in one transaction. A canceled slot gets no permission. The worker can't turn its old job into permission by itself. So the race is decided there, not when somebody finally opens the email. What if send permission commits first and Nora cancels a moment later? That already-authorized reminder can still arrive, even if the provider accepts it after her cancellation.

12:05 Our local database cannot commit atomically with an external inbox. Cancellation blocks future authorizations; it cannot recall permission already handed to delivery. Oh, that's the limit I'd want stated before promising “no stale reminders.” Cancellation is ordered against send permission, not inbox arrival. Provider retries still need separate duplicate and uncertain-acceptance handling. Our transaction protects authorization; it doesn't promise exactly-once email. But reminder delivery doesn't tell us whether every attendee's calendar refreshed.

12:33 Consider this failure: the saved cancellation is correct, but Nora's phone misses the notification. Google's push guide says those hints contain no changed event body and may be missed. They're a doorbell, not the calendar. Then her phone still shows the canceled Monday. Does reconnecting ask what changed, even without a push? Yes. Her phone last synced before she canceled Monday. Its cursor, its saved place in the change stream, asks for the changes since then. Google's incremental sync includes deleted entries.

13:05 If that cursor is invalid, finish a fresh server copy before resuming. That completed reload must hide Monday as well. Right, the visible Monday disappears. But keep Nora's unsent edits in a separate queue while replacing that cached copy. Refreshing the calendar mustn't erase a decision she hasn't sent yet. Precisely. The repaired view tells her what the server accepted. Her queued edit still goes through the version check. Missing a doorbell doesn't authorize changing the meeting. With that repaired client view, return to the same full architecture.

13:38 Nora's future-time command reaches one series owner. One transaction saves the complete rule change, retained exceptions and work instructions. Then the read and follow-up paths separate. The read service shows the rescheduled Tuesday, suppresses the cancellation and puts the ordinary 3rd Monday at 10. Attendee copies carry that schedule to other calendars. That corrected schedule is what reminders must check too. The owner serializes each cancellation with authorization; delivery has the limit we just named.

14:07 A lost update is recoverable by sync. None of those right-hand boxes gets to rewrite Nora's rule. And the newly chosen hour stays tied to New York. Seasonal clock changes alter derived UTC timestamps, not Nora's local instruction. There it is. One durable decision, several views and actions. Each box has a clear way to catch up, and a clear boundary on what it can promise. Finally, take Nora's corrected schedule into the interview: make the edit policy explicit before the schema. Which exceptions survive, what identifies a moved occurrence, and which component commits the whole change?

14:42 Then make readers prove they can find moved meetings and keep cancellations out. Compact rules save storage, but the exceptions and boundaries are what make Nora trust the calendar. She moved the future time. She didn't bring Monday back. Thanks for listening to Learning Podcasts.