Requirements clarification:
- Mobile: intermittent/low bandwidth, background sync, small payloads, battery-sensitive.
- Web: rich interactivity, low-latency real-time updates, complex queries.
- Cross-cutting: security (auth, encryption), scale, observability.
Protocol choices (hybrid):
- REST/JSON over HTTPS for simple CRUD, cacheable endpoints, and where broad compatibility is needed (mobile, proxies, CDN).
- gRPC-Web for high-performance RPC from browsers where binary efficiency and strict typed contracts matter (useful for telemetry-heavy flows).
- GraphQL (single endpoint) for flexible, client-driven queries; use persisted queries to reduce payloads.
- Real-time: GraphQL subscriptions over WebSocket or server-sent events for web; for constrained mobile, use lightweight push (APNs/FCM) to wake device and fetch deltas via REST/gRPC.
Caching:
- Edge/CDN for GETs and persisted GraphQL responses when safe; use cache keys with Vary and short TTLs for dynamic content.
- HTTP caching and ETags/If-None-Match to minimize payloads.
- Client-side: normalized cache (Apollo/Relay) on web; mobile local cache layer with eviction policies and size limits.
Offline strategies & sync:
- On-device authoritative local store (SQLite/Room/Realm) and operation queue (command log).
- Optimistic updates in UI with rollback on error.
- Background sync: schedule exponential backoff retries; use push notifications to trigger immediate sync.
Conflict resolution:
- For commutative data (counters, presence), use CRDTs to achieve automatic merge.
- For complex domain objects, combine server-side merge rules + versioning:
- Use vector clocks or per-field timestamps to detect concurrent edits.
- Default policy: per-field merge where possible; otherwise surface conflict to user with contextual diff and allow manual resolution.
- Provide last-write-wins only for low-risk fields; log conflicts and expose metrics/alerts.
- Support idempotent APIs and opaque operation IDs to prevent duplicate application.
Trade-offs & implementation notes:
- Start with REST + GraphQL read layer; add gRPC-Web for performance hotspots.
- Keep real-time limited to web subscribers; use push+delta fetch for mobile to save battery.
- Invest in monitoring (conflict rates, sync failures) and tooling to help support teams debug client state.
This hybrid approach balances compatibility, efficiency, offline resilience, and developer ergonomics while keeping clear escalation paths for conflict cases.