Offline-First Client Synchronization Engine Spec
Specify client-side local persistence, queue management, and conflict resolution rules for web apps.
Use this template when designing an offline-capable web application that requires client-side data mutation, background queuing, and deterministic server reconciliation.
Role: Lead Client-Side Distributed Systems Engineer specializing in progressive web applications.
Context
- Client Storage Engine: {{client_database}}
- Server Transport Protocol: {{backend_api_protocol}}
- Conflict Resolution Strategy: {{conflict_resolution_strategy}}
- Max Offline Retention: {{max_offline_retention_days}} days
- Connectivity Polling Frequency: {{network_heartbeat_interval_ms}} ms
- Authentication Lifecycle: {{auth_token_refresh_flow}}
Task
Produce a technical synchronization engine specification for an offline-first web client, defining local schema design, mutation queue processing, retry backoff schemes, and deterministic conflict reconciliation against {{backend_api_protocol}}.
Method
- Design the local storage schema and mutation ledger inside {{client_database}}, tracking operation idempotency keys, timestamps, and entity states.
- Specify the network state detector and heartbeat polling mechanism using {{network_heartbeat_interval_ms}} intervals.
- Formulate the queue worker state machine detailing transition states: IDLE, DRAINING, PAUSED, RETRYING, and FAILED.
- Detail the handling of {{auth_token_refresh_flow}} when processing queued requests after token expiration while offline.
- Define the exact merge rules dictated by {{conflict_resolution_strategy}} (e.g., Last-Write-Wins, CRDT, or 3-Way Merge).
- Establish data pruning and eviction rules once locally cached mutation history exceeds {{max_offline_retention_days}} days.
- Construct telemetry tracking for sync latency, conflict rates, and failed mutation recovery.
Constraints
- MUST include concrete JSON schemas for the local mutation queue item and sync payload.
- MUST NOT allow offline data writes to block the UI main thread.
- MUST specify exponential backoff parameters with jitter for network reconnect retries.
- Keep the specification concrete, focusing on deterministic edge cases over general theory.
Output format
-
- Storage & Schema Specification (with JSON schema structures)
-
- Synchronization Queue State Machine
-
- Conflict Resolution Protocol & Edge Case Matrix
-
- Security & Offline Session Handling
-
- Telemetry, Recovery & Purge Policies
Self-review
- Does the conflict resolution section explicitly define client vs server tie-breaking behavior?
- Are all offline retention and queue expiration limits accounted for?
- Is the authentication renewal flow secure against stale token replay during sync?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.