Backend Design for a Offline-Capable, Cross-Device Scheduling App
System DesignModel answerLast updated
Design the backend for a scheduling app where one user's devices stay in sync, edits work offline, and repeating events are stored and queried efficiently at 10M daily users.
Backend Design for an Offline-Capable, Cross-Device Scheduling App
You are asked to design the server side of a personal scheduling product, comparable to a mainstream online calendar. Each person may use several devices (phone, tablet, laptop), and all of them must show the same data.
What the product must do
- Create, edit, and remove events.
- Support repeating events, such as "every Monday morning".
- Show the events that fall inside a chosen window, such as the current week.
- Propagate changes made on one device to the user's other devices.
Quality goals
- Highly available, with strong guarantees on what a user sees after their own changes.
- Fast retrieval when a user opens or flips through the calendar.
- Offline-first: edits made without connectivity are queued and merged once the device reconnects.
Scale assumptions
- 10 million daily active users.
- Each user has on average about 50 events per month.
What your answer should cover
- Data model: the schema for events, including how repeating rules and time zones are represented.
- API: the main REST or gRPC endpoints, including how devices sync.
- Conflict handling: a strategy for when two devices change the same event while offline.
- Scalability: how you serve a read-heavy workload, especially calendar views.
Include a high-level architecture description, with emphasis on the choice of database and the caching layers. Back your choices with rough capacity estimates.
Hints
Hint 1
Start with numbers: estimate read QPS versus write QPS, and storage. Reads will dominate, which shapes the cache and database choices.
Hint 2
For time zones, think about what 'every Monday at 9am' should do across a daylight-saving change. What must you store to keep it correct, and what can be derived for indexing?
Hint 3
Decide whether to store the repeating rule, every occurrence, or both. Consider what happens with infinite series and with editing a whole series versus one occurrence.
Hint 4
Because the server can order all writes for a user's calendar, ask whether you need vector clocks at all. Think about per-record version numbers, a change log with a cursor, and optimistic concurrency.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and capacity estimate
Focus on a single user with several devices; sharing between users is an extension. Rough numbers:
- Reads: ~20 calendar views per user per day (app opens, week swipes, widgets) gives ~200M/day, about 2.5K QPS average and 15-20K QPS at peak (Monday morning). Reads dominate.
- Writes: ~3-5 mutations per user per day gives ~40M/day, about 500 QPS average and ~3K at peak.
- Storage: with recurring events stored as rules, a user has roughly 1-2K rows over several years. At ~1 KB each, that is on the order of 10-20 TB: a sharded relational workload, nothing exotic.
- Consistency: read-your-writes is mandatory; cross-device propagation within a few seconds when online.
2. API
REST for commands, plus a push channel.
POST /calendars/{cid}/events Idempotency-Key header -> {id, version}
PATCH /events/{id} {fields, base_version}
DELETE /events/{id}?base_version=N
PATCH /events/{id}/instances/{orig_start} edit or cancel one occurrence
GET /calendars/{cid}/events?start=&end=&tz= expanded occurrences
GET /sync?cursor=T -> {changes[], next_cursor, has_more}
POST /sync/batch offline outbox upload
WS /notifications "calendar changed, pull"
Design points:
- Idempotency keys let offline clients retry safely without duplicate creates.
base_versionon every mutation enables optimistic concurrency.- Push is a hint; pull is truth. A device gets a nudge (WebSocket, APNs/FCM) and then pulls changes by cursor. Lost or reordered pushes cannot corrupt state.
3. Data model
calendars(id PK, owner_id, name, default_tz, version)
events(
id PK, calendar_id, title, description, location,
start_local, end_local, tzid, -- wall-clock time + IANA zone
all_day, start_utc, -- start_utc derived, for indexing
rrule NULL, -- RFC 5545 string
recurrence_end_utc NULL, -- NULL = infinite
version, updated_at (hybrid logical clock), deleted
)
event_exceptions(series_id, original_start_local, status, override fields, version)
change_log(calendar_id, seq, event_id, version, op)
Indexes: (calendar_id, start_utc) and (calendar_id, recurrence_end_utc).
Time zones. Store local wall-clock time plus an IANA zone. "9am every Monday in New York" must stay at 9am across DST; storing only UTC would shift it by an hour twice a year. UTC is a derived column used purely for range lookups. All-day events are floating dates with no zone.
Recurrence. Three options:
- Rule only: compact, cheap edits, supports infinite series, but every read must expand.
- Materialize all occurrences: trivial reads, but infinite series are impossible and editing a series rewrites thousands of rows.
- Hybrid (recommended): the rule plus exceptions is authoritative. The service expands rules for the requested window and caches the result. Expanding ~50 occurrences in memory costs microseconds. Optionally materialize a rolling 12-month table asynchronously for search and reminders, never as the source of truth.
Range query for [S, E): fetch non-recurring events with start_utc in the window (padded for long events); fetch recurring masters that started before E and have not ended before S; expand the masters, apply exceptions, merge and sort.
4. Sync and conflict resolution
The server is the single authority. Each calendar lives on one shard, and the server assigns a monotonic per-event version and a per-calendar change-log seq. This makes vector clocks unnecessary: they solve peer-to-peer causality, which we do not have. Saying this trade-off out loud is worthwhile.
Offline flow:
- The client applies the edit locally and appends it to an outbox with
base_versionand a hybrid logical clock stamp. - On reconnect it uploads the outbox in order via
/sync/batch, then pulls/sync?cursor=. - The server compares versions. If
base_versionequals the current version, it applies the edit, bumps the version, and writes the change-log row in one transaction. Otherwise it merges.
Merge policy:
- Different fields: three-way merge against
base_version; both edits apply (title from the phone, time from the laptop). - Same field: last-write-wins by hybrid logical clock, which tolerates clock skew. Keep the losing value in history so the UI can say "your change was overwritten".
- Delete vs edit: delete wins as a tombstone, and the editing client is told. Undo can restore.
- Series vs instance: a single-occurrence exception survives later changes to the series title; changing the series time drops exceptions whose original start no longer exists.
Keep tombstones at least as long as the maximum offline window (e.g. 30 days); older cursors trigger a full resync.
5. Architecture and read scaling
Clients -> Gateway/LB -> Event Service (stateless: expansion, merge, ACL)
|-> Redis (view cache)
|-> Sharded SQL (by calendar_id)
| CDC from change_log
v
Kafka -> Notification service -> devices
-> reminders, search indexer
- Database: relational, sharded by
calendar_id(Postgres with Citus/Vitek-style sharding) or a managed globally consistent store such as Spanner or CockroachDB. The workload needs multi-row transactions (event, exceptions, change log) and range queries, and each calendar is a natural shard key, so most operations touch one shard. - Caching: cache expanded views per calendar and window (for example week buckets) in Redis. Invalidate or version-bump the affected buckets from the same change-log events. Serve the user's own reads from the primary or a caught-up replica to preserve read-your-writes.
- Client cache: devices keep a local copy, so most week flips never hit the server.
- Hot spots: large shared or subscribed calendars can be cached aggressively and fanned out asynchronously.
- Availability: replicate across zones, make writes idempotent, and let clients keep working from local state during outages.
6. Common mistakes
- Storing only UTC and breaking recurring events across DST.
- Materializing infinite series.
- Using push payloads as the source of truth.
- Reaching for vector clocks or CRDTs when a single authoritative server suffices.
- Forgetting tombstones, so deleted events reappear after an offline device syncs.
- No idempotency on retried offline uploads, causing duplicates.