Building Scalable Tick Engines: Redis Streams vs. MySQL Cron Loops for 10,000+ Concurrent Players
By Blackwave · Category: Engineering & Architecture · PBBG Vault Forums
The heartbeat of every Persistent Browser-Based Game is its Tick Engine. Whether it's energy replenishment every 60 seconds, crime cooldowns, city production cycles, or market stock price recalculations, the tick engine is what makes a world feel alive while players are logged off.
In this article, we analyze the architectural evolution from naive database crons to modern memory-backed streaming pipelines.
The Legacy Trap: The 60-Second MySQL Update
Most early browser games (and many engines still today) schedule a system cron that fires every minute:
* * * * * php /var/www/game/cron/minute_cron.php
And inside that file:
UPDATE users SET energy = LEAST(max_energy, energy + 5), nerve = LEAST(max_nerve, nerve + 1);
UPDATE properties SET rent_due = rent_due + daily_rate WHERE is_rented = 1;
Why This Collapses at Scale
- Full Table Locks / InnoDB IOPS Spikes: At 50,000 player rows, running an
UPDATEthat recalculates mathematical columns every 60 seconds forces MySQL to lock thousands of pages, flood the InnoDB redo log, and cause query queues to back up. - Lag Cascades: If the minute cron takes 45 seconds on normal traffic, a sudden surge in active players will push cron execution time to 75 seconds. The next minute's cron fires before the previous one finished, stacking processes until the server runs out of memory (OOM killer).
- Wasted CPU on Inactive Accounts: Why are you recalculating energy and rent every 60 seconds for an account that hasn't logged in since 2018?
Pattern 1: The "Lazy Tick" (Calculate On-Demand)
Instead of updating every user row in a background loop, compute persistent metrics only when the player interacts with the game.
How It Works
Store last_tick_at on the user row:
public function refreshPlayerEnergy(User $user): void
{
$now = now();
$elapsedSeconds = $now->diffInSeconds($user->last_energy_tick_at);
// One tick every 60 seconds
$ticksDue = intdiv($elapsedSeconds, 60);
if ($ticksDue > 0) {
$energyGained = $ticksDue * 5;
$user->energy = min($user->max_energy, $user->energy + $energyGained);
// Advance clock exactly by the consumed ticks
$user->last_energy_tick_at = $user->last_energy_tick_at->addSeconds($ticksDue * 60);
$user->save();
}
}
Benefits
- Zero background cron overhead for inactive users.
- Completely immune to cron lag cascades.
- Scales effortlessly to millions of accounts because CPU cost is distributed across organic player HTTP requests.
Pattern 2: Global World Ticks with Redis Streams & Worker Pools
Lazy ticks work wonders for individual player meters, but what about world-wide mechanics?
- Market prices that fluctuate every 15 minutes.
- Automated auction settlements.
- Gang wars where factions capture territories on synchronized 5-minute ticks.
For these, you need a deterministic, queue-backed message pipeline.
flowchart LR
A["System Scheduler (Pulse Tick)"] -->|Publishes Tick Event| B["Redis Stream (game:ticks)"]
B --> C["Worker Pool 1 (Economy Consumer)"]
B --> D["Worker Pool 2 (Faction Wars Consumer)"]
B --> E["Worker Pool 3 (Auction Settlement)"]
Implementation with Redis Streams & Laravel Pulse Engine
In Pulse Engine, the tick scheduler emits a time-stamped event into a dedicated Redis stream:
use Illuminate\Support\Facades\Redis;
// Scheduler dispatches tick event
Redis::xadd('game_ticks_stream', '*', [
'tick_id' => (string) Str::uuid(),
'epoch' => time(),
'type' => 'five_minute_world_tick',
]);
Consumers process chunks of operations concurrently:
public function handleTickEvent(array $payload): void
{
// Chunked batch updates using primary keys to avoid table locks
Territory::where('is_contested', true)
->chunkById(100, function ($territories) {
foreach ($territories as $territory) {
$territory->resolveControlCycle();
}
});
}
Summary: The Best-of-Both-Worlds Architecture
For modern PBBGs in 2026:
- Individual Player Stats (Energy, Health, Nerve, Cooldowns): Use Lazy On-Demand Calculations tied to timestamps.
- Synchronized Global Events (Markets, Wars, Seasons): Use Redis Streams with Horizontally Scaled Workers.
- Never run
UPDATE users SET ...across entire tables in a single cron!
What architecture is your game running today? Share your setups and benchmarks!