Build a Multi-User Calendar with Recurring Events and Reminders
System DesignModel answerLast updated
Design the backend for a calendar platform that handles event creation, recurrence rules, shared access permissions, and scalable notification delivery.
You're designing the backend architecture for a calendar platform that multiple users can access simultaneously. The system needs to support personal and team calendars with sophisticated scheduling features.
Core Capabilities
Your design must support:
- Event management: Users create, modify, and remove calendar entries with title, time range, timezone, and participant list
- Repeating patterns: Events can recur on schedules like "every Tuesday at 2 PM" or "first Monday of each month"
- Access control: Calendar owners grant different permission levels to other users (view-only, can-edit, full-control)
- Advance notifications: The system delivers alerts to users before their events begin
Performance Targets
- Availability: Calendar viewing must remain operational even during partial outages
- Response time: Loading a month view should complete in under 200ms
- Recurrence complexity: Support industry-standard recurrence syntax (iCalendar RRULE format)
What to Cover
- Storage schema: How will you represent events in the database? For repeating events, will you store each occurrence separately or save the pattern and generate instances on demand?
- System components: Sketch the services, data stores, and communication paths
- Collision handling: How do you prevent double-booking shared resources like conference rooms?
- Notification infrastructure: Describe an approach that scales to millions of daily alerts, especially when most events cluster at common start times (:00 and :30 past the hour)
Focus on the technical decisions that make this system work reliably at scale.
Hints
Hint 1
Think about the read-to-write ratio for calendars and how that influences caching strategy
Hint 2
Materializing recurring event instances within a rolling time window balances query speed against storage cost
Hint 3
Pre-computing reminder fire times into bucketed rows avoids scanning the entire event table every minute
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
The central challenge is modeling recurring events in a way that keeps reads fast, conflict checks accurate, and reminder delivery scalable. Strong candidates articulate the trade-offs between storage approaches early and commit to a hybrid model.
1. Scope and Scale Estimation
Begin by establishing concrete numbers:
- User base: 100 million registered, 20 million active daily
- Write volume: Each active user creates or updates roughly 3 events per day → 60M writes/day, averaging 700 writes/sec with peaks near 4,000/sec
- Read volume: Calendars are viewed far more than edited (50:1 ratio). Users check their calendar 20 times daily → 400M reads/day, averaging 5,000 reads/sec and peaking around 30,000/sec
- Notifications: Approximately 150M reminders daily, averaging 1,700/sec but spiking to 80,000/sec at :00 and :30 when most meetings start
- Data footprint: 2KB per event × billions of events = low terabytes. Materialized instances add more, requiring careful bounds.
Clarify functional scope: Can attendees modify individual occurrences of a repeating event? Can rooms be reserved? (Both yes.)
2. API Design
POST /calendars/{calendarId}/events
Body: {title, start, end, timezone, recurrenceRule?, attendees[], reminders[]}
PATCH /events/{eventId}
Query: scope=(thisOnly|thisAndFuture|all), occurrenceDate=...
DELETE /events/{eventId}?scope=...
GET /calendars/{calendarId}/events
Query: startDate=..., endDate=...
Returns: expanded event instances within range
PUT /calendars/{calendarId}/permissions/{userId}
Body: {level: "read" | "write" | "owner"}
POST /events/{eventId}/respond
Body: {status: "accepted" | "declined" | "tentative"}
POST /availability/check
Body: {userIds[], startDate, endDate}
Returns: free/busy blocks
The scope parameter handles the complexity of editing recurring series: modify just one occurrence, or change the entire future series.
3. Data Schema
calendars (id PK, owner_user_id, display_name, default_timezone)
calendar_permissions (calendar_id, user_id, permission_level)
PK: (calendar_id, user_id)
events (id PK, calendar_id, creator_user_id, summary, description,
start_local_time, duration_minutes, timezone,
recurrence_rule, recurrence_end_date, edit_version)
event_overrides (event_id, occurrence_date, modified_fields_json | is_cancelled)
-- Single-instance edits to recurring events
participants (event_id, user_id, response_status, is_room_resource)
event_instances (calendar_id, start_utc, end_utc, event_id, occurrence_date, edit_version)
PK: (calendar_id, start_utc, event_id)
-- Materialized view for queries
notification_queue (fire_time_bucket, notification_id, recipient_user_id,
event_id, occurrence_date, delivery_channel, event_edit_version)
Recurring Event Storage Trade-off
| Approach | Advantages | Drawbacks |
|---|---|---|
| Store each occurrence | Simple range queries; straightforward overlap detection | Infinite series impossible; editing "all future" means rewriting thousands of rows |
| Store rule only, expand at read time | Minimal storage; edits touch one row | Every query expands rules (CPU-intensive); indexing for reminders becomes complex |
| Hybrid (recommended) | Rule + overrides are source of truth; instances materialized for a rolling 12-month window | Requires background workers to maintain materialized instances |
The hybrid approach wins because calendar queries, conflict checks, and reminder scheduling all benefit from pre-computed instances in a known time range. Queries beyond the window (rare) fall back to runtime expansion using an iCalendar library.
When an event changes, increment edit_version and enqueue a job to delete and rebuild affected instances. A nightly job extends the materialization window forward.
4. Architecture Overview
API Gateway (auth/routing)
↓
Calendar Service Cluster
↓
├─→ Event Database (sharded by calendar_id: Postgres or Cloud Spanner)
│ ↓ change data capture
│ ↓
├─→ Cache Layer (Redis: month views keyed by calendar_id + version)
│
├─→ Event Stream (Kafka: event-modified, event-deleted topics)
↓
├─→ Instance Materializer Workers
│ ↓ writes event_instances, notification_queue
│
├─→ Invitation Fanout Service
│ ↓ creates calendar entries for all attendees
│
└─→ Notification Scheduler
↓ Kafka: due-notifications
↓
Delivery Workers → push services (APNs, FCM, email)
Sharding: Partition by calendar_id. A single calendar's month view becomes one range scan on (calendar_id, start_utc).
Invitations: When a user invites others, fanout creates an instance row in each attendee's calendar. This is intentional denormalization (write amplification) that makes reads fast—appropriate given the 50:1 read/write ratio.
Read path: Users typically view multiple calendars simultaneously (personal, team, shared). The service validates permissions (cached), issues parallel queries per calendar, merges results, and caches the merged month view in Redis with a version tag. Edits invalidate the cache by bumping the version.
High availability: Deploy read replicas per shard across availability zones. Serve views from cache or replicas even if the write primary is temporarily down, preserving read availability while writes briefly degrade during failover.
5. Conflict Detection for Shared Resources
Model conference rooms as calendars with an is_room_resource flag. Booking must be strongly consistent. User conflicts only trigger warnings.
PostgreSQL approach: Use an exclusion constraint:
ALTER TABLE event_instances
ADD CONSTRAINT no_room_overlap
EXCLUDE USING gist (calendar_id WITH =, tstzrange(start_utc, end_utc) WITH &&)
WHERE (is_room_resource);
Concurrent booking attempts fail atomically at insert time.
Without native range types: Acquire a row lock on the room's calendar, query for overlaps with WHERE start_utc < :end AND end_utc > :start, insert if clear, then commit. Contention is per-room, which remains manageable.
Recurring bookings: Expand all instances within the materialization window and attempt batch insert in one transaction. If any conflict, either reject the entire series or return conflicting dates so the user can exclude them.
6. Reminder System at Scale
Never scan the events table looking for upcoming items. Instead:
Pre-compute fire times: When materializing an instance, create one notification_queue row per attendee per reminder (e.g., "15 minutes before"). Set fire_time_bucket to the minute the reminder should fire. Only materialize the next 48 hours; a rolling job refills.
Scheduler service: Partitioned by time bucket, with leader election per partition. Several minutes early, read the upcoming bucket and publish messages to Kafka (keyed by user_id) with precise fire times. Publishing early absorbs the :00 spike.
Delivery workers: Subscribe to Kafka partitions. Before sending, verify event_edit_version matches and the user hasn't declined (discards stale reminders). Deduplicate on notification_id using Redis (handles Kafka's at-least-once delivery). Send via APNs, FCM, or email with retries and dead-letter queue.
Scaling: Add Kafka partitions and workers to handle throughput. Delete fired rows to keep the queue table small.
7. Key Trade-offs
Materialization lag: Edited events briefly show stale instances until workers rebuild. Mitigation: include edit_version in API responses so clients can detect outdated cached data.
Storage cost: Materializing 12 months of instances for 100M users with recurring meetings requires significant storage. Monitor and tune the window length based on query patterns.
Fanout cost: Inviting 50 people writes 50 rows. For very large events (company all-hands), batch writes and accept brief inconsistency, or switch to a pointer model where attendees read from a shared canonical event.
Timezone complexity: Store event times in local time with timezone ID, not UTC, because "9 AM every Monday" must respect daylight saving transitions. Materialize to UTC for range queries.
Common Mistakes to Avoid
- Storing all times in UTC breaks recurring rules across DST boundaries
- Generating instances unbounded creates infinite rows for open-ended rules
- Scanning events for due reminders creates a thundering herd every minute
- Ignoring permission checks in the read path leaks private calendars
- Forgetting to version event data causes stale notifications after edits
A complete answer demonstrates understanding that recurrence drives most complexity, commits to a materialization strategy, and shows how that choice cascades through queries, conflicts, and notifications.