Back to catalog
LabfreeFoundations

Multi-Device Stopwatch

Sync a stopwatch across multiple devices in real time using the DOSFI mesh.

beginner 45mFree

What you'll build

Vertical stack context: DOSFIUniversity (research) → DOSFI Academy (this course) → MeshNativeExchange (publishing & monetizing). Students progress from Learning → Building → Publishing → Monetizing. This module introduces the fundamental concepts of Multi-Device Stopwatch within the Mesh-Native ecosystem, emphasizing architecture, subsystem interaction, and deterministic behavior. Learners will explore the integration of DOSFI components to synchronize timing events across multiple nodes, understand data flow through the Transport Layer, and implement a simple distributed timing application. The course emphasizes core principles necessary for building reliable, privacy-preserving multidevice applications with Mesh-Native.

Skills you'll practice

  • Understand the architecture of a Multi-Device Stopwatch in the Mesh-Native ecosystem.
  • Implement a basic Multi-Device Stopwatch utilizing DOSFI components and the Transport Layer.
  • Analyze data flow and subsystem responsibilities to ensure deterministic synchronization across nodes.

Before you start

  • Basic understanding of Mesh-Native ecosystem architecture.
  • Familiarity with DOSFI core components and terminology.
  • Fundamentals of distributed systems and data synchronization.

Lab steps5 steps

  1. 1
    Architecting Mesh-Native Distributed Time

    In this opening lesson, we establish the foundations of a distributed stopwatch. Unlike client-server models where a central authority dictates the 'true' time, DOSFI applications operate on a consensus-driven mesh. The challenge is achieving sub-millisecond precision across heterogeneous nodes. Architecture: [Node A] <---Transport Layer---> [Node B]. We utilize the Vital settlement layer to anchor time-stamps that require non-repudiation. Concepts: Clock skew, logical clocks (Lamport timestamps), and the Distributed Intelligence Unit (DIU) overhead. Implementation: You must define the TimeSync bundle structure. Pseudocode: struct TimeBundle { uint64 timestamp; DIU_Hash anchor; } Every node listens for these bundles via the Transport Layer. Configuration: { 'sync_interval': '50ms', 'min_nodes': 3, 'transport_protocol': 'mesh-native-udp' }. Practical Exercise: Configure three local nodes and monitor the variance in their internal clocks using the dashboard. Pitfalls: Assuming physical time is linear; always use monotonic clocks for local delta calculations. Connection: We will use these synchronized time foundations to trigger the stopwatch 'Start' event in the next lesson.

  2. 2
    State Propagation via Mesh-Native Bundles

    Moving from time synchronization, we focus on bundle propagation. A stopwatch state change (e.g., ticking from 1.0s to 1.1s) must be broadcast efficiently. We leverage the Identity Fabric to authenticate every node that broadcasts a state update. The Transport Layer handles retransmission if packets are dropped due to network congestion. Architecture: [Pub/Sub mesh] where every node is both a publisher and subscriber. Diagram: (Node1) --Bundle--> (Mesh Fabric) --Broadcast--> (Node2, Node3). Implementation: Create an event listener for state packets. Example: if(bundle.type == 'TICK_UPDATE') { updateDisplay(bundle.elapsed); propagate(bundle); }. Configuration: { 'bundle_ttl': 5, 'retry_policy': 'exponential_backoff', 'broadcast_mode': 'flood' }. Practical Exercise: Simulate a packet loss scenario by introducing artificial network latency and verify if the state reconciles correctly. Pitfalls: Flood exhaustion; ensure your TTL (Time-To-Live) is low enough to prevent broadcast storms. Connection: This lesson provides the propagation mechanism; we will now handle node failure resiliency in Lesson 3.

  3. 3
    Resiliency: Handling Node Failure and Partitioning

    A distributed system is only as strong as its ability to survive failures. If the leader node in a cluster dies, the stopwatch must continue seamlessly. We integrate MeshInfer to predict state changes if the connectivity is interrupted. Using Vital, we secure the transition of state custody between nodes. Architecture: [Active/Passive failover]. If Node A fails, Node B promotes itself based on DIU priority. Diagram: [A] <-> [B] <-> [C] (Active) -> [A] (Timed Out). Implementation: Implement a heart-beat monitor within the Bundle handling logic. Pseudocode: if (last_received > timeout_limit) { trigger_election(); }. Configuration: { 'election_algorithm': 'raft-lite', 'health_check_interval': '200ms' }. Practical Exercise: Terminate the primary stopwatch node process and verify if a secondary node picks up the timer with zero drift. Pitfalls: Split-brain scenarios; always ensure consensus is achieved before an asset (the timer) transition. Connection: Now that we have resilient state, we will optimize the UI for high-frequency updates.

  4. 4
    Real-Time Distributed UI Rendering

    Rendering a stopwatch that feels smooth across devices requires bypassing traditional DOM bottlenecks. We use MeshInfer to pre-render UI frames before they arrive. The Identity Fabric ensures that UI permissions are locked to the user session. Architecture: [Local Buffer] + [Remote Stream]. The UI layer subscribes to the Transport Layer's bundle stream. Diagram: [Network Layer] -> [State Buffer] -> [UI Viewport]. Implementation: Write a React/Vue component that subscribes to local event emitters. Example: useEffect(() => { mesh.on('TICK', updateClock); }, []). Configuration: { 'render_buffer_ms': 10, 'interpolation_enabled': true }. Practical Exercise: Build a UI that shows the 'local' time vs 'mesh' time. Use a CSS transform to animate the digit transitions. Pitfalls: Rendering too frequently; cap updates at 60fps even if the network sends 1000 packets. Connection: Finally, we will monetize and anchor this application using the MeshNativeExchange.

  5. 5
    Monetization and MNE Settlement

    In the final lesson, we connect the stopwatch to the MeshNativeExchange (MNE). Every tick or session milestone is recorded as a micro-transaction, settling via Vital to ensure fair usage billing. Architecture: [App Layer] <-> [MNE Adapter] <-> [Vital Ledger]. Every stopwatch session produces an 'AuditBundle'. Diagram: [Stopwatch Event] -> [MNE Registry] -> [Vital Settlement]. Implementation: Integrate the MNE SDK to initiate a session fee. Pseudocode: MNE.registerTransaction(session_id, diu_cost);. Configuration: { 'settlement_currency': 'DIU', 'fee_structure': 'per_second_fractional' }. Practical Exercise: Perform a full test run from 'Start' to 'Stop', verify the DIU balance deduction in your developer console. Pitfalls: High gas costs; settle in batches rather than per-tick to optimize the Vital load. Connection: You have now built a production-grade mesh-native application ready for deployment.