ADR-009: Data syncronisation strategy β
Context β
The Digital Lock On platform requires real-time data synchronisation across all connected devices to ensure Site Protectors, RPOs, and other users have accurate, current information for safety-critical decisions. When one user performs an action (worker lock-on/off, plant status changes, protection state updates), all other connected users must receive these updates automatically without manual refresh.
Key constraints:
- Must support offline-first workflows for worker/plant lock-on and lock-off
- Authentication and multi-user interactions (handover, worksite activation) require online connectivity
- Must integrate with existing 5-second heartbeat mechanism (ADR-007)
- Solution must be simple and pragmatic for initial release
Decision β
We will implement polling-based data synchronisation at a 5-second interval, aligned with our existing heartbeat mechanism.
Technical Approach β
- Polling Interval: 5 seconds (matches ADR-007 heartbeat frequency)
- Mechanism: HTTP polling requests to check for data updates
- Offline Behaviour: Changes queued locally and synchronised when connectivity restored
- Online-Required Operations: Authentication, handover, worksite activation/authorisation
- Offline-Capable Operations: Worker/plant lock-on and lock-off, site limit changes
Implementation Strategy β
- Piggyback data sync checks on existing heartbeat requests where possible
- Queue local changes during offline periods
- Synchronise queued changes when connectivity restored
- Display appropriate loading/sync indicators in UI
Future Evolution β
This polling approach is suitable for v1 and provides a foundation for future enhancement. When scale or real-time requirements demand it, we can migrate to Server-Sent Events (SSE) or WebSockets without changing the functional behaviour exposed to users.
Consequences β
Positive β
- Simple Implementation: Straightforward HTTP polling, no complex connection management
- Consistent Intervals: Aligns with existing heartbeat, reduces network overhead
- Offline Support: Works naturally with offline-first workflows
- Migration Path: Clear upgrade path to SSE/WebSockets when needed
- Debuggable: Easy to troubleshoot and monitor
Negative β
- Network Overhead: More requests than push-based approaches (though minimal at 5-second intervals)
- Latency: Up to 5-second delay for updates (acceptable for current requirements)
- Scalability: May need optimisation as user base grows
Neutral β
- Battery Impact: Minimal additional drain beyond existing heartbeat
- Server Load: Manageable with current architecture, scalable with caching strategies
Alternatives Considered β
Server-Sent Events (SSE) β
- Pros: More efficient for server-to-client updates, lower latency
- Cons: More complex implementation, requires persistent connections
- Rejection Reason: Over-engineering for v1; polling is sufficient for current scale
WebSockets β
- Pros: True bidirectional real-time communication, most efficient at scale
- Cons: Significantly more complex, requires connection state management, load balancer considerations
- Rejection Reason: Unnecessary complexity for current requirements; viable for v2+
Longer Polling Intervals (10-30 seconds) β
- Pros: Lower network overhead
- Cons: Unacceptable delay for safety-critical operations, inconsistent with heartbeat timing
- Rejection Reason: 5-second interval provides right balance for rail safety context
Implementation Notes β
Polling Behaviour β
- Poll every 5 seconds when app is active and online
- Suspend polling when app is backgrounded (respect browser/OS lifecycle)
- Resume polling immediately when app returns to foreground
- Display sync status indicators to users
Error Handling β
- Retry failed polls with exponential backoff
- Gracefully degrade to offline mode if repeated failures
- Clear user feedback about connectivity status
Related Requirements β
Related Decisions β
- ADR-007: Heartbeat Frequency - Establishes 5-second interval for presence detection