Step 1: Create the Project
http://localhost:8080 to see the default syncing todo app.
Step 2: Understand the Default App
The template includes a working todo list. Let’s trace how data flows.The Store
Look atservice/todo/mutator.go:
The Apply Function
This is the heart of sync - it processes mutations:The Snapshot Function
Returns current state for new clients:Step 3: Test Offline Behavior
- Open the app in your browser
- Add some todos
- Open DevTools → Network → check “Offline”
- Add more todos (they appear immediately!)
- Uncheck “Offline”
- Watch todos sync to server
Step 4: Add Priority Feature
Let’s add priority levels to todos.Update the Model
Editservice/todo/mutator.go:
Update Create Function
Add Set Priority Mutation
Update the JavaScript Client
Editassets/js/sync.js to handle priority:
Step 5: Add Conflict Resolution
When two users edit the same todo, we need to handle conflicts.Last-Write-Wins Strategy
The simplest approach - later mutations win:Step 6: Add Multi-User Support
Open the app in two browser windows to test collaboration.Add User Tracking
Client Listens for Updates
How Sync Works
What You Learned
- Mutation-based data changes
- Optimistic UI updates
- Offline queueing and sync
- Conflict resolution strategies
- Multi-user broadcasting
Next Steps
Sync Documentation
Deep dive into sync internals
Live Template
Add real-time features without full sync