What Are Snapshots?
📸 Snapshot Definition
Snapshots are serialized copies of your complete model state, saved periodically to the cloud. They capture:
- All model properties and data
- Current object relationships
- Session state at a specific moment
- Everything needed to restore the exact state
Snapshots are taken automatically by the Multisynq system - you don’t need to manually create them.
How Snapshots Work
1
Automatic Creation
The Multisynq reflector periodically requests one of the session participants to create a snapshot of the current model state.
2
Cloud Storage
The snapshot is compressed and stored in the cloud, associated with your session ID.
3
Restoration
When needed, the snapshot is loaded and your model state is restored exactly as it was.
Snapshot Use Cases
- 🔄 Session Persistence
- 🚀 New User Synchronization
Automatic save functionality for your applicationWhen users quit or reload:
- Session state is preserved in the latest snapshot
- When they return, the exact state is restored
- No progress is lost
New User Join Process
1. Snapshot Loading
1. Snapshot Loading
The local model is initialized with data from the last snapshot
Your model’s
init()
method is NOT called when loading from a snapshot.2. Event Replay
2. Event Replay
The reflector resends all events transmitted after the snapshot
Event replay is deterministic - the same events produce the same results.
3. Model Simulation
3. Model Simulation
The model simulates all events to bring the snapshot up-to-date
4. View Initialization
4. View Initialization
The local view initializes to match the model state
View Initialization Considerations
Important: When writing your View initialization, account for the fact that the Model may have been restored from a snapshot and already contains data.
- ❌ Problematic Approach
- ✅ Correct Approach
Snapshot Performance
Current Limitation: The snapshot system is currently unoptimized and may cause performance hitches when snapshots are taken.
- 🐌 Current Behavior
- 🔄 Mitigation Strategies
- Performance hitch: Brief pause when snapshot is taken
- Visible to users: May notice application freeze
- Depends on model size: Larger models = longer pause
Best Practices
📊 Model Design
Keep your model state snapshot-friendly
- Use simple, serializable data types
- Avoid circular references
- Keep the state tree flat when possible
- Clean up unused objects regularly
🎨 View Initialization
Design views to handle existing state
- Check for existing model data in
init()
- Create visuals for pre-existing objects
- Subscribe to future events
- Handle both fresh starts and snapshot loads
🧪 Testing
Test your snapshot behavior
- Test fresh session starts
- Test joining existing sessions
- Verify state restoration
- Check view initialization
⚡ Performance
Optimize for snapshot performance
- Monitor your model size
- Use efficient data structures
- Clean up regularly
- Avoid storing view-specific data in models
Debugging Snapshots
- Snapshot Detection
- State Validation
Detect if your model loaded from a snapshot
Common Patterns
🎮 Game State Snapshots
🎮 Game State Snapshots
Preserving game progress across sessions
💬 Chat History
💬 Chat History
Preserving conversation history
Future Improvements
The Multisynq development team is working to make snapshots invisible to both users and developers:
- Invisible performance: No more hitches during snapshot creation
- Optimized storage: Smaller snapshots, faster loading
- Better compression: Reduced network overhead
- Incremental snapshots: Only save changes since last snapshot
Next Steps
Persistence
Learn about explicit persistence beyond snapshots
Writing a Multisynq Model
Master model development for snapshot-friendly code
Writing a Multisynq View
Learn to handle both fresh starts and snapshot loads
Sim Time & Future
Understand time-based behaviors in snapshotted sessions
Snapshots are fundamental to Multisynq’s persistence and scalability. Understanding how they work will help you design better models and views that handle session continuity seamlessly.