Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Server-Side Development  ›  Lesson

The Tick Loop — The Server's Heartbeat

Server-Side Development 12 minA game server advances its world in fixed steps called ticks, and the tick rate sets both how often inputs are applied and the time budget each step must fit inside.

The Tick Loop — The Server's Heartbeat

Inputs pour into the Manja Arena server from 16 players at unpredictable moments. If the server recomputed the whole world every time one message arrived, it would never catch up, and each player would see events in a slightly different order. So the server works in beats instead.

The rule

Each tick: read the inputs, step the world, send the state.

A tick is one step of the server's simulation. The tick rate is how many ticks it runs each second, measured in hertz (Hz). Manja Arena runs at 20 Hz.

  1. Read the inputs — collect every input message that arrived since the last tick.
  2. Step the world — move each kite by exactly one tick's worth of time, check for crossing strings, apply any cuts.
  3. Send the state — capture the result and send it to every client.
import time

TICK_RATE = 20
TICK = 1 / TICK_RATE              # 0.05 s, which is 50 ms

next_tick = time.monotonic()
while match_running:
    inputs = drain_inbox(sock)    # everything that arrived since the last tick
    world.step(inputs, TICK)      # always the same step size
    send_snapshots(world)         # one update per player
    next_tick += TICK
    time.sleep(max(0, next_tick - time.monotonic()))

Every step is the same size, a fixed timestep. That keeps the physics stable: a kite can never skip through another string because one step happened to be unusually long. It also means the same inputs always produce the same result, which makes bugs repeatable.

Choosing the rate is a trade-off. A higher rate means inputs wait less before they are applied and the simulation is finer grained, but the server does more work every second and sends more updates. A slow strategy game may tick only a few times a second; fast shooters often run at 60 Hz or more.

The shortcut

Tick length in milliseconds = 1000 ÷ tick rate. Treat that number as a budget: all three jobs must fit inside it, every tick, with room to spare.

Could Manja Arena tick faster?Step 1 of 4
  1. Find the budget

    At 20 Hz, 1000 ÷ 20 = 50 ms per tick.

The trap is a tick that runs over its budget. If the work takes 60 ms on a 50 ms tick, the server slips further behind with every tick, and players watch the world stutter and slow down. Measure the worst tick, not the average one: a moment with all 16 kites tangled together costs far more than an empty sky.

Drills

Answer fast — trust the rule.

quick drill

At 20 ticks per second, how long is one tick?

quick drill

A server ticks at 64 Hz. Roughly how long is each tick?

quick drill

Each Manja Arena tick needs 60 ms of work, but the server runs at 20 Hz. What happens?

quick drill

Manja Arena moves from 20 Hz to 40 Hz and still sends one snapshot per player per tick. What happens to snapshot traffic?

quick drill

Why does the server move the world by the same fixed step every tick?

Remember

  • Each tick: read the inputs, step the world, send the state.
  • Tick length = 1000 ÷ tick rate, and all the work must fit inside it.
  • Trap: a tick that overruns its budget falls further behind every tick.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainShould we tick at 60 Hz?

A producer wants Manja Arena to run at 60 ticks per second instead of 20, 'so it feels smoother'. Explain what that change does to the tick budget, the CPU and the bandwidth, and what you would measure before agreeing.