FireDevOps FireMUD & Ops Projects

⏱️ FireMUD System Architecture: Tick System and Runtime Design

📄 This document expands on the Game Loop / Tick Model section of the FireMUD System Architecture Overview. It defines how ticks execute, resolve concurrency, handle crashes, and preserve deterministic, fair game logic under load. Cross-service operations triggered by ticks rely on Redis scripts and gRPC; sagas are unnecessary for these gameplay actions as explained in Transaction Strategies.

🔗 For Redis keys, Lua-based atomicity, and operational guarantees, see the Redis Architecture.


🧠 Hybrid Tick Model

FireMUD uses a Hybrid Tick Model to balance real-time responsiveness with deterministic action resolution:

This model ensures:

🔗 Overview of this model appears in System Architecture Overview


🔐 Distributed Locking

To prevent concurrent entity updates, ticks acquire distributed locks in Redis using:

If a required lock is unavailable:

Conflict metadata is recorded and reported to the Game Session Service, which reorders future submissions intelligently.

🔗 See Atomicity and Concurrency Control


🔁 Smart Retry and Conflict Resolution

FireMUD includes a robust system for lock contention, timeouts, and retries, coordinated by the Game Session Service and powered by Redis.

🧠 Retry Scheduling

When an action fails due to contention:

Future enhancements may include:


🌍 Tick Regions and Parallel Execution

Ticks are region-scoped, not globally synchronized. Each tick region (typically a room or room cluster) runs its own independent cycle, enabling:

🧠 Tick regions are mapped to Redis shards for atomicity and lock discipline.


🔄 Tick Execution Flow

Each tick proceeds as follows:

  1. Collect Actions From the command queues of active entities in the tick region

  2. Resolve Fairly Sort by timestamp, stat priority, or custom policy; only one action per entity is executed per tick

  3. Apply Effects Mutate entity state (e.g., HP, inventory, buffs, position)

  4. Trigger Events Run regeneration, room scripts, NPC behaviors, AI-driven commands — all use the same command queue model

Note: Game Logic Service resolves each action statelessly and does not participate in commit or rollback phases — those are fully managed by the Game Session Service via Redis.

The Game Session Service manages orchestration, while gameplay rules are resolved via the Game Logic Service, and final commit flow is also handled by Game Session Service.


🧮 Tick Staging and Commit Flow

State changes are first staged in Redis under keys like tick:pending:{regionId}:

This ensures:


⏳ Timeout and Fairness Policy

Each tick enforces a soft execution budget (e.g., 100ms):


🔍 Isolation and Replay Safety

To prevent cross-tick contamination and support deterministic replay:

This guarantees clean, deterministic ticks and safe replays after crash or restart.


⏱️ Timers and Time Scaling

Time-based effects (e.g., cooldowns, regeneration) are managed with real-time timers in milliseconds, stored as:

Each tick scans timers for expirations and triggers corresponding events. If delayed, multiple may fire at once.

🕒 Dynamic Time Scaling

Durations can be modified on the fly:

Runtime feature flags controlling global pace or status effects are applied by the Game Session Service before tick execution. For how these flags are defined and edited, see Versioning & Runtime Configuration.


💥 Crash Recovery and Replay

If a tick crashes mid-flight (e.g., Game Session Service restart), Redis preserves:

Recovery is coordinated by Game Session Service and backed by:

This supports idempotent, replayable ticks — without risk of duplicate effects or inconsistent state.


🧠 Service Responsibilities

ServiceRole
Game Session ServiceOrchestrates tick regions, lock acquisition, retries, commit flow
Game Logic ServiceResolves each queued action deterministically
Automation & ScriptingInjects AI or scripted commands into queues
World ManagementDefines tick region layout and room segmentation
RedisStores locks, timers, staged changes, retry metadata; executes Lua

Game Session Service manages all tick lifecycle logic and delegates atomic operations to Redis via Lua.


✅ Model Benefits

FireMUD treats time as localized pulses, not a global clock. Each tick is a self-contained transaction — safely composing gameplay logic in a world that never stops evolving.


📚 Related Documentation