Design an Enterprise Calendar System
System DesignModel answerLast updated
Architect a scalable calendar service handling interval-based queries, concurrent updates, recurring schedules, and real-time user invitations.
Architect a scalable backend service for an enterprise calendar system (similar to Google Calendar or Outlook).
Requirements
Functional Requirements
- Core Operations: Users can create, update, view, and cancel calendar events.
- Range Queries: Users can view all events occurring within a specified time window (e.g., day, week, month view).
- Attendees & Invitations: Events can have multiple participants who receive invitations and update their RSVP status (Yes, No, Maybe).
- Recurring Events: Support recurring patterns (daily, weekly, monthly) with exceptions (e.g., moving or deleting a single instance in a series).
- Reminders/Notifications: Deliver scheduled notifications to participants prior to an event starting.
Non-Functional Requirements
- High Availability & Scalability: Support 100M daily active users (DAU) with high read availability (99.99%).
- Low Latency: Time-range queries for a user's calendar view must return within < 100ms.
- Eventual Consistency vs. Strong Consistency: Strong consistency for event scheduling/modifications; eventual consistency acceptable for attendee notifications and feed updates.
System Scale (Estimates)
- 100M DAU.
- Average user checks their calendar 10 times a day ($1\text{B}$ read requests/day $\approx 12,000\text{ QPS}$).
- Average user creates/updates 2 events per day ($200\text{M}$ write requests/day $\approx 2,300\text{ QPS}$).
- Read-to-write ratio is roughly 5:1.
Explain the data models, API endpoints, key architectural components, strategies for handling recurring events, and concurrency management for simultaneous event updates.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. High-Level Architecture
The system follows a microservices architecture designed to decouple fast user-facing calendar queries from background tasks like notification delivery and recurrence expansion.
+-------------------+
| API Gateway |
+---------+---------+
|
+-------------------+-------------------+
| | |
+-------v-------+ +-------v-------+ +-------v-------+
| Event Service | | Query Service | | Invite Service|
+-------+-------+ +-------+-------+ +-------+-------+
| | |
+-------v-------+ +-------v-------+ |
| Primary DB | | Redis Cache | |
| (PostgreSQL/ | +---------------+ |
| CockroachDB) | |
+-------+-------+ |
| |
+-------------------+-------------------+
|
+------v-----+
| Kafka Bus |
+------+-----+
|
+------v-----+
| Notification
| Worker Pool|
+------------+
Key Components
- API Gateway: Handles authentication, rate limiting, and routes requests.
- Event Service: Manages CRUD operations for events and recurring rules (strong consistency).
- Query Service: Serves time-range reads for calendar views using caching and pre-computed indexes.
- Invite & Notification Service: Processes attendee RSVP state changes and dispatches alerts via push notifications/email.
- Event Bus (Kafka): Decouples write operations from notification dispatch and background index updates.
2. API Design
Create an Event
POST /v1/events
{
"title": "Architecture Review",
"start_time": "2025-04-10T14:00:00Z",
"end_time": "2025-04-10T15:00:00Z",
"time_zone": "America/New_York",
"attendees": ["[email protected]", "[email protected]"],
"recurrence_rule": "FREQ=WEEKLY;BYDAY=TH;UNTIL=20251231T235959Z"
}
Read Calendar Time Range
GET /v1/calendars/{calendar_id}/events?start=2025-04-01T00:00:00Z&end=2025-05-01T00:00:00Z
Returns both single events and expanded recurring instances within the requested window.
3. Data Model & Storage Strategy
Schema Design (Relational / Hybrid Approach)
We use a relational store (e.g., PostgreSQL or distributed SQL like CockroachDB) because calendar metadata requires strong transactional guarantees and strict foreign key relations.
events Table
| Column | Type | Description |
|---|---|---|
event_id | UUID (PK) | Unique event identifier |
organizer_id | UUID | User ID of the creator |
title | VARCHAR(255) | Title of the event |
start_time | TIMESTAMPTZ | Absolute start timestamp |
end_time | TIMESTAMPTZ | Absolute end timestamp |
time_zone | VARCHAR(50) | Time zone context |
is_recurring | BOOLEAN | Indicates if recurrence applies |
version | INT | Used for Optimistic Locking |
recurrence_rules Table
| Column | Type | Description |
|---|---|---|
rule_id | UUID (PK) | Identifier |
event_id | UUID (FK) | Reference to events table |
rrule | TEXT | iCalendar RFC 5545 string format |
event_exceptions Table
Stores instances where a recurring series item is altered or deleted.
| Column | Type | Description |
|---|---|---|
exception_id | UUID (PK) | Identifier |
event_id | UUID (FK) | Parent recurring event ID |
original_start_time | TIMESTAMPTZ | Start time of the instance being modified |
status | ENUM | MODIFIED, CANCELLED |
override_event_id | UUID (FK, Nullable) | Points to new event record if modified |
event_attendees Table
| Column | Type | Description |
|---|---|---|
event_id | UUID (FK) | Reference to events table |
user_id | UUID | Participant user ID |
status | ENUM | PENDING, ACCEPTED, DECLINED, TENTATIVE |
| Primary Key | (event_id, user_id) | Composite key |
4. Handling Recurring Events
Storing every individual occurrence of a daily event for 10 years would bloat database storage needlessly.
Recommended Strategy: On-the-Fly Expansion with Windowed Caching
- Base Storage: Store only the initial event entity and its
RRULE(iCalendar format). - Query Phase:
- Query non-recurring events matching the time window:
start_time < window_end AND end_time > window_start. - Fetch recurring events for the user whose range overlaps the query window.
- Use an in-memory iCalendar library (e.g.,
libical) to compute virtual event occurrences for the window. - Cross-reference with
event_exceptionsto drop deleted instances or replace modified instances.
- Query non-recurring events matching the time window:
- Caching: Cache the expanded calendar view for active users in Redis with a key like
user:{id}:events:{YYYY-MM}and a TTL of 24 hours. Invalidate this key upon any write operation.
5. Concurrency & Hot Spots
Concurrent Edits (Optimistic Concurrency Control)
When two organizers update an event simultaneously, we prevent race conditions using optimistic locking:
UPDATE events
SET title = 'Updated Title', version = version + 1
WHERE event_id = '123e4567-e89b-12d3-a456-426614174000' AND version = 3;
If affected_rows == 0, the server rejects the request with a 409 Conflict and prompts the user to refresh.
High-Profile Celebrities (Hotspot Mitigation)
A public calendar event for a celebrity with millions of subscribers creates extreme fan-out write pressure when updated.
- Fan-out Strategy: Instead of duplicating the event record across all subscribers, store one public event.
- Read Path Integration: Subscribers' query calls execute a fan-out on read:
- Fetch individual events from
user_events. - Fetch events from subscribed public calendars (
celebrity_id). - Merge and return the result set.
- Fetch individual events from
6. Reminders and Notifications
Reminders must execute reliably even at scale.
- Scheduler Worker: A background service periodically queries for upcoming events starting within the next $N$ minutes (e.g., 15 minutes).
- Time-Wheel / Priority Queue: Events are added to a distributed delay queue (e.g., Redis ZSET with epoch timestamp as score or Kafka with delayed topics).
- Execution: Workers consume ready jobs from the queue and push notification payloads to push notification services (APNs, FCM) or email queues.
7. Trade-offs and Considerations
| Decision | Pros | Cons |
|---|---|---|
| On-the-fly Recurrence Expansion | Saves massive database storage capacity. | Increases CPU usage during read queries. Mitigated by Redis caching. |
| Optimistic Locking | Fast, non-blocking, efficient for high-read low-write conflict patterns. | Retries required on high-contention events. |
| Fan-out on Read for Public Calendars | Eliminates millions of duplicate database writes per event modification. | Adds query latency to merge public and private calendars. |