Building a Global Multi-Tenant Scheduling and Events Platform
System DesignModel answerLast updated
Design a calendar backend for hundreds of millions of users covering events, recurrence, time zones, sharing, reminders, sync, and storage choices, with APIs, schemas, queries, and scaling.
You are asked to design the backend of a scheduling product that serves hundreds of millions of users across many tenants. Users own several calendars, share them with others, invite people to events, and expect reminders to arrive on time.
Functional scope
- Timed and all-day events, attendees, invitations and RSVPs
- Recurring series with per-occurrence changes
- Correct handling of time zones, including daylight saving transitions
- Reminders (email, push, in-app)
- Shared calendars with roles and privacy boundaries
- Text, attendee and time-based search
- ICS import/export and sync with external calendar providers
Non-functional goals
- Low read latency for range queries
- High availability
- Strong consistency where it matters (a user's own writes), eventual consistency elsewhere
- Cost efficiency
Please cover
- Requirements and scale: state your assumptions and do rough capacity math.
- APIs: REST or gRPC endpoints for event CRUD, listing events in a time range, invites and RSVP, search, and calendar sharing. Address idempotency, pagination, filtering, concurrency control and rate limiting.
- Data model: relational schemas with keys, indexes and constraints. Explain how you represent recurrence (rule plus exceptions), time zones, soft deletes and audit fields.
- Queries: (a) all visible events for a user in a window, (b) conflict detection for a proposed event, (c) materializing one occurrence of a series given its rule and exceptions, (d) search by attendee and keyword.
- Scaling and storage: partition keys, sharding, secondary indexes, caching, search indexing, and precomputed versus on-the-fly expansion of recurring instances.
- Consistency and operations: concurrent edits, retries, transactions versus an outbox, eventual consistency for search and notifications, disaster recovery, backups, GDPR and retention.
- Notifications and integrations: reminder delivery, ICS, external sync, abuse prevention and quotas.
- Database choices: when relational, document or time-series stores fit, and which you would pick as the primary store.
Hints
Hint 1
Start with numbers: reads dominate writes, and reminders cluster at the top of the hour. Let these drive the sharding and the reminder design.
Hint 2
Store a recurring series once as wall-clock start + IANA zone + RRULE, key exceptions by the occurrence's original start, and expand only a bounded window into a per-user instances table.
Hint 3
Use optimistic versions (ETag / If-Match) for concurrent edits, idempotency keys for retries, and a transactional outbox to feed search, reminders and attendee copies asynchronously.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and scale
Assumptions: 300M users, 100M daily actives, about 10 calendar views per DAU per day (about 1B reads/day, roughly 12k QPS average and 50k peak), about 1 write per DAU per day (roughly 1.2k QPS average, 5k peak, each fanning out to about 5 attendees). Around 1,000 events per user at about 1 KB gives roughly 300 TB raw before replication and materialized instances. Reminders run around 200M/day, spiking at :00 and :30.
Targets: p99 under 200 ms for range reads, 99.99% availability, read-your-writes for a user's own calendar, seconds-level eventual consistency for search, notifications and attendee copies.
The workload is read-heavy, per-user, and time-range oriented. That points to sharding by user and indexing by time.
2. APIs
POST /v1/calendars/{cal}/events Idempotency-Key
PATCH /v1/calendars/{cal}/events/{id}?scope=this|following|all&instanceStart=
DELETE /v1/calendars/{cal}/events/{id}?scope=...
GET /v1/calendars/{cal}/events?start=&end=&pageToken=&pageSize=
GET /v1/users/me/events?start=&end=&calendars= (merged view)
POST /v1/events/{id}/attendees
POST /v1/events/{id}/rsvp {status, instanceStart?}
GET /v1/search?q=&attendee=&start=&end=
PUT /v1/calendars/{id}/acl/{principal} {role}
POST /v1/freebusy {users[], start, end}
- Idempotency: store
(user, key) -> responsefor 24h; a retry returns the saved result. - Concurrency: each event has a
versionexposed as an ETag; staleIf-Matchyields 412. - Pagination: opaque cursors encoding
(start_utc, instance_id), never offsets, so pages stay stable under inserts. - Rate limiting: token buckets per user and per API key at the gateway, with tighter quotas for invites and ICS imports. Return 429 with
Retry-After.
3. Data model
Primary store: relational, sharded by owner_user_id.
calendars(calendar_id, owner_user_id, name, tz, version, deleted_at, ...)calendar_acl(calendar_id, principal_id, role)mirrored ascalendar_access(user_id, calendar_id, role)on the principal's shard, with roles freebusy / reader / writer / owner.events(event_id, calendar_id, organizer_id, title, start_local, end_local, tzid, start_utc, end_utc, is_all_day, rrule, version, created_by, updated_by, created_at, updated_at, deleted_at)withCHECK (end_local > start_local)and a partial index on(calendar_id, start_utc) WHERE deleted_at IS NULL.event_exceptions(event_id, original_start_utc, kind IN ('cancel','override'), override fields..., PK(event_id, original_start_utc))attendees(event_id, email, attendee_user_id, rsvp, is_optional, PK(event_id, email))with an index on(attendee_user_id, event_id).event_instances(owner_user_id, calendar_id, event_id, original_start_utc, start_utc, end_utc, is_busy, PK(owner_user_id, event_id, original_start_utc))with an index on(owner_user_id, start_utc, end_utc).reminders, and anoutbox(id, aggregate_id, type, payload, created_at, published_at).
Recurrence: keep one row per series: RFC 5545 RRULE, wall-clock DTSTART and TZID. Exceptions are keyed by the occurrence's original start so a moved instance is still identifiable. "This and following" splits the series: cap the old one with UNTIL, create a new one from the split point.
Time zones: expand recurrences in local time using the IANA database, so 9:00 New York stays 9:00 across DST, then derive UTC. All-day events are dates, not instants. Pin the tzdata version and re-expand affected instances when rules change.
Soft deletes and audit: deleted_at supports undo, sync tombstones and attendee propagation. created_by, updated_by and version give light auditing; full history goes to an append-only change log.
4. Queries
Visible events in [s, e):
SELECT i.event_id, i.start_utc, i.end_utc, e.title, ca.role
FROM calendar_access ca
JOIN event_instances i ON i.calendar_id = ca.calendar_id AND i.owner_user_id = :uid
JOIN events e ON e.event_id = i.event_id AND e.deleted_at IS NULL
WHERE ca.user_id = :uid AND i.start_utc < :e AND i.end_utc > :s
ORDER BY i.start_utc, i.event_id
LIMIT :n;
Conflicts for candidate [cs, ce): intervals overlap when start < other_end AND end > other_start.
SELECT event_id, start_utc, end_utc FROM event_instances
WHERE owner_user_id = :uid AND is_busy
AND start_utc < :ce AND end_utc > :cs
LIMIT 10;
One occurrence: fetch the series plus any exception row for :occ_start, then in application code (dateutil, ical4j) check that the RRULE generates :occ_start and that kind != 'cancel'; apply override fields if present.
Attendee + keyword: relational fallback joins attendees to events with a GIN full-text index and a time filter. Production search goes to a search engine.
5. Scaling and storage
- Partitioning: shard by owner user so a user's calendar views are single-shard. Shared calendars are handled by mirroring ACL rows on the viewer's shard and fanning instances out, trading write amplification for fast reads.
- Expansion strategy: materialize instances for a rolling window (for example 12-18 months) in a background job, and expand beyond that on the fly. Infinite or very long series never get fully materialized. Re-materialize on edit, on tzdata change, and as the window rolls.
- Caching: read-through cache of recent/upcoming windows per user, invalidated by version bump on writes.
- Search: Elasticsearch-style index fed from the outbox, filtered by ACL, eventually consistent.
- Tiering: move old events to cheaper storage.
6. Consistency and concurrency
- Single-shard transactions for a user's own writes (event row, exceptions, instances, outbox row together).
- Cross-user effects (attendee copies, search, notifications) go through the outbox: a relay publishes to a log, consumers are idempotent and dedupe by event id and version. This avoids two-phase commit across shards.
- Concurrent edits use optimistic versioning; clients re-fetch on 412 and merge.
- DR: multi-AZ replication, cross-region async replicas, point-in-time recovery, periodic restore drills.
- GDPR/retention: per-user export, hard-delete pipeline that purges rows, search documents, caches and backups on a schedule, and retention limits on audit logs.
7. Notifications and integrations
- Reminders: a scheduler stores due-time buckets (for example by minute). Workers pull the due bucket, resolve current event state (it may have moved or been cancelled), and send. Spread the :00/:30 spike with partitioned buckets, autoscaled workers and jittered pre-fetching. Delivery is at-least-once with dedupe keys.
- ICS: import parses into events with size and count limits; export serializes series with RRULE and exceptions.
- External sync: CalDAV and provider APIs using sync tokens and webhooks, with tombstones for deletions and per-provider backoff.
- Abuse: per-user invite and import quotas, recipient-side spam controls, and verification for external invitees.
8. Database choices
- Relational (primary): event metadata, ACLs, attendees. Needs transactions, constraints and range indexes.
- Document/wide-column: viable for the instance cache or per-user partitioned data if the relational store is outgrown, but ACL and attendee joins get harder.
- Append-only log/time-series: change history, sync feeds, analytics and reminder metrics.
- Search engine: text and attendee search.
Common mistakes
- Storing only UTC for recurring events, which breaks across DST.
- Expanding infinite series eagerly.
- Using offset pagination.
- Keying exceptions by current rather than original start.
- Distributed transactions for invite fan-out instead of an outbox.
- Forgetting tombstones for sync and ignoring the reminder spike.