Device Sync Service
Problem Statement
Design a Device Synchronization Service that allows users to keep their data in sync across multiple devices (e.g., phones, tablets, laptops).
The system should ensure that whenever a user updates, deletes, or creates data (such as preferences, notes, messages, or documents) on one device, those changes are propagated
reliably and efficiently to all other devices associated with the same user account.
It should handle conflict resolution, network disruptions, and scalable synchronization for millions of users and devices.
🎯 Objective
Build a backend system that supports:
✅ Functional Requirements
1. Device Registration
2. Data Synchronization
3. Change Tracking
4. Conflict Resolution
5. Offline and Retry
6. Notifications
⚙️ Non-Functional Requirements
Attribute with Goal
Scalability
Handle 100M+ devices syncing concurrently
Availability
99.9% uptime
Latency
<200ms for sync response under normal load
Consistency
Eventual consistency across devices
Reliability
Ensure no data loss during sync interruptions
Security
Encrypt user data during transfer and at rest
Extensibility
Support new data types in future (e.g., contacts, tasks)
🧩 Core Components
Component with Description
Sync API Gateway
Entry point for sync requests (HTTP/WebSocket)
Sync Orchestrator
Manages delta computation, conflict resolution, and change propagation
Change Log Service
Stores incremental updates and timestamps for each device
Device Registry
Tracks registered devices and their last sync state
Notification Service
Pushes change notifications to connected devices
Storage Service
Persists user data (structured or document-based)
Auth Service
Validates user and device credentials
Queue/Stream Processor
Handles async updates and broadcasts changes (Kafka, Pub/Sub)
🧱 High-Level Architecture
1
2 +-------------------------+
3 | User Devices |
4 | (Mobile / Web / PC) |
5 +-----------+--------------+
6 |
7 +------+------+
8 | Sync API GW |
9 +------+------+
10 |
11 +-------------+-------------+
12 | |
13+-------v--------+ +--------v--------+
14| Sync Orchestrator | | Notification Svc |
15+-------+--------+ +--------+--------+
16 | |
17+-------v--------+ +-------v--------+
18| Change Log Svc | | Device Registry |
19+-------+--------+ +-------+--------+
20 | |
21+-------v--------+ +-------v--------+
22| Storage Service | | Auth Service |
23+-----------------+ +----------------+
24
25 +--------------------------+
26 | Message Bus (Kafka/PubSub) |
27 +--------------------------+🔄 Data Flow Example
1. Initial Device Sync
2. Update Propagation
3. Conflict Resolution
🧱 Data Model (Simplified)
Device
1
2{
3 "device_id": "d123",
4 "user_id": "u456",
5 "last_sync_time": "2025-10-24T10:00:00Z",
6 "device_type": "mobile",
7 "status": "active"
8}ChangeLog
1
2{
3 "change_id": "c789",
4 "user_id": "u456",
5 "entity_type": "note",
6 "entity_id": "n321",
7 "operation": "UPDATE",
8 "delta": "{ 'title': 'Updated title' }",
9 "timestamp": "2025-10-24T10:05:00Z"
10}⚡ Scalability & Optimization
| Challenge | Solution |
| ------------------------------ | ---------------------------------------- |
| High write load (many updates) | Use Kafka/PubSub to fan out updates |
| Frequent sync requests | Use incremental sync with delta tracking |
| Read latency | Cache recent changes in Redis |
| Conflict management | Keep vector clocks or version numbers |
| Mobile data limits | Compress payloads, sync diffs only |
| Offline sync | Queue local ops and replay later |
| Fault tolerance | Retry with exponential backoff |
🔒 Security
🧰 Tech Stack (Example)
| Layer | Technology |
| ----------------- | ------------------------------------- |
| **API Layer** | Go / Node.js / Java Spring Boot |
| **Queue/Streams** | Kafka / Google PubSub |
| **Storage** | DynamoDB / MongoDB / PostgreSQL |
| **Cache** | Redis |
| **Notification** | Firebase Cloud Messaging / WebSockets |
| **Auth** | OAuth2 / JWT |
| **Deployment** | Kubernetes / Docker |
| **Monitoring** | Prometheus + Grafana |
🧠 Key Challenges
| Challenge | Description |
| --------------------- | ------------------------------------------------------- |
| **Data Conflicts** | Multiple device writes need deterministic resolution. |
| **Offline Sync** | Handle large change sets when device comes back online. |
| **Scalability** | Billions of deltas across users/devices. |
| **Real-Time Updates** | Minimize delay between update and broadcast. |
| **Partial Failures** | Must ensure no lost updates during sync failures. |
✅ Goal:
Design a fault-tolerant, scalable, and real-time Device Sync Service that keeps user data consistent and synchronized across multiple devices — even under high concurrency, intermittent connectivity, and large-scale user activity.