Skip to main content
In this tutorial, you’ll build a todo application that works offline and syncs automatically when reconnected. Offline-first apps are essential for mobile users and anyone with unreliable connections. Your app stays responsive even without internet, and changes from multiple users merge seamlessly when connectivity returns.

Step 1: Create the Project

Open 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 at service/todo/mutator.go:
The store uses a mutex for thread safety and organizes todos by scope (like a namespace).

The Apply Function

This is the heart of sync - it processes mutations:
Each mutation type maps to a specific operation.

The Snapshot Function

Returns current state for new clients:

Step 3: Test Offline Behavior

  1. Open the app in your browser
  2. Add some todos
  3. Open DevTools → Network → check “Offline”
  4. Add more todos (they appear immediately!)
  5. Uncheck “Offline”
  6. Watch todos sync to server
The key insight: the UI updates before the server confirms.

Step 4: Add Priority Feature

Let’s add priority levels to todos.

Update the Model

Edit service/todo/mutator.go:

Update Create Function

Add Set Priority Mutation

Update the JavaScript Client

Edit assets/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:
Update the Todo struct:

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