Core Components
π± View
Handles user input and output
- Processes keyboard, mouse, and touch events
- Determines whatβs displayed on screen
- Interacts with the DOM
- State is NOT synchronized across users
βοΈ Model
Handles calculation and simulation
- Contains all application logic
- Manages shared state
- State is ALWAYS identical for all users
- Runs deterministic computations
βοΈ Synchronizer
Stateless cloud service
- Routes events between users
- Mirrors events to all session participants
- Handles snapshot storage and retrieval
- Manages session membership
Key Principles
π Guaranteed State Synchronization
π Guaranteed State Synchronization
The model state is guaranteed to always be identical for all users.This is the fundamental promise of Multisynq. No matter how many users are in a session, their model state will be perfectly synchronized. This eliminates the complexity of managing distributed state.
π¨ View Flexibility
π¨ View Flexibility
View state is NOT synchronized and can differ between users.This allows for personalized experiences while maintaining shared core functionality. Users can have different UI preferences, screen sizes, or device capabilities.
π‘ Event-Driven Communication
π‘ Event-Driven Communication
All communication happens through events.Events provide a clean, decoupled way for components to communicate. The routing is handled automatically by Multisynq.
Session Architecture
1
Session Creation
When a Multisynq application starts, it joins a session. Users with the same session ID will share the same synchronized state.
2
Synchronization
The synchronizer ensures all users receive the same events in the same order, maintaining deterministic execution.
3
Snapshot Management
Snapshots are periodically saved to the cloud. New users can join by loading a recent snapshot instead of replaying all events from the beginning.
Event Routing Rules
Understanding these routing rules is crucial for proper Multisynq development:
- View β Model
- Model β View
- View β View
- Model β Model
Events from view to model are reflected to all usersThis ensures all users see the same game state changes.
Data Flow Constraints
Critical Rule: The view can read from the model, but canβt write to it directly.
- β Correct
- β Incorrect
Practical Example
Hereβs how the MVS pattern works in practice:- Model (Synchronized)
- View (Local)
Benefits of MVS Architecture
π― Perfect Synchronization
All users see exactly the same state at all times, eliminating sync bugs and conflicts.
π§ Clean Architecture
Clear separation between business logic (Model) and presentation (View) improves maintainability.
π Scalability
Deterministic execution means no server-side state management or complex conflict resolution.
π Performance
Local computation with synchronized results provides excellent performance and responsiveness.
Best Practices
ποΈ Model Design
ποΈ Model Design
- Keep models deterministic and side-effect free
- Use
future()
for time-based behaviors - Avoid external dependencies in models
- Make model state easily serializable
π¨ View Design
π¨ View Design
- Handle all user input in the view
- Use local state for UI-specific data
- Avoid blocking operations in the view
- Keep views responsive and interactive
π‘ Event Design
π‘ Event Design
- Use clear, descriptive event names
- Keep event payloads small and simple
- Avoid high-frequency events when possible
- Use scoped events for user-specific actions
Common Pitfalls
Avoid these common mistakes:
- Direct Model Mutation: Never modify model state directly from the view
- Async Operations in Models: Models must be deterministic and synchronous
- Heavy View Events: Donβt send large data payloads in events
- Circular Dependencies: Avoid event loops between model and view
Next Steps
Writing a Multisynq Model
Learn how to build robust, synchronized models
Writing a Multisynq View
Master view development and user interaction
Events & Pub-Sub
Deep dive into event-driven communication
Snapshots
Understand state persistence and recovery
The Model-View-Synchronizer pattern is the foundation of all Multisynq applications. Understanding this architecture deeply will help you build more robust, maintainable, and scalable multiplayer experiences.