Overview
Sync is the process of keeping local data consistent with the server. Zeus uses a local-first approach where changes are made locally first, then synchronized in the background.How Sync Works
The Sync Cycle
- Local Change - User creates/updates/deletes an entity
- Queue for Sync - Entity marked with
syncStatus - Background Sync - App attempts to sync when online
- Server Update - Server processes the change
- Confirmation - Local entity updated with
serverIdandsyncedstatus
Sync Status Lifecycle
Sync States
synced
The entity is in sync with the server. No action needed.pending_create
A new entity that hasn’t been created on the server yet.pending_update
An existing entity that has been modified locally and needs to update the server.pending_delete
An entity marked for deletion. Will be hard-deleted after server confirmation.Triggering Sync
Automatic Sync
Sync runs automatically on app startup:Manual Sync
Trigger sync manually:Listening to Progress
Sync Order
Entities sync in dependency order:- Categories - No dependencies
- Wallets - No dependencies
- Transactions - Depends on wallets and categories
Conflict Resolution
Last-Write-Wins
When the same entity is modified on multiple devices:- Server compares
updated_attimestamps - Latest change wins
- Outdated clients receive the current state on next sync
Example Scenario
Handling Failures
Retry Logic
Failed operations are automatically retried:- Immediate retry on transient errors (network timeout)
- Exponential backoff for persistent errors
- Queue preserved across app restarts
- User can trigger manual retry
Error Types
| Error | Handling |
|---|---|
| Network timeout | Retry immediately |
| Server error (5xx) | Retry with backoff |
| Validation error (4xx) | Log error, skip retry |
| Authentication error | Pause sync, re-auth |
Offline Behavior
What Works Offline
- ✅ Creating wallets, categories, transactions
- ✅ Reading all cached data
- ✅ Updating existing entities
- ✅ Deleting entities (soft delete)
What Requires Connection
- ❌ Initial data fetch (first install)
- ❌ Syncing pending changes
- ❌ Multi-device consistency
Best Practices
- Always handle sync failures gracefully - Don’t block UI
- Show sync status - Users should know if data is pending
- Respect user bandwidth - Batch sync operations
- Test offline scenarios - Ensure app works without network
Monitoring Sync
Track these metrics:- Pending operations count
- Sync success rate
- Average sync latency
- Conflict frequency
Related
- Architecture - System design
- Flutter Cache - Implementation details

