Skip to content
SD-18 · Back to the write-up

Design a Calendar Service

Store each series once, precompute instances per user, and drive invites, reminders and sync from a change log.

Follow a request

Clients
Edge
Services
Data
AppsWeb and phones
Push and emailProviders
API gatewayAuth, limits
Sync service“Changed” pushes
SenderPush, email
Calendar serviceStateless
Change logOutbox → log
Fan-out workersPer attendee
Reminder schedulerMinute buckets
Events DBBy calendar
Instance indexBy user, start
View cacheWeek views
1client → gateway · POST /eventsAna creates “Design review, every Tuesday 10:00 Europe/Berlin” and invites Ben and Chen.1 / 11

The numbers, at a glance

For every change saved……about 10 views are served
1 write ≈ 3,500/s10 views ≈ 35,000/s
Reminders bunch upReminders a second through the hour, at peak
Pushing instead of pollingDelta fetches against polls a second
Devices ask only when their calendar changed.

A save, in order

The organizer gets 201 after one transaction; attendees are updated from the log a few seconds later.

App
Calendar service
Events DB
Change log
Fan-out worker
Instance index
1 POST /events + Idempotency-Key
2 INSERT event, attendees, outbox
3 committed v1
4 organizer’s instances
5 201 event_id
6 outbox relay: change v1
7 consume
8 attendee rows, v1
9 ok
RequestResponseAsync, does not block

How to store repeating events

The decision this question is really about.

Every instance
Breaks on edits
every weekday
row × ∞
edit → rewrite all
+ Simple range reads.− “Forever” never ends; edits rewrite thousands of rows.
Rule, expand on read
Slow reads
RRULE row
load all series
expand per view
+ One row; edits are cheap.− Every view expands every series.
Rule + rolling index
Our pick
RRULE row
expand 12 months
index by user, startrebuildable
+ Cheap edits and range reads.− Two copies to keep in step.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 100 views/sMake it work
Apps
App server
SQL database
One server and one database; rules expanded on read.
Stage 2 · ≈ 35,000 views/sPrecompute views
Apps
API gateway
Calendar × 12View cache
Events DB × 16Instance index × 16
An instance index by user, a week cache, shards.
Stage 3 · 3,500 writes/sTake work off the save
Apps
API gateway
Calendar × 12View cacheChange log
Fan-outReminder schedulerSender
Events DB × 16Instance index × 16
Change log, fan-out workers, minute-bucket reminders.
Stage 4 · 100M devicesSync every device
Apps
API gatewaySync service
Calendar × 17View cacheChange log
Fan-outReminder schedulerSender
Events DB × 16Instance index × 16
Content-free pushes and sync tokens instead of polling.
Was this walkthrough useful?Your vote tells us what to improve next.