Time Synchronization

GONet provides production-grade time synchronization using an NTP-style protocol with Golden Sample filtering. The system resists bufferbloat and network jitter while maintaining nanosecond-resolution time reads across all connected clients.

Overview

Accurate time synchronization is critical for multiplayer games. Without it, interpolation breaks, hit detection becomes unreliable, and animations desync. GONet's SecretaryOfTemporalAffairs handles all of this automatically, giving every client a synchronized clock that accounts for network latency and jitter.

The time sync system runs on a dedicated high-priority channel, separate from gameplay traffic, ensuring that clock corrections are never delayed by large state updates.

NTP-Style 4-Timestamp Protocol

GONet uses a 4-timestamp exchange modeled after the Network Time Protocol:

  1. 1.Client sends request -- Records local timestamp T1 and sends a time sync request to the server.
  2. 2.Server receives -- Records server-side receive timestamp T2.
  3. 3.Server responds -- Records server-side send timestamp T3 and sends the response with T2 and T3.
  4. 4.Client receives -- Records local timestamp T4. The client now has all four timestamps and can compute the clock offset and round-trip time.

This gives an accurate measurement of the clock difference between client and server, compensating for asymmetric network latency.

Golden Sample Filtering

Not all time sync samples are equal. Network congestion, bufferbloat, and route changes can produce outlier measurements that would destabilize the clock if applied directly. GONet uses Golden Sample filtering to select only the most reliable measurements.

  • Bufferbloat resistance -- Samples with unusually high round-trip times are discarded, as they indicate network congestion rather than a true clock offset.
  • Statistical filtering -- Only samples within acceptable variance of recent history are used to update the clock. This prevents sudden jumps from transient network events.
  • Convergence -- The clock converges toward the true offset over multiple samples, becoming more accurate the longer the session runs.

Correction Strategies

When a clock offset is detected, GONet applies one of three correction strategies depending on the magnitude of the difference:

Snap

For large offsets (e.g., initial sync or reconnection). The clock jumps immediately to the correct time. This is the fastest correction but can cause a visible "jump" in interpolated values.

Dilationdefault

For moderate offsets. The clock speeds up or slows down gradually to converge on the correct time without visible jumps. This is the recommended strategy for most games.

Interpolation

For small offsets. Blends between the current and target time over multiple frames. Produces the smoothest result but corrects slowly.

Dual Time Systems

GONet maintains two synchronized time systems:

Standard Time

Runs at the game's frame rate. Used for interpolation, event timestamps, and general game logic. Access via GONetMain.Time.ElapsedTicks.

Physics Time

Runs at the physics fixed timestep. Used for physics-based synchronization and FixedUpdate logic. Keeps physics determinism across clients.

Both time systems are synchronized independently, ensuring that game logic and physics stay in lockstep even when the frame rate varies.

Performance

  • Nanosecond resolution -- Time reads use high-resolution timers with nanosecond precision, avoiding the overhead of DateTime.Now or Time.realtimeSinceStartup.
  • Dedicated channel -- Time sync uses a high-priority system channel, so it is never delayed by gameplay traffic or large state updates.
  • Minimal bandwidth -- Time sync packets are small (a few timestamps) and sent at a configurable interval. They add negligible bandwidth overhead.

Host Failover Continuity

GONet Legendary — Host failover is a GONet Legendary feature (v1.6+).

When host failover ships, the time sync system will preserve continuity across host transitions. The new host will inherit the session's time state, and clients will re-synchronize against the new host without a visible time jump. This will ensure that interpolation, event ordering, and gameplay timers remain consistent across host transitions.

Next Steps

  • Transport Layer -- Learn about the underlying transport protocols and channel system.
  • Host Migration & Failover -- Planned feature: automatic host failover with time continuity preservation.
  • Performance -- Best practices for bandwidth, CPU, and memory optimization.
Time Synchronization | GONet Docs