Design a Distributed Scheduling and Calendar Platform
System DesignModel answerLast updated
Design a calendar system for millions of users covering event storage, recurring rule expansion, time zone correctness, and a responsive frontend with optimistic updates.
Prompt
You are building a collaborative scheduling platform — think of it as a calendar service used by millions of people to create meetings, block time, and coordinate with others. Your task is to walk through the key design decisions an engineering team would need to make before writing a line of code.
What the system must do
- Users can create, edit, delete, and view calendar events.
- Events can recur on a schedule (e.g., "every Tuesday and Thursday at 2 PM").
- A user can query another user's free/busy status to find an open slot.
- Users receive reminders before an event begins.
Quality requirements
- Calendar reads (viewing the week, loading events) must be fast and highly available.
- Meeting bookings must not double-book a time slot — consistency matters there.
- The system must correctly handle participants spread across different time zones.
Your deliverables
Address each of the following areas in your answer:
- API design — what are the core endpoints? How do you handle safe retries and concurrent edits?
- Data model — how do you store events and recurrence rules? How do you make range queries efficient without expanding an infinite series at read time?
- Frontend strategy — how does the browser client manage local state, handle optimistic updates when a user creates an event, and stay in sync with the server?
- Scaling hot calendars — a public figure or a shared room resource may have thousands of simultaneous viewers. How do you serve them without hammering the database?
You do not need to design email delivery, video conferencing integration, or external calendar sync (iCal import/export).
Hints
Hint 1
For recurring events, storing only the rule and expanding lazily at read time hurts free/busy queries across many users. Storing fully pre-expanded rows breaks on infinite series and makes edits expensive. Think about a middle path: materialize instances up to a rolling horizon and fall back to on-demand expansion beyond it.
Hint 2
Storing event times in UTC is correct for point-in-time instants, but a weekly recurring meeting defined in a specific city must keep its IANA time zone name alongside the rule — otherwise it drifts by an hour after a daylight saving transition. The two concerns are different and need to be stored separately.
Hint 3
For optimistic UI updates, the hard part is not applying the change locally — it is handling a conflict when the server rejects it. Think about what you store in a client-side outbox, what a version or ETag gives you, and what the user should see when a slot was taken by someone else a moment earlier.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and Scale Estimates
Anchor the design with numbers before proposing anything structural.
- Users: 100 M registered, ~20 M daily active.
- Read load: 10 calendar views per DAU → 200 M reads/day → ~2,500 QPS average, with Monday-morning peaks around 10×, roughly 25 K QPS. Free/busy lookups add comparable volume.
- Write load: ~2 event mutations per DAU → 500 QPS average, ~5 K at peak. The system is read-heavy at about 10:1.
- Storage: 1 KB per event row × 500 events per user × 100 M users → ~50 TB base, plus materialized instances.
- Out of scope: email delivery, video links, external calendar import.
2. API Design
POST /v1/events
body: { title, start_local, end_local, tz_id, rrule?, attendees[], reminders[] }
header: Idempotency-Key
GET /v1/events/{eventId}
PATCH /v1/events/{eventId}?scope=this|following|all&instanceStart=<utc>
header: If-Match: <version>
DELETE /v1/events/{eventId}?scope=this|following|all&instanceStart=<utc>
GET /v1/calendars/{calId}/events?from=<utc>&to=<utc> → expanded instances in window
GET /v1/freebusy?users=a,b,c&from=<utc>&to=<utc> → busy intervals only
POST /v1/events/{eventId}/rsvp body: { status }
GET /v1/sync?calId=<id>&syncToken=<tok> → delta since token
Key decisions to call out explicitly:
- Server-side expansion. The range endpoint returns fully expanded instances; clients never parse RRULEs. This avoids rendering bugs when rules change.
- Optimistic concurrency with
If-Match. APATCHcarrying a stale version returns412 Precondition Failed, letting the client merge or show a conflict. - Idempotency keys. A client that retries after a timeout will not create a duplicate event.
- Sync tokens. Incremental sync keeps mobile and browser clients cheap — only deltas travel on the wire.
3. Data Model
events(
event_id PK, calendar_id, organizer_id,
title, description, location,
start_local TIMESTAMP, end_local TIMESTAMP, -- wall-clock time
tz_id TEXT, -- IANA zone, e.g. 'America/Chicago'
start_utc TIMESTAMPTZ, end_utc TIMESTAMPTZ, -- first occurrence, for non-recurring scans
rrule TEXT NULL, -- RFC 5545, e.g. FREQ=WEEKLY;BYDAY=TU,TH
recurrence_end_utc TIMESTAMPTZ NULL, -- NULL = infinite
version INT, updated_at, deleted BOOL
)
event_exceptions(
event_id, original_start_utc,
override_event_id NULL, -- points to a modified replacement instance
cancelled BOOL
)
-- Materialized rolling window of instances
event_instances(
calendar_id, start_utc, end_utc, event_id, original_start_utc, status,
PRIMARY KEY (calendar_id, start_utc, event_id)
)
attendees(event_id, user_id, rsvp_status, PRIMARY KEY (event_id, user_id))
reminders(event_id, user_id, offset_minutes)
Time zones done right
Storing all times as UTC is correct for point-in-time events. Recurring events are different. "Every Thursday at 10 AM Chicago time" is UTC-06:00 in winter and UTC-05:00 in summer. If only the UTC offset is stored, the meeting silently drifts an hour after every daylight saving transition. The fix is to store the IANA zone name with the rule and expand server-side in that zone, writing each resulting instance back as UTC. The client then converts UTC → viewer's local zone using the Intl API. Candidates who spot this distinction stand out.
Recurrence expansion strategy
| Approach | Range query | Write cost | Main problem |
|---|---|---|---|
| Lazy expand at read time | Recomputes each query; expensive for free/busy across many users | Cheap | Cannot index |
| Fully pre-expand all instances | Fast indexed scan | Impossible for infinite series; editing rewrites many rows | Storage explosion |
| Hybrid (rolling horizon) | Indexed scan within the window | Bounded, background work | Needs a horizon-extension job |
The hybrid works as follows: materialize instances into event_instances for a rolling window of ~12 months. A background job extends the window daily. Queries beyond the window fall back to on-demand expansion (rare for most users). Sharding by calendar_id means "my week" is a single-shard index scan on (calendar_id, start_utc).
4. High-Level Architecture
Client → API Gateway → Event Service → Postgres (sharded by calendar_id)
│ │ CDC (Debezium) → Kafka
├→ FreeBusy Service ←── Redis (busy-interval cache)
└→ Push/Sync (WebSocket)
Kafka consumers:
- instance expander / horizon extender
- cache invalidator
- reminder scheduler
- attendee fan-out writer
Attendee fan-out: when an event is created, a Kafka consumer asynchronously writes an instance row into each attendee's calendar shard. This keeps reads single-shard at the cost of eventual consistency in attendee calendars (~seconds of lag), which is acceptable.
Reminders: store (fire_at_minute, reminder_id) in a Redis sorted set or a partitioned table. Workers poll the current minute bucket, publish to the notification service, and use a dedupe key (event_id, user_id, offset_minutes) for at-least-once safety.
5. Frontend Strategy
Local state shape
instancesById: Map<instanceId, Instance>
rangeIndex: Map<calId, Map<weekKey, instanceId[]>>
outbox: Array<{ tempId, idempotencyKey, mutation, snapshotBefore }>
Persist to IndexedDB for instant cold start and offline viewing.
Optimistic updates
- Assign a temporary ID, apply the mutation to the local store, and render immediately.
- Append the mutation to the outbox with an idempotency key.
- On success: swap the temp ID for the server ID, store the new
versionfor futureIf-Matchheaders. - On
409 / 412conflict: restoresnapshotBefore, re-fetch the affected range, and surface a specific message ("This time slot was just booked by someone else").
Never silently drop conflicts — users need to know their action did not land.
Background sync
- A WebSocket or server-sent event delivers a
calendarChangednotification. - The client calls
/sync?syncToken=and applies the delta locally. - If the socket is disconnected, fall back to polling every 30–60 seconds.
- An expired sync token triggers a full re-fetch of the visible window only, not the entire calendar.
6. Hot Calendars
A room resource or a high-profile shared calendar may have thousands of concurrent viewers.
- Serve free/busy, not raw events. Most viewers only need blocked intervals; those are far smaller to cache and safe to expose.
- Read replicas + CDN-cacheable responses. Free/busy responses with a short
Cache-Control(e.g., 10–30 s) absorb most of the read traffic before hitting the database. - Fan-out on write vs. read. For extremely hot calendars, pre-compute and cache the free/busy bitmap. Invalidate on write via the CDC pipeline.
- Shed load gracefully. If the cache is cold, serve a slightly stale response rather than collapsing under a thundering-herd revalidation.
Common Mistakes
- Storing only UTC offset instead of the IANA zone name, breaking recurrence across DST changes.
- Fully pre-expanding infinite recurrence series without a horizon cutoff.
- Forgetting the
scopeparameter on edit/delete — editing "just this instance" versus "all future instances" requires exception row handling, not just a simple update. - Optimistic updates that silently discard server conflicts instead of rolling back and notifying the user.
- Sharding by user ID rather than calendar ID — it scatters one user's events across shards and makes weekly range queries expensive.